Question: Do in Python Using the model for ticket-tac-toe described in chapter 5 create a complete tic-tac-toe game. The game should be able to determine if

Do in Python

Using the model for ticket-tac-toe described in chapter 5 create a complete tic-tac-toe game. The game should be able to determine if there is a winner and display who the winner is X or O. The game should have 1 player and two player mode. 2 player mode you would take turns with a friend. 1 player mode the computer would automatically select a free space. The game should only allow the user to select a free space for their move. After the game has finished and reported a winner the program should ask if the user would like to play again.

- 1 or 2 player mode for tic-tac-toe game - error check space entered - display the winner at the end of each game - ask users to play again - the model for the tic-tac-toe board should be a dictionary that was defined in chapter 5 - only allow users to move to a space that is not occupied and is valid

Sample game play: 1 player or 2 player mode? (1 or 2) 1 | | -+-+- | | -+-+- | | Turn for X. Move on which space? top-L X| | -+-+- | | -+-+- | | Turn for O. Bleep Blorp I'm a comptuer. X|O| -+-+- | | -+-+- | | Turn for X. Move on which space? . . . Turn for X. Move on which space? low-R X|O| -+-+- |X| -+-+- O| |X X won. Do you want to play again? y or n y 1 player or 2 player mode? (1 or 2)

Starting point

theBoard = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ', 'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ', 'low-L': ' ', 'low-M': ' ', 'low-R': ' '} def printBoard(board): print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R']) print('-+-+-') print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R']) print('-+-+-') print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])

turn = 'X' for i in range(9): printBoard(theBoard) print('Turn for ' + turn + '. Move on which space?') move = input() theBoard[move] = turn if turn == 'X': turn = 'O' else: turn = 'X' printBoard(theBoard)

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!