CS160-Assignment 10- Tic-Tac-Toe Solved

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Program Implementation                                     

You will write a program that plays the game Tic-Tac-Toe.

First, prompt the user to find out if they want to play with one or two players.  If the user wants to play with only one player, then the computer must be the other player.  You can choose whatever algorithm you want for the computer, i.e. picking random places to put the piece or intelligently selecting your move based on player 1’s selection.  However, you must not select a position that has already been selected at any time!!!

After you determine how many players are playing the game, then you can determine what character each player wants to choose.  You must make sure that Player 2 or the computer doesn’t choose the same character as Player 1.  Print the empty board, and then prompt the player(s) for their position on the board, printing the board after each turn.  Make sure that the player(s) chooses valid positions on the board!!!

Example Tic-Tac-Toe:

Congratulations Player 1, you are a winner!!!

Program Input:

  • Determine whether the user wants to play 1 or 2 players for Tic-Tac-Toe
  • The character/game piece each player wants.
  • Player’s choice of position on the board.

 

Program Output:

  • The view of the board after each player’s turn, along with an initial empty board.
  • A prompt asking for the player’s selection on the board.

 

Tic-Tac-Toe Error Handling:

  • Player’s choice is not appropriate, such as a non-positive int for row/column
  • Player chooses a position that is not on the board, i.e. row 5, column 2.
  • Player chooses a position that is already occupied.
  • Player 2 chooses Player 1’s character.

Some functions you might want to include are an initialize_board(), which initializes the board to spaces, a get_player_piece() that allows players to pick their pieces, i.e. ‘X’ or ‘O’,  choose_next_move(), which fills the board with the player’s choice, a print_board() that prints the board to the screen after each user’s turn, is_full() to check if the board is full, a is_winner(), which checks to see if there is a winner, and a print_winner_results() that prints the results of the game to the screen.

 Program Design

Begin by designing you program using these steps, and write steps 1, 2, and 4 on paper or in a text editor.  Then, implement the program using Python.

  • Step 1: Problem Analysis. (10 pts)

Do you understand everything in the problem? List anything you do not fully understand, and make sure to ask a TA or instructor about anything you do not understand.

  • What are the user inputs/requirements, program outputs, etc.?
  • What assumptions are you are making?
  • What are the functional requirements of this problem?
  • What are all the tasks and subtasks in this problem?
  • Step 2: Program Design. (20 pts) List the specific steps needed to play the game of

TicTacToe.  What does the overall big picture of this program look like? (flowchart or pseudocode) o What are all the higher-level tasks to accomplish in this program, and where will you call each task?

  • What are the decisions that need to be made to determine which high-level tasks to complete?
  • Based on all the tasks you identified, what does the algorithm details in each task look like?

(flowchart or pseudocode)

▪ What are the decisions you’ll make within each task?

  • How and where are you going to handle bad input?

Based on your answers above, list the specific steps or provide a flowchart of what is needed to program Tic-Tac-Toe. Be very explicit!!!

 

  • Step 3: Program Implementation.

This is the Python code that plays TicTacToe.

 

  • Step 4: Program Testing. (10 pts)

Create a Test Plan with several test cases including good and bad cases.

 

 

  • Assignment10-izgy8t.zip