Question: Tic - Tac - Toe Game Write a program that allows two players to play a game of tic - tac - toe. Use a

Tic-Tac-Toe Game
Write a program that allows two players to play a game of tic-tac-toe. Use a twe. dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run ?a loop that does the following:
Displays the contents of the board array.
Allows player 1 to select a location on the board for an X. The program should alk the user to enter the row and column numbers.
Allows player 2 to select a location on the board for an O. The program should ask the user to enter the row and column numbers.
Determines whether a player has won, or a tie has occurred. If a player has won, the program should declare that player the winner and end. If a tie has occurred, the program should display an appropriate message and end.
Player 1 wins when there are three Xs in a row on the game board. The Xs can appear in row, in a column, or diagonally across the board. Player 2 wins when there are three Os in a row on the game board. The Os can appear in a row, in a column, or diagonally across the board. A tie occurs when all of the locations on the board are full, but there is no winner.
A 2-D array is required to store the board and needs to be passed between functions.
You nut have the following functions.
void load(char b[3][3]); //stores the values 1-9 in the initial board so the user con select a number (position) to place an X or an O
void display(const char b[3][3]); //displays the current status of the board
bool valid_move(const char b[3][3], int pos); //verifies that the position is in the range 1-9 and has not already been taken
bool winner(const char b[3][3]); //checks after each play to see if X or O has won the game
additional functions can be added if needed
The game needs to allow for the user to re-play
Displaying the board needs to be visually appealing by either drawing the board or spacing appropriately
Things to consider when developing the game
If the user inputs an invalid position (either off the board or already taken) the user needs to be able to re-enter their choice
When someone wins a message needs to be displayed and the game ends
If the board is full and there is not a winner a message stating the game was a draw needs to be displayed
12|3||
-+-+-
4|5|6
-+-+-
|8|9
Player x where do you want to play? 1
x|2|3
-+-+-
4|5|6
-+-+-
7|8|9
Player 0 where do you want to play? 0
That is not on the board.
Player 0 where do you want to play? 1
That possition has already been played.
Player O where do you want to play? 5
x|2|3
-+-+-
4|6
-+-+-
7|8/9
Player X where do you want to play?
lote: The int 9 is not the same as the char 9. The ASCII value of char 9 is int 057. You can find all of the ASCII values in the chart on pages 1287-1288.1
Tic - Tac - Toe Game Write a program that allows

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 Programming Questions!