Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tic-Tac-Toe is normally played with two people. One player is X and the other player is O. Players take turns placing their X or O.

Tic-Tac-Toe is normally played with two people. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of their marks on the board in a row, column, or diagonal, they win. When the board fills up with neither player winning, the game ends in a draw. In this version you will design your game to be played by two players, but in part B you will modify it to have the user play against the computer.

You will need two variable to represent the players (player1 and player2). One variable will hold 'X' and the other variable will hold 'O'. A player makes their move by entering the number of the space they want to take. To help us remember which index in the list is for which space, we'll number the board like a keyboard's number pad, as shown below:

image text in transcribedimage text in transcribed

Represent the Tic-Tac-Toe board in your program as a list of strings named board. Each string represents one of the nine spaces on the board. The strings are either 'X' for the X player, 'O' for the O player, or a single space ' ' for a blank space. Remember that we're laying out the board like a number pad on a keyboard. You can make the list length 10 and have the program ignore the string in index 0 of the list so that the player will enter a number from 1 to 9 to tell the game which space they want to move on.

Include the following procedures in your program:

def drawBoard(board):

def whoGoesFirst( ): #randomly choose which player goes first and return that letter

def getPlayerMove(board): # input a move (1 -9) and return that move as an integer

def isSpaceFree(board, move): # return True if the space is free (a blank), return False otherwise

def makeMove(board, letter, move): # put the letter in the board at index move

def isWinner(board, letter): # return True if there is a horizontal, vertical or diagonal win, return False otherwise

def isBoardFull(board): # return True if the board is fill (has no blanks ' '), return False otherwise

7 8 9 4 5 6 1 2 3 NILK Tab 7 8 8 9 + 4 5 6 6 1 N 3 Enter 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions