Тёмный

Beginner Python Project From Scratch: Tic Tac Toe 

CDcodes
Подписаться 3,4 тыс.
Просмотров 66 тыс.
50% 1

Follow along with me on replit: replit.com/new...
In this tutorial, we'll be creating this simple 2-player tic-tac-toe game using python. This was my first assignment when I took Intro to Programming in University, so I thought it be a fun little game for beginners to tackle.
Despite being simple, there's a lot to learn about Python and coding in this small little project. The video assumes you know a bit about some of the basics of coding (variables, if-statements, and while loops). Everything else is explained in more detail.
Code used in the video can be found here: github.com/Chr...
Personal Channel - / @sunset_cd

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 54   
@CDcodes
@CDcodes 2 года назад
Hey everybody! In the spirit of learning, here are some ideas you can try and implement if you finished the video and are looking to add a bit more to this project. Exercise: Allow the players to put in their names so it doesn't just say "Player 1" and "Player 2" Exercise: Add a timer to the game so that each player only has a certain amount of time to make a decision (hint: checkout the built in "time" module) Exercise: Add an option to replay the game when it ends. Also add a game counter to keep track of how many times each player has won. Challenge Exercise: Add a single player mode with some AI functionality for the second player. It doesn't need to be a fancy algorithm, just think about how you can have the program make a valid move. Once you get it working, see if you can come up with something better! Happy coding!
@DisperseControl
@DisperseControl Год назад
Thank you! This was a great learning experience for me to follow along with and rebuild. Taught me some new tricks as a beginner to Python and was useful for fulfilling a project requirement for my course work.
@CDcodes
@CDcodes Год назад
Happy to hear!
@joey546
@joey546 2 года назад
Good to see you back! You still have, by far, the best tutorial on the Game States I've ever seen.
@CDcodes
@CDcodes 2 года назад
Really appreciate the support!
@IrrelevantPride
@IrrelevantPride 2 года назад
Truth
@AaronProgZ
@AaronProgZ 11 месяцев назад
This is a well put together tutorial video. Thanks for making it!
@chosenone2435
@chosenone2435 2 года назад
Great to see you back! You are the best Pygame youtuber and your tutorials help me a TON.
@CDcodes
@CDcodes 2 года назад
Thanks for the support! Got some Pygame stuff planned for the near future : )
@tulli1275
@tulli1275 Год назад
Omg, i really need to learn a lot. I tried to do this exercise by my self and ended up contemplating bout suicide, I wish I was a pro like you at problem solving
@CDcodes
@CDcodes Год назад
Hiya. I may make it look easy, but what you don't see behind this tightly edited video is the years of experience I've had with problems like this. When I started learning to code, I could barely wrap my head around even simple tasks. Now I'm a lot more confident, but still learning. With some time and patience, I have confidence everything will click for you! Wishing you all the best in your coding journey : )
@seal6978
@seal6978 2 года назад
Your turtorials are amazing! You deserve more support!
@CDcodes
@CDcodes 2 года назад
Thank you!
@tameemwahab8752
@tameemwahab8752 10 месяцев назад
its not working, at 2:03 draw_board has a red line underneath it so it isnt working im doing everything the video tells me to
@williamchilcote46
@williamchilcote46 Год назад
Thank you for the video. I tweaked the code so that you could choose 1 or 2 players and play the computer.
@CDcodes
@CDcodes Год назад
Nice work! Happy to see you were to take my project and create something even better : )
@jiviteshkanodia5666
@jiviteshkanodia5666 Год назад
i have just started python and it was very good experience thanks
@imperial-x9899
@imperial-x9899 Год назад
bruh you literally destroy programmer who are making hour length video just for this simple code
@CDcodes
@CDcodes Год назад
Appreciate the kind words : )
@Amateurartist111
@Amateurartist111 Месяц назад
Thank you
@MyFishWillKillU
@MyFishWillKillU 2 года назад
Wow so cool
@Poxlol
@Poxlol 2 года назад
Underrated
@CDcodes
@CDcodes 2 года назад
Appreciate it!
@foreducation408
@foreducation408 4 месяца назад
such an awesome tutorial.
@phoebely2900
@phoebely2900 2 года назад
Fantastic work!
@CDcodes
@CDcodes 2 года назад
Thank you!
@gigigem5631
@gigigem5631 2 года назад
Thank you!
@CDcodes
@CDcodes 2 года назад
Happy to Help!
@GodSahil
@GodSahil 9 месяцев назад
"churn" lol
@mainkev
@mainkev Год назад
This is amazing, thanks
@CDcodes
@CDcodes Год назад
You're very welcome!
@娇毅轨柴
@娇毅轨柴 4 месяца назад
Amazing
@thomasyusuf1366
@thomasyusuf1366 8 месяцев назад
thank you for an amazing video. However im a little confused about line 19 in main file. How does that check if there is an X or O. The last part isnt even a dictionary. Id appreciate a response thanks :)
@CDcodes
@CDcodes 8 месяцев назад
We start by equaling the previous turn to the current turn (Line 19). Because there's an infinite number of things the player can enter other than a correct board position, the idea is that we assume whatever they give us is invalid input. If they provide invalid input, we don't change the turn. If they actually give us an valid board position, then we increment the turn counter. When the next iteration of the loop occurs, it will check to see if the turn counter when up or not by comparing it to the previous turn. If it didn't, then our assumption that the player would give us something wrong is correct. so we want to print an error message for them.
@swezork
@swezork Год назад
amazing video!! 3:11 which keys did you use to convert them instantly? or was it cropped part of the video?
@CDcodes
@CDcodes Год назад
Thank you! Unfortunately that was just a copy paste from a notepad on a different monitor haha.
@swezork
@swezork Год назад
@@CDcodes kk, gotu. thank ou for being honest
@Bettybarnes42
@Bettybarnes42 11 месяцев назад
I don't understand how prev_turn == turn results in an invalid entry. Can someone help me understand?
@Andrzejkl94
@Andrzejkl94 11 месяцев назад
is it after an if? if it is, it should be if prev_turn == turn: so if theres no if, you only need to put only one "="; prev_turn = turn "==" checks if two values are equal, "=" is (for example) to assign a value to a variable AND OF COURSE, IM STILL LEARNING TOO, i've started coding 2 weeks ago, i could be completely wrong, but thats what i understood ATM
@dommad1964
@dommad1964 Год назад
Hi! I think your logic is great here! I am very much a beginner in python and am curious if you have any *hints* to implemting another game play? does turn = 0 need to be reset somehow? I am trying to implent best 2/3 gameplay to your code. I feel very far off. I started as: if finished: if what_turn(turn) == 'X': print("Player1 is the Winner!") else: print("Player2 is the Winner!") else: print("NO game!") print('Do you want to play again?(Y/N)') play_again = input().lower() gameplay = True if play_again == 'n': gameplay= False print(' Thanks for playing!')
@CDcodes
@CDcodes Год назад
Glad you enjoyed the video! One way to approach it could be to place all the game logic from this video inside another while loop. So you'll have two loops, with the code from this video nested inside. Something like while program is running: **all tic tac toe logic code from this video** check above results and update score set whether the loop can end or not (if someone has won the 2/3) Print winner
@W-uq7pc
@W-uq7pc 4 месяца назад
yo is that visual code? or smth cuz i see it familiar
@CDcodes
@CDcodes 4 месяца назад
It is replit link in the description
@dzplayer0149
@dzplayer0149 Год назад
my code isn't that great (it's almost twice as long as yours) but the game works perfectly.
@CDcodes
@CDcodes Год назад
Congrats on building the game! Working code is always better than pretty code that doesn't
@Simon-on6jv
@Simon-on6jv 8 месяцев назад
Which application are you using??
@CDcodes
@CDcodes 8 месяцев назад
replit, link is in the description
@Lintang7
@Lintang7 Год назад
can it be run on vs code?
@CDcodes
@CDcodes Год назад
It sure can
@faezenazari5047
@faezenazari5047 Год назад
Ok always x wins.. 🤣
@alpeshmahajan5474
@alpeshmahajan5474 2 года назад
there's a correction in the exit section if choice=='q' it should'nt be playing =false instead ......if choice =='q' exit()
@CDcodes
@CDcodes 2 года назад
Hi. That would technically work for the purpose of a single use game. But from what I understand, I think using exit() is generally a practice best avoided for production type code. Using exit() will just end the program. If we wanted to say, allow the players to replay the game without having to run the script again, exit() wouldn't be the best approach. The loop approach allows us to do things such as encapsulating our code into other loops.
@alpeshmahajan5474
@alpeshmahajan5474 2 года назад
@@CDcodes then we'll have to write additional line of code to restart the game
@30sec_amv44
@30sec_amv44 2 месяца назад
Thank you
Далее
Please Master These 10 Python Functions…
22:17
Просмотров 155 тыс.
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1,2 млн
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Просмотров 1,6 млн
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 805 тыс.
Learn Python With This ONE Project!
55:04
Просмотров 1,8 млн