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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!