#describing the board board = [" ", " ", " ", " ", " ", " ", " ", " ", " "] #making the board def print_board(): print(board[0] + '|' + board[1] + '|' + board[2]) print('-+-+-') print(board[3] + '|' + board[4] + '|' + board[5]) print('-+-+-') print(board[6] + '|' + board[7] + '|' + board[8]) #A counter to track the player's moves count = 0 #main loop while True: print_board() #PLAYER 1 p1 = input('YOU ARE "X", Pick a number from 0-8 ') p1 = int(p1) board[p1] = 'X' count+=1 print(count) #Rules of the game if board[0] == board[1] == board[2] != " ": print('player 1 wins the game') break elif board[3] == board[4] == board[5] != " ": print('player 1 wins the game') break elif board[6] == board[7] == board[8] != " ": print('player 1 wins the game') break elif board[0] == board[3] == board[6] != " ": print('player 1 wins the game') break elif board[1] == board[4] == board[7] != " ": print('player 1 wins the game') break elif board[2] == board[5] == board[8] != " ": print('player 1 wins the game') break elif board[0] == board[4] == board[8] != " ": print('player 1 wins the game') break elif board[2] == board[4] == board[6] != " ": print('player 1 wins the game') break print_board() #PLAYER 2 p2 = input('YOU ARE "O", please choose a position 0-8 ') p2 = int(p2) board[p2] = 'O' count+=1 print(count) if board[0] == board[1] == board[2] != " ": print('player 2 wins the game') break elif board[3] == board[4] == board[5] != " ": print('player 2 wins the game') break elif board[6] == board[7] == board[8] != " ": print('player 2 wins the game') break elif board[0] == board[3] == board[6] != " ": print('player 2 wins the game') break elif board[1] == board[4] == board[7] != " ": print('player 2 wins the game') break elif board[2] == board[5] == board[8] != " ": print('player 2 wins the game') break elif board[0] == board[4] == board[8] != " ": print('player 2 wins the game') break elif board[2] == board[4] == board[6] != " ": print('player 2 wins the game') break #checking for ties if count >= 8: print('THE GAME ENDS WITH A TIE') break
Please review and suggest some modifications about my TIC-TAC-TOE programme
Please review and suggest some modifications about my TIC-TAC-TOE programme
|
May-04-2020, 05:09 PM
It didn't run for me. It printed the game board and that was it.
May-05-2020, 04:45 AM
No, It works i have tested it more than 10 times By the way this is my first game program and I have posted on a forum for the first time so, If there are some mistakes Please let me know.
Thank you.
May-05-2020, 10:40 AM
(This post was last modified: May-05-2020, 10:41 AM by pyzyx3qwerty.)
(May-04-2020, 05:09 PM)michael1789 Wrote: It didn't run for me. It printed the game board and that was it.It runs for me :/ Are you sure have ran it completely? (May-05-2020, 04:45 AM)MohammedSohail Wrote: No, It works i have tested it more than 10 times By the way this is my first game program and I have posted on a forum for the first time so, If there are some mistakes Please let me know.It's a fine code. I ran it and didn't come across any mistakes. I would have gone for it using built in functions, but your approach is fine
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela Need help on the forum? Visit help @ python forum For learning more and more about python, visit Python docs |
|
Users browsing this thread: 1 Guest(s)