May-04-2020, 03:22 PM
#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