Sale!

Computer Science 220 Tic-Tac-Toe solved

Original price was: $35.00.Current price is: $30.00. $25.50

Description

5/5 - (4 votes)

Learning objectives:

  • Practice creating functions
  • Practice mutating lists within functions
  • Practice Boolean functions
  • Creating a logical solution

 

Assignment:

For this assignment you are asked to write a modular solution to the game of tic-tac-toe.  Here are functions you will need.  For each function add code to test them in main().  I have written the list below in an order that I think functions should be developed.  As desired you may have additional functions.

 

  • A method to build the board.  This method should create a list of the numbers 1 – 9 and return that list.
  • A void method to display the board.  (See sample displays below.)
  • A void method to fill a spot on the board.  This method will need to have the board, the position to be filled and the character to place in that position.  Do some error checking here so that the board doesn’t allow for letters other than ‘x’ and ‘y’.
  • A Boolean method to determine if a spot is a legal spot on the board.  Don’t allow the method mentioned in the previous bullet to execute if the spot isn’t legit.
  • A Boolean method to determine if the game has been won. (This requires a little thought. You can always skip it by just having it return False and thinking about it later.)
  • A Boolean method to determine if the game is over.  This should call the previously mentioned method plus check to make sure there are more plays allowed on the board.
  • A method to play the game.  This method should continue as long as the game is not over.  Once the game is over, display the message “Player 1 wins!”, “Player 2 wins”, or “Tie” as is appropriate.

 

Below are sample displayed boards.

 

The board original board before any players have played:

1 | 2 | 3

———

4 | 5 | 6

———

7 | 8 | 9

 

 

The board after player 1 played an “x” in position 5, player 2 played an “o” in position 7 and player 1 played and “x” in position 1:

X | 2 | 3

———

4 | X | 6

———

O | 8 | 9

 

Submission:

Upload tictactoe.py to your class account.

 

Policies:

The policies given in Program 1 are in effect for this and all assignments. Do not forget to include your name and the Certification of Authenticity.