Question
Write a python code that Implement a game called Tic Tac Toe. Your game should ensure that each user makes a legal move, your game
Write a python code that Implement a game called Tic Tac Toe. Your game should ensure that each user makes a legal move, your game should print out who wins, when there is a winner or that it is a TIE if there are no more legal moves. After a game ends, your program should ask if they want to play again, if YES, clear the board and start again.
Hints:
def displayBoard(board):
for row in board:
for col in row:
print(col, end= '\t')
print(" ")
def makeMove(moveVal, board):
print(moveVal + " what row?", end= ' ')
row = int(input())
print(moveVal + " what col?", end= ' ')
col = int(input())
#ensure the move is legal or ask them again
board[row][col] = moveVal
def isWinner(board):
#return true if their is a winner and false otherwise
return False
def clearBoard(board):
#this function should perform the logic to clear the board
for rowNum in range(0, len(board)):
for colNum in range(0, len(board[rowNum])):
board[rowNum][colNum] = '_'
def playGame(board):
moves = ['X', 'O']
currPlayer = 0
while(isWinner(board) == False):
displayBoard(board)
makeMove(moves[currPlayer], board)
if(currPlayer == 0):
currPlayer = 1
else:
currPlayer = 0
#we want to ask if they want to play again
#if yes, clear the board and start over
board = [['_', '_', '_'], ['_', '_', '_'], ['_', '_', '_']]
playGame(board)
Help!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started