Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, your goal is to program the game TIC-TAC-TOE using what you have used in C as well as what you have learned

In this project, your goal is to program the game TIC-TAC-TOE using what you have used in C as well as what you have learned so far in C++. The game is not a hard one to play, but here is a refresher on the rules:

Rules: 1. There are two players per game

2. The game is played on a 3 by 3 grid.

3. The first player picks a position in the grid and places an X.

4. The second player picks a position in the grid not previously chosen and places an O.

5. The first player and second player go back and forth picking spots not previously chosen until one of two things happen: A winning situation where there are 3 Xs or 3 Os in a row, column, or diagonally. A Tie (or Cat) game where all spaces are taken but there is no winner.

Figure 1: The TIC-TAC-TOE grid. Columns are in letters, the rows are in numbers. Here you will do the following tasks:

1. Create a display function for the TIC-TAC-TOE game board that displays not only the 3 by 3 grid, but also the Xs, Os, and blank spaces. Use letters for the Columns, and numbers for the rows. The function needs to accept the board you created in main.

2. Ask the user for a Column and Row. Check to make sure that the information put in by the user is a possible playable position. For examples, the users can input a. A row or column outside the scope of the grid b. A character when asked for a number or a number when asked for a character (we wont try strings until later). c. A position already taken by an X or an O Let the player know if they made an error in their input (out of scope, wrong input, position already taken). Place an X in the position chosen.

3. The program will select a random position in the grid. If the position has already been taken, the program will select a random position until the grid position chosen is available.

4. Tasks 2 and 3 repeat until either a winner is present OR all of the positions in the grid are taken. When this happens, the game is over and the program ends.

Recommendations:

1. Think about using a 2 dimensional character array of 3 by 3 size for the grid. Fill this character array with spaces ( ). This way you can check if the grid[row][column] == for availability. Display it using your display function, but this should make the game design a little easier. Every time the player puts in a position, grid[row][column] = X or grid[row][column] = O can be called.

2. Create functions checking if the grid is full and if there is a winner. Youll be checking for this several times and it just makes it easier to write functions that return a boolean value. The winner checker can be done with If else if else statements. The function that checks to see if the grid is full can be done with nested for loops.

3. When reading in information from the user, read it in a character. This way, you can read in A, B, C, 1, 2, and 3 and not worry about > or < comparisons. Take these characters and convert them to 0-2 integer values corresponding to column and rows in the 3 by 3 array grid.

Grading:

main.cpp and makefile

Program displays blank 3 by 3 grid in readable format.

Display is done through a function

Grid display shows labeled columns (Letters) and rows (Numbers).

Program asks user for Column and Row

Program will re-ask user for column and/or row if wrong information type is put in.

Program will re-ask for column and row if a position chosen is already taken

Program places an X at the location the user chooses.

Program randomly chooses location within the grid for O

Program verifies that location for O is not already taken. If the position is taken, program randomly chooses location until location is not already taken.

Program displays grid with updated playing field.

Program keeps running until winner condition is satisfied or when playing grid is full. Appendix: Comment Header

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

More Books

Students also viewed these Databases questions