Beginner Python Project From Scratch: Tic Tac Toe

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024

Комментарии • 55

  • @CDcodes
    @CDcodes  2 года назад +12

    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!

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

  • @DisperseControl
    @DisperseControl Год назад +8

    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  Год назад +2

      Happy to hear!

  • @tulli1275
    @tulli1275 2 года назад +5

    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  2 года назад +8

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

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

  • @AaronProgZ
    @AaronProgZ Год назад +4

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

  • @seal6978
    @seal6978 2 года назад +3

    Your turtorials are amazing! You deserve more support!

  • @imperial-x9899
    @imperial-x9899 2 года назад +3

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

    • @CDcodes
      @CDcodes  2 года назад

      Appreciate the kind words : )

  • @jiviteshkanodia5666
    @jiviteshkanodia5666 Год назад

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

  • @tameemwahab8752
    @tameemwahab8752 Год назад +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

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

  • @foreducation408
    @foreducation408 7 месяцев назад

    such an awesome tutorial.

  • @codingandcaffeine253
    @codingandcaffeine253 Месяц назад

    It was a great tutorial, very easy to follow. But one thing i am not able to grasp completely. Why did we call the check_turn function to check who the winner is? I mean the check turn function only returns the number of turn. Or what i am able to understand is, that as soon as the player 1 (let's say) is done with their final winning turn, this function return that and the winner is declared! please help me understand this. thankyou!
    And once again, great tutorial!

  • @phoebely2900
    @phoebely2900 2 года назад +1

    Fantastic work!

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

  • @30sec_amv44
    @30sec_amv44 4 месяца назад

    Thank you

  • @thomasyusuf1366
    @thomasyusuf1366 10 месяцев назад

    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  10 месяцев назад

      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.

  • @GodSahil
    @GodSahil Год назад +1

    "churn" lol

  • @gigigem5631
    @gigigem5631 2 года назад +2

    Thank you!

    • @CDcodes
      @CDcodes  2 года назад +1

      Happy to Help!

  • @mainkev
    @mainkev Год назад

    This is amazing, thanks

    • @CDcodes
      @CDcodes  Год назад

      You're very welcome!

  • @dommad1964
    @dommad1964 2 года назад

    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

  • @娇毅轨柴
    @娇毅轨柴 6 месяцев назад

    Amazing

  • @Bettybarnes42
    @Bettybarnes42 Год назад

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

    • @Andrzejkl94
      @Andrzejkl94 Год назад

      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 6 месяцев назад

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

    • @CDcodes
      @CDcodes  6 месяцев назад

      It is replit link in the description

  • @dzplayer0149
    @dzplayer0149 2 года назад

    my code isn't that great (it's almost twice as long as yours) but the game works perfectly.

    • @CDcodes
      @CDcodes  2 года назад

      Congrats on building the game! Working code is always better than pretty code that doesn't

  • @Simon-on6jv
    @Simon-on6jv 11 месяцев назад

    Which application are you using??

    • @CDcodes
      @CDcodes  10 месяцев назад

      replit, link is in the description

  • @Lintang7
    @Lintang7 Год назад

    can it be run on vs code?

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

  • @faezenazari5047
    @faezenazari5047 Год назад +1

    Ok always x wins.. 🤣

  • @Amateurartist111
    @Amateurartist111 4 месяца назад

    Thank you