Python TIC TAC TOE Tutorial | Beginner Friendly Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 มี.ค. 2021
  • Tic tac toe tutorial in python. Hey everyone! In today's video I showcase an ultra-beginner friendly project all beginners should try. We reinforce many beginner skills and end up with a great product! As I said in the video, linked below is the source code:
    Source code: github.com/watsojar/tictactoe
    On this channel we focus on all things Python. Whether it is a project tutorial/showcase, teaching different Python concepts, or just live coding this is one of the best channels for programmers. Check out my links down below 👇
    Links:
    Patreon: / codecoach
    Github: github.com/watsojar
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 215

  • @Fresco7
    @Fresco7 2 ปีที่แล้ว +121

    board = ['-', '-', '-',
    '-', '-', '-',
    '-', '-', '-']
    currentPlayer = "X"
    winner = None
    gameRunning = True
    #printing board
    def printBoard(board):
    print(board[0] + " | " + board[1] + " | " + board[2])
    print("-" * 9)
    print(board[3] + " | " + board[4] + " | " + board[5])
    print("-" * 9)
    print(board[6] + " | " + board[7] + " | " + board[8])
    #take player input
    def playerInput(board):
    while True:
    if currentPlayer == "X":
    inp = int(input(f"Enter a number 1-9 \033[1;34m Player (X) \033[0;0m : "))
    else:
    inp = int(input(f"Enter a number 1-9 \033[1;31m Player (0) \033[0;0m : "))
    if inp >= 1 and inp

  • @samreither
    @samreither 2 ปีที่แล้ว +46

    my man... this was a great video. I love how you lay this out. I've tried watching other basic python projects but have trouble following other people's thinking, but your's came really intuitive to me so THANK YOU. Gonna be watching more of your vids for sure. Thanks again!

  • @arslan5829
    @arslan5829 ปีที่แล้ว +2

    Excellent; I will return to this one once I finish my weekly assignments. Great video!

  • @subhransu7810
    @subhransu7810 ปีที่แล้ว +8

    so damn awesome my man. i loved it all the way. my first big project in learning python. thanks for the tutorial.

  • @Caroline-pb8xx
    @Caroline-pb8xx 11 หลายเดือนก่อน

    you make it so easy to understand, but actually making it and developing the program is a whole different story!

  • @Yinyang1277
    @Yinyang1277 11 หลายเดือนก่อน +3

    after dealing with some hiccups throughout this tutorial. I noticed there were some indentation errors for me, but overall I got it to work in the end! Thank you for your tutorial as this was my first ever project and I am getting a grasp on the terminology.

  • @denisem1951
    @denisem1951 ปีที่แล้ว +2

    You explained this better than how my professor explain python... thank you!!

  • @iiiiiiiiii8489
    @iiiiiiiiii8489 ปีที่แล้ว

    great video looking forward to seeing another project thank you for all the help.

  • @alzhanvoid
    @alzhanvoid ปีที่แล้ว +2

    Hey when the game ends with a horizontal or diag or row as the last input (no "-" on the board remaining but last input made one of 3 lines) it still says that it's a tie despite clearly being a win for one of the players. How can I fix this?

  • @vanlang9959
    @vanlang9959 2 ปีที่แล้ว +5

    Great beginner-friendly tutorial on how to build a simple project like TicTacToe!

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      Glad it was helpful!

  • @alafleur39
    @alafleur39 2 ปีที่แล้ว +3

    this is a very clear and concise tutorial

  • @fulamstrong7921
    @fulamstrong7921 9 หลายเดือนก่อน +1

    The best lecture to me as a beginner ,thanks.

  • @PeppyHannah
    @PeppyHannah 8 หลายเดือนก่อน +1

    This was really fun to do, thank you so much! Do you think you could possibly do some Python tutorials for complete beginners? The way you teach and explain what you're doing is the best and would love to see it in Python tutorials 😆

  • @soumitakar4373
    @soumitakar4373 หลายเดือนก่อน

    Most simplest video on yt, Thanks a lot.

  • @user-mx7qp9ls3o
    @user-mx7qp9ls3o ปีที่แล้ว +1

    Thanks for this, ive been learning python for a few weeks and i did a few projects and yet i still had some trouble with the basics...

  • @theoracle.cescido
    @theoracle.cescido ปีที่แล้ว

    Well explained and easy to understand . Great!!!

  • @faithnsikak1032
    @faithnsikak1032 ปีที่แล้ว +3

    This was really great ..your explanations and steps are great! excellent work. Thank you so much for this video.

    • @CodeCoachh
      @CodeCoachh  ปีที่แล้ว

      You're very welcome!

  • @_iam_seven_
    @_iam_seven_ ปีที่แล้ว +2

    the most easy way and literally easy to understand. The best tutorial

  • @mohammadadil5080
    @mohammadadil5080 ปีที่แล้ว

    The best tic tac toe tutorial.

  • @jacktyler924
    @jacktyler924 2 ปีที่แล้ว +1

    The video is awesome, quite enjoyed it!

  • @Rahul-ld6po
    @Rahul-ld6po 2 ปีที่แล้ว

    thanks man im a beginner and ive seen like 3 tutorials and yours is the most easy to understand.

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      Glad I could help, thanks for the support!

  • @drsoundy
    @drsoundy 2 ปีที่แล้ว +10

    Something is false I think. If you use a number which is already taken, the player switch. So one person can play two times if the other took a number which has alraedy been used (sry for bad english but hope y'all understand)

  • @LunchBox77
    @LunchBox77 2 ปีที่แล้ว

    Awesome video dude, very helpful

  • @blazetekchaos8498
    @blazetekchaos8498 ปีที่แล้ว +1

    This is a wonderful video, but in the case that the last move results in a win then it would print both the winner and also that it is a tie, what is a different way you could get around this?

  • @milestones3481
    @milestones3481 2 ปีที่แล้ว +4

    Thank you for a clear explanation. You are the best!!!

  • @BoddepallliKeshavaKumar-qx6hp
    @BoddepallliKeshavaKumar-qx6hp 2 หลายเดือนก่อน +1

    very nice video, good explanation and well understood . Thank You

  • @fulamstrong7921
    @fulamstrong7921 9 หลายเดือนก่อน +1

    I will like following you up till I fully understand programming.

  • @Jack_Merrett_
    @Jack_Merrett_ ปีที่แล้ว

    thanks this was a tremendous help!

  • @martinkichukov3144
    @martinkichukov3144 ปีที่แล้ว

    When the player inputs an invalid input (e.g. if 10 is inputted) it switches immediately to the next player so is there any way to fix that

  • @hanzalakhan-by8si
    @hanzalakhan-by8si ปีที่แล้ว

    thanks man it was so much helpful

  • @Mr.Phantom001
    @Mr.Phantom001 2 วันที่ผ่านมา

    Thanks mate for this help❤

  • @a.hannan_06
    @a.hannan_06 ปีที่แล้ว

    while running the "gamerunning func at 9:30 , its saying ""bool object is not callable""////--> how do we solve this??

  • @ulludots
    @ulludots ปีที่แล้ว

    by far the best workflow for Tic Toe Toe

  • @justpriyanshlife
    @justpriyanshlife ปีที่แล้ว

    Totally worth it!

  • @rudix4872
    @rudix4872 ปีที่แล้ว +3

    Great video, thank you very much :) however i have a slight problem. When the board is completely full and either player wins on the last move, it prints out above the board that the winner is ___ and bellow the board it says that it is a draw. Do you have the same problem od did I make a mistake? Thanks

    • @River8346
      @River8346 ปีที่แล้ว +1

      You didn't make a mistake! If you add a "exit()" command inside of the "def checkWin()" segment, it should work itself out:
      def checkWin():
      if checkDiagonal(board) or checkHorizontal(board) or checkRow(board):
      print(f"The winner is {winner}")
      gameRunning = False
      exit()
      Hope this helped!

  • @tasneemmotiwala3917
    @tasneemmotiwala3917 ปีที่แล้ว +1

    i dont know why but when ever i put in a number it shows oops player has taken the spot pls help

  • @user-dojgeo
    @user-dojgeo ปีที่แล้ว

    Thank you for giving me a good lecture, sir.

  • @RickyBascom
    @RickyBascom 2 ปีที่แล้ว +2

    thank you! this makes more sense than the free code camp one

  • @togicodes
    @togicodes ปีที่แล้ว +1

    What is your vscode theme?

  • @River8346
    @River8346 ปีที่แล้ว +6

    For those who found the bug that appears when the last input is a winning move, and it displays both the Win AND Tie text, this should fix it. If you add a "exit()" command inside of the "def checkWin()" segment, it should work itself out:
    def checkWin():
    if checkDiagonal(board) or checkHorizontal(board) or checkRow(board):
    print(f"The winner is {winner}")
    gameRunning = False
    exit()
    Since the gameRunning loop checks for a Win BEFORE it checks for a Tie, you only have to apply this to the "def checkWin()" segment :)

    • @denisem1951
      @denisem1951 ปีที่แล้ว

      instead of exit() is there a different code that will just end the shell instead of exiting out of it?

    • @River8346
      @River8346 ปีที่แล้ว

      @@denisem1951 I don't think that the "exit()" line will literally exit the shell, only end the code. You can try "quit()" as well :). That should work too, although I haven't tried it.

    • @Caroline-pb8xx
      @Caroline-pb8xx 11 หลายเดือนก่อน +1

      WOW! how cool!

  • @thomashowald2592
    @thomashowald2592 ปีที่แล้ว

    thank you !!!!!! nice and clear.

  • @xzex2609
    @xzex2609 9 หลายเดือนก่อน +3

    Obviously you are coming from JS , in python we do board = ["-"] * 9 and you don't need to pass board to the function cause it's on global scope and functions defined after that has access to the board.

  • @__ikiran
    @__ikiran 10 หลายเดือนก่อน

    such an amazing video bro

  • @adarabdulaev
    @adarabdulaev 7 หลายเดือนก่อน

    Great tutorial

  • @thanapalthanapal9838
    @thanapalthanapal9838 2 หลายเดือนก่อน

    tnk u so much, it very helpful

  • @emmanuellemus3942
    @emmanuellemus3942 ปีที่แล้ว +1

    what is the website called?

  • @i11usion
    @i11usion 2 หลายเดือนก่อน

    Thank you!

  • @Kira-dw7ko
    @Kira-dw7ko ปีที่แล้ว +1

    hi, how can i make it on 3 wins?

  • @slavonian_stud
    @slavonian_stud ปีที่แล้ว

    amazing, thank you

  • @vatsaljohar9646
    @vatsaljohar9646 ปีที่แล้ว

    there is one bug in this code and I'm not able to figure out how to correct it. if player x wins still o takes the turn and then winner is declared

  • @samatamotors2299
    @samatamotors2299 3 หลายเดือนก่อน

    Thank you so much life save!

  • @uchejanefrances5249
    @uchejanefrances5249 ปีที่แล้ว

    When I run my python code on visual studio code the numeric keys are not working why is that?
    Enter your name 1-9: .my numeric keys aren't working in this line why?

  • @alicemureverwi4910
    @alicemureverwi4910 2 ปีที่แล้ว +1

    Hi great tutorial really helpful. I was following your code and I get stuck when you create the function checkWin, when i create my if loop and try to call the other functions that check for rows, columns and diagonally I get an error message that those 3 functions dont exist. I cant figure out why this could be

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      I would make sure the functions are spelled the same in both places - sorry for the late reply

  • @myblessed
    @myblessed 2 ปีที่แล้ว +2

    awesome tutorial!

  • @edenlee7752
    @edenlee7752 2 ปีที่แล้ว +1

    Hi @coachcode for the code board(inp-1) == "-" at 8:02 of the video
    I understand that it is to check if the position picked on the board by the player is empty. But why is there -1 from inp? Shouldn't it be just board(inp) to check the availability of the position picked by the player on the board?

    • @d1ylor266
      @d1ylor266 2 ปีที่แล้ว +5

      Basically, a program counts a list like 0, 1, 2, 3, 4 and we usually count a list like 1, 2, 3, 4, 5. So when the person inputs a 6 we want to convert it to a computer number which is five or (input-1). (hope this helps)

    • @262626VJ26
      @262626VJ26 2 ปีที่แล้ว

      @@d1ylor266 so you mean like last number in that list?

    • @mrup4825
      @mrup4825 2 ปีที่แล้ว +2

      @@262626VJ26 the indexes in the list go from 0 to 8 but the numbers you input go from 1 to 9 so you have to subtract one from the input to get the correct index

  • @Raf-01
    @Raf-01 11 หลายเดือนก่อน

    Great Explanation and video, i was just wondering is there a way to end the code if someone wins

  • @woovs101
    @woovs101 ปีที่แล้ว +2

    I m wondering how to get the game to reset after the win. I was thinking that after gamerunning = false you could break the loop... but doesn't seem to work for me... any tips?

    • @anasmahdi5149
      @anasmahdi5149 ปีที่แล้ว

      yeah same here ,after winning the game , the game is not resetting automatically. gameRunning = False is also not working for me

  • @CodeCoachh
    @CodeCoachh  3 ปีที่แล้ว +10

    Let me know what you guys think!

    • @AlExItOXD409
      @AlExItOXD409 2 ปีที่แล้ว

      Hi coach! I was testing your program and i found an error. When you insert a number that is already occupied, it stills switching the turn and enables the x or o user to make 2 moves in a row. Do you know how can i solve it. Thanks for your help :)

    • @thereverend01
      @thereverend01 2 ปีที่แล้ว

      hi how can we make this using A* algo? would really appreciate if you could teach it

    • @msvisoko9105
      @msvisoko9105 2 ปีที่แล้ว

      @@AlExItOXD409 I did player input like this and it works fine (no switching error):
      def player_input(board):
      while True:
      try:
      inp = int(input("Enter a number 1-9: "))
      if 1

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว +1

      @@thereverend01 Planning on doing this tutorial before the end of the summer!

  • @user-vi5kg5ue3h
    @user-vi5kg5ue3h 2 หลายเดือนก่อน

    keep going bro

  • @ayeitzbam
    @ayeitzbam ปีที่แล้ว

    I’m new to coding does this have a list and a function?

  • @katilehtonen614
    @katilehtonen614 ปีที่แล้ว +1

    using this as a base, how could I make a "star menu" at the beginning where you can choose if you want to play against the computer or a friend?

    • @bartpekelaer8047
      @bartpekelaer8047 ปีที่แล้ว +1

      def start_game():
      mode = input('Choose mode pvp/ai: ')
      if mode == 'pvp':
      run_pvp()
      else:
      run_ai()
      def run_pvp():
      while game_running:
      print_board(board)
      player_input(board)
      check_win()
      check_tie(board)
      switch_player()
      def run_ai():
      while game_running:
      print_board(board)
      player_input(board)
      check_win()
      check_tie(board)
      switch_player()
      ai_player(board)
      check_win()
      check_tie(board)
      start_game()
      this would be a way to handle both computer and player.
      *note i changed some function names to my liking but should be clear in reference to the tutorial

  • @user-zn5ct3yz3z
    @user-zn5ct3yz3z 10 หลายเดือนก่อน

    Great video!!!!!!!!!!
    ❤❤❤❤

  • @johanandrescastrillongonza740
    @johanandrescastrillongonza740 2 ปีที่แล้ว

    thank you so much exelent video

  • @clovergrey
    @clovergrey ปีที่แล้ว

    How do I create the option to replay the game instead of exiting?

  • @SlytherinLassie
    @SlytherinLassie หลายเดือนก่อน

    I didn't understand the "board[inp-1]" thing in the function of playerInput.

  • @iwatchanime9789
    @iwatchanime9789 2 หลายเดือนก่อน

    HELP great vid i copied it perfectly but im jw how do i get in the terminal mine isnt like urs also i cant run the program it says error "cant find __main__" i put this in a new file im 1 week into coding so i probably didnt do something very basic

  • @ghoulzexz5135
    @ghoulzexz5135 2 ปีที่แล้ว

    brilliant video really helped me out thanks alot

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      I am glad I could help!

  • @sreekalaranjit2938
    @sreekalaranjit2938 ปีที่แล้ว

    why do you send the board variable in the arguments if its already global? wont it be otherwise accesible?

    • @CodeCoachh
      @CodeCoachh  ปีที่แล้ว

      Within the scope of the function any variable is classified as local (not existing outside the function) unless passed as a parameter or declared as global.

  • @riskatjukyungssi8858
    @riskatjukyungssi8858 ปีที่แล้ว

    I tried running it @9:39 but it keeps telling me “oops player is already in that spot” but there’s no player. I need help

  • @SuperAxon2
    @SuperAxon2 2 ปีที่แล้ว +1

    After print("Oops player already on that spot") executes, the computer keeps playing until the game ends, which crashes it.
    I added the switchPlayer() function right below the print. That solved the issue.

  • @coderxyz4990
    @coderxyz4990 ปีที่แล้ว

    Its Amazing

  • @alealvarado4793
    @alealvarado4793 2 ปีที่แล้ว

    great tutorial it saved my term

  • @zayinconde8971
    @zayinconde8971 ปีที่แล้ว

    i didnt get how the "global" works, both with "global currentPlayer" and "global winner"?

  • @realperson9951
    @realperson9951 2 ปีที่แล้ว +1

    i have a few problems when i was copying the code
    1. the board was printed twice in the beginning
    2. when i put an occupied space as X, the current player next turn would be changed to O
    3. it says there is a problem at "position = random.randint(0, 8) and i dont know how to fix this

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      It’s hard for me to debug considering I do not have ur code but 2 sounds correct and for 3 I would double check you imported random.

    • @realperson9951
      @realperson9951 2 ปีที่แล้ว

      @@CodeCoachh i'll check it later today and import random, thanks

  • @isabellapucci2098
    @isabellapucci2098 ปีที่แล้ว +1

    Thank you for this video!!! I have to do a project for my programming class and this has helped me understand a ton!!
    I have to use Matlab… I think it’s doable as long as some changes are made for the language… do you think this would be a possibility?

    • @CodeCoachh
      @CodeCoachh  ปีที่แล้ว

      I’m sure it can be done tic tac toe is pretty simple.

  • @exED
    @exED ปีที่แล้ว

    hi just wanted to ask, what does
    "-1" in board[inp-1] == "-" ?

    • @CodeCoachh
      @CodeCoachh  ปีที่แล้ว

      Here we are checking if the position in the board the user inputted is equal to “-“ to see if that is an empty position as the array board was initialized containing “-“ and input -1 is the index of the position we must check.

  • @nokhinsiu7210
    @nokhinsiu7210 2 ปีที่แล้ว

    I tested it but it broke at the change player help

  • @moritzpfurtscheller4248
    @moritzpfurtscheller4248 2 ปีที่แล้ว

    great video thanks alot:)

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว +1

      Glad you liked it!

  • @ryanm8431
    @ryanm8431 2 ปีที่แล้ว +3

    i understood most of this but why is the -1 place in the [inp-1 ] ?
    if inp >= 1 and inp

    • @nicolasliegeard1401
      @nicolasliegeard1401 2 ปีที่แล้ว +8

      Because the board starts at index 0, so it goes from board[0] up to board[8] while we asked the user to choose a number between 1-9

    • @godza4735
      @godza4735 2 ปีที่แล้ว

      to avoid index out of range

  • @srinivaspulleti2003
    @srinivaspulleti2003 ปีที่แล้ว

    thanks for code

  • @user-pu4eb7ew5g
    @user-pu4eb7ew5g 6 หลายเดือนก่อน

    Nice video thank you , only had to change it on playerInput , because if there was a "oops blablabla.." it would switch to the next player , so you can fill the rest of the grid with only O or only X if you want :
    def playerInput(board):
    while True:
    user_input = int(input("Enter a number 1-9: "))
    if user_input >= 1 and user_input

  • @Jed.7
    @Jed.7 ปีที่แล้ว

    Thanks

  • @shrithikvardhan
    @shrithikvardhan 2 ปีที่แล้ว +2

    can you code tic tac toe which is multiplayer and vs computer , with scores and time

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      Basic multiplayer requires a lot more code and gets pretty advanced but maybe if I have a lot of time over a long weekend I can try and learn how to do it! In the mean time, I just published a video creating an unbeatable AI to play against in this tic tac toe game

  • @omatamaneenyanga1586
    @omatamaneenyanga1586 6 หลายเดือนก่อน

    My python isn't showing the board and it Python 3.12.0

  • @gilbertgonzalez7766
    @gilbertgonzalez7766 2 ปีที่แล้ว +2

    Best tic tac toe tutorial on TH-cam

  • @mansuriaziz
    @mansuriaziz 2 ปีที่แล้ว

    thanks, very nice and clear about contents the only thing I was curious to know is how can we make computer to try to win rather than throwing random input

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      There are a couple algorithms which can be implemented to improve the computer. The most common is the mini max algorithm and I could potentially make a video adding that feature to the game.

  • @mxo709
    @mxo709 ปีที่แล้ว

    Hi, i've found 2 big problems...first if you pplay against the computer he can't win, second if then computer win the game continue and if you win the game give you the win and when the board is full it's a tie. If you play against yourself using this combination of number (1-2-3-4-5-6-8-7-9) the game give you the win but it's a tie and immediately after the game print that it's a tie because the board is full...I'm trying to find where the problems, did you had already found them?

    • @fnni3720
      @fnni3720 ปีที่แล้ว

      if you combine the checkTie def with the checkWin def...
      example:
      def checkWinOrTie(board):
      global gameRunning
      if checkHorizontal(board) or checkRow(board) or checkDiag(board):
      print(f"The winner is {winner}!")
      gameRunning = False
      elif "-" not in board:
      print("It is a Tie!")
      gameRunning = False
      ...I think that should fix the problem with the tie print

  • @gkof23
    @gkof23 2 ปีที่แล้ว

    on line 87
    def computer(board)
    why do you set the position that the computer can pick from 1-8 only ? why not 1-9 ?

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว +1

      That is because in programming counting always starts at 0. In this game we represented the game board as an array of strings with each index representing a spot on the board - so in order to set a random position all we have to do is generate a random number excluding 9 as 8 is the max index in the list. I hope this made sense!

    • @gkof23
      @gkof23 2 ปีที่แล้ว

      @@CodeCoachh Thank you for the explanation, but if that's the case, why is it not 0-8?

  • @favouritemusichub244
    @favouritemusichub244 ปีที่แล้ว

    thanks g😃

  • @manoville3840
    @manoville3840 2 ปีที่แล้ว +2

    Great vid coach… I was wondering how to code it so that the bot doesn’t always win… can u make a vid on that?

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว +1

      Was up Nate! Check my response on the minimax video!

  • @hell0kitje
    @hell0kitje 2 ปีที่แล้ว

    color theme name?

  • @kodama7132
    @kodama7132 6 หลายเดือนก่อน

    so with this im finding that if you choose a spot that is already taken, it still switches currentPlayer variable and skips your turn

    • @Marci.K
      @Marci.K 5 หลายเดือนก่อน

      You can fix this by removing switchPlayer() from the while cycle and put it in the playerInput under the if statement

  • @skylorhamilton9151
    @skylorhamilton9151 2 หลายเดือนก่อน

    Oddly I'm getting "oops player is already in that spot when entering 1. 2-9 is cool though. There's a dash in the 1 position in the code just like 2-9. The computer is able to use position 1 though.

  • @kamat069
    @kamat069 2 ปีที่แล้ว +1

    It was a really nice and informativ Video, I learned a lot from you!
    But I found 1 small bug. If you choose a number that was already picked, the Computer atomatically just picks another spot so hes in the lead.
    But i fixed it with just one line: Where you printed the line "Oops player already in that spot"
    Write underneath switchPlayer()
    And your done it just switches back to you.
    I hope you know what I mean by that.

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว

      Yes, some others pointed out my flaw in my logic here I’m glad you were able to figure out my error!

  • @XxAbdo
    @XxAbdo 2 ปีที่แล้ว

    what is the theme that you are using

    • @CodeCoachh
      @CodeCoachh  2 ปีที่แล้ว +1

      I do not really remember which theme it was. It was a while ago on a different laptop. Sorry I could not be more helpful.

  • @juppeeez
    @juppeeez 2 ปีที่แล้ว

    does anyone have a fix for computer making one extra move after I win the game? The code in the github does it as well

    • @SAN925
      @SAN925 2 ปีที่แล้ว +1

      I did some minor tweaking in the code but if you still want it I can update my code to add a computer to it and fix it

    • @SAN925
      @SAN925 2 ปีที่แล้ว +1

      def computerPlayer(board):
      while currentPlayer == 'O' and gameRunning:
      pos = random.randint(0, 8)
      if board[pos] == "-":
      board[pos] = 'O'
      switchPlayer()
      you need to add "and gameRunning" to the while statement and it fixes it

  • @Personpac
    @Personpac ปีที่แล้ว

    I made a couple edits to the code but the switchPlayer function isn't working anymore and only placing X, can you help?
    #Building Board
    board = ['-', '-', '-',
    '-', '-', '-',
    '-', '-', '-']
    currentPlayer = "X"
    winner = None
    gameRunning = True
    def printBoard(board):
    print(board[0] + ' | ' + board[1] + ' | ' + board[2])
    print('----------')
    print(board[3] + ' | ' + board[4] + ' | ' + board[5])
    print('----------')
    print(board[6] + ' | ' + board[7] + ' | ' + board[8])
    #Player Input
    def playerInput(board):
    inp = int(input('Enter a Number 1-9: '))
    if inp >= 1 and inp

    • @Personpac
      @Personpac ปีที่แล้ว

      nvm i just put a double instead of single equal sign on the currentPlayer = "o" bit

  • @pavelpolosin2217
    @pavelpolosin2217 หลายเดือนก่อน

    I don't understand. How is possible to equal board[inp - 1] = current_player. But current_player variable is a string type, and inp - integer

    • @Aqua001_
      @Aqua001_ 4 วันที่ผ่านมา

      8:28
      That [inp-1] is to find the index(Since the player input starts at 1 and the board index starts at 0 we sub the 1) after that we assign the player input to the board accourding to the index.
      Therefore it is Board[index] = playerInp.

  • @remist
    @remist 2 ปีที่แล้ว +3

    bruh this tutorial confused me a lot haha but thanks anywayys

  • @sunitsawant885
    @sunitsawant885 6 หลายเดือนก่อน

    Cant run it again please help