this code should be in python: First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as “X”. •The players (computer and the user) will then take turns in playing. The computer will choose a random empty spot on its turn. The user enters its choice in the console. • Each of the empty spots have a corresponding number that the players choose on their turn. If the user enters anything other than the number of an empty spot (not yet filled with “X” or “O”), it will not be accepted, and they will be prompted to enter a correct number. After each turn, two things need to be done: 1) displaying the updated board 2) checking if anyone has won (it should be printed who has won – the user or the computer). • The game goes on until someone wins or until all the 9 empty spots are filled and no one has won. When the game ends, the user should see the message saying who has won (even if no one). You should implement at least the two following functions : DisplayBoard(board) Parameter board is a dictionary containing the non-empty spots of the board. This function does not return anything. It will just print the content of the board as depicted in Gameplay example. HasWon(board) Parameter board is a dictionary containing the non-empty spots of the board. This function determines if anyone has won and returns a suitable value (up to you how you want to handle the returned value). Creating other functions can be helpful (such as checking if the user input is valid, the general gameplay, etc.). The design and implementation of other functions is up to you.
this code should be in python: First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as “X”. •The players (computer and the user) will then take turns in playing. The computer will
choose a random empty spot on its turn. The user enters its choice in the console.
• Each of the empty spots have a corresponding number that the players choose on their
turn. If the user enters anything other than the number of an empty spot (not yet filled
with “X” or “O”), it will not be accepted, and they will be prompted to enter a correct
number. After each turn, two things need to be done: 1) displaying the updated board 2) checking
if anyone has won (it should be printed who has won – the user or the computer).
• The game goes on until someone wins or until all the 9 empty spots are filled and no one
has won. When the game ends, the user should see the message saying who has won
(even if no one).
You should implement at least the two following functions :
DisplayBoard(board)
Parameter board is a dictionary containing the non-empty spots of the board.
This function does not return anything. It will just print the content of the
board as depicted in Gameplay example.
HasWon(board)
Parameter board is a dictionary containing the non-empty spots of the board.
This function determines if anyone has won and returns a suitable value (up to
you how you want to handle the returned value).
Creating other functions can be helpful (such as checking if the user input is valid, the general
gameplay, etc.). The design and implementation of other functions is up to you.
Step by step
Solved in 3 steps