Beginner Python Project From Scratch: Tic Tac Toe

Поділитися
Вставка
  • Опубліковано 4 кві 2022
  • Follow along with me on replit: replit.com/new/python3
    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/ChristianD37/Youtu...
    Personal Channel - / @ur_homedawg
  • Ігри

КОМЕНТАРІ • 53

  • @CDcodes
    @CDcodes  Рік тому +10

    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!

  • @AaronProgZ
    @AaronProgZ 8 місяців тому +3

    This is a well put together tutorial video. Thanks for making it!

  • @DisperseControl
    @DisperseControl Рік тому +4

    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.

  • @chosenone2435
    @chosenone2435 2 роки тому +4

    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 : )

  • @joey546
    @joey546 2 роки тому +9

    Good to see you back! You still have, by far, the best tutorial on the Game States I've ever seen.

  • @foreducation408
    @foreducation408 2 місяці тому

    such an awesome tutorial.

  • @jiviteshkanodia5666
    @jiviteshkanodia5666 Рік тому

    i have just started python and it was very good experience thanks

  • @seal6978
    @seal6978 2 роки тому +3

    Your turtorials are amazing! You deserve more support!

  • @phoebely2900
    @phoebely2900 2 роки тому +1

    Fantastic work!

  • @tulli1275
    @tulli1275 Рік тому +2

    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  Рік тому +5

      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 : )

  • @MyFishWillKillU
    @MyFishWillKillU 2 роки тому +4

    Wow so cool

  • @30sec_amv44
    @30sec_amv44 4 дні тому

    Thank you

  • @mainkev
    @mainkev Рік тому

    This is amazing, thanks

    • @CDcodes
      @CDcodes  Рік тому

      You're very welcome!

  • @user-ll2om1kv7y
    @user-ll2om1kv7y 2 місяці тому

    Amazing

  • @tameemwahab8752
    @tameemwahab8752 8 місяців тому +2

    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

  • @imperial-x9899
    @imperial-x9899 Рік тому +3

    bruh you literally destroy programmer who are making hour length video just for this simple code

    • @CDcodes
      @CDcodes  Рік тому

      Appreciate the kind words : )

  • @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 : )

  • @gigigem5631
    @gigigem5631 2 роки тому +2

    Thank you!

    • @CDcodes
      @CDcodes  2 роки тому +1

      Happy to Help!

  • @Poxlol
    @Poxlol 2 роки тому +2

    Underrated

    • @CDcodes
      @CDcodes  2 роки тому

      Appreciate it!

  • @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  Рік тому +1

      Thank you! Unfortunately that was just a copy paste from a notepad on a different monitor haha.

    • @swezork
      @swezork Рік тому +1

      @@CDcodes kk, gotu. thank ou for being honest

  • @GodSahil
    @GodSahil 7 місяців тому +1

    "churn" lol

  • @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

  • @thomasyusuf1366
    @thomasyusuf1366 6 місяців тому

    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  6 місяців тому

      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.

  • @Bettybarnes42
    @Bettybarnes42 9 місяців тому

    I don't understand how prev_turn == turn results in an invalid entry. Can someone help me understand?

    • @Andrzejkl94
      @Andrzejkl94 8 місяців тому

      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

  • @W-uq7pc
    @W-uq7pc 2 місяці тому

    yo is that visual code? or smth cuz i see it familiar

    • @CDcodes
      @CDcodes  Місяць тому

      It is replit link in the description

  • @Simon-on6jv
    @Simon-on6jv 6 місяців тому

    Which application are you using??

    • @CDcodes
      @CDcodes  6 місяців тому

      replit, link is in the description

  • @Lintang7
    @Lintang7 Рік тому

    can it be run on vs code?

  • @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

  • @faezenazari5047
    @faezenazari5047 Рік тому +1

    Ok always x wins.. 🤣

  • @alpeshmahajan5474
    @alpeshmahajan5474 Рік тому

    there's a correction in the exit section if choice=='q' it should'nt be playing =false instead ......if choice =='q' exit()

    • @CDcodes
      @CDcodes  Рік тому

      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 Рік тому

      @@CDcodes then we'll have to write additional line of code to restart the game