Question: 1.Create a TicTacToe game using C++ by utilizing multidimensional arrays and functions. Use a two-dimensional 3x3 array to represent the game board. Use char as

1.Create a TicTacToe game using C++ by utilizing multidimensional arrays and functions. Use a two-dimensional 3x3 array to represent the game board. Use char as your datatype. The board holds 3 distinct values. 0 (zero) if the space is empty, 1 if the space is taken by the "X" player(player1), -1 if the space is taken by the "O" player(player2). 2.You must use: std::array, 3>board = {0}; and not int board[3][3];

Player "X" will start first. So after initially outputting the board full of 0(zeros) Moves are determined by inputting rows, columns where r is a 0-based index for the row and c is a 0-based index for the column. In this format, (0,0) is the upper left corner of the board and (1,1) is the "middle space". You will need to use cin to scan these values from the user, but the comma gets in the way. Use a "dummy" variable appropriate for storing a comma, and cin that variable to remove the comma from the keyboard buffer.

In this step, you will use a function called GetMove, which takes two integer pointers and fills them in with the inputs from the user. The main function will pass in pointers to local variables to the function GetMove, and when GetMove is done, main's variables should be updated with the input.

3.Check the square the user chose to make sure it is in bounds and currently empty (what value will be in the array if its empty?) If the square is occupied, loop and ask the player to choose a valid move again.

4.Once a valid square is chosen, update the game board by writing a 1 or -1 to the chosen space according to whose turn it is. 5.Change your variable for whos turn it is, then loop back to step 2. (Output the board; ask for a move; verify the move; update the game) Complete a total of 9 game loops, one for each square in the board.

6. Dont need to check for winner. Just complete a total of 9 game loops

Use the tictactoe.h:

The header contains declarations for functions you will need to write and use in your implementation, along with comments about how they should work.

// PrintBoard takes a 2-dimensional array parameter representing the game state // and prints it to cout. See the spec for details on formatting the output. void PrintBoard(std::array, 3> board);

// GetMove uses cin to read the user's choice for where to move next on the // board. It does NOT update the game board with the move choice; it simply // scans in values to the row and col variables, which will update whatever // variables were used as arguments in the main. Do not check move validity // in this function. void GetMove(int *row, int *col);

// MoveIsValid returns true if the board is empty at the requested row/col, // and false otherwise. Used in main to see if the move is valid and alert // the user if it is not. bool MoveIsValid(std::array, 3> board, int row, int col);

Create a TicTacToe.cpp to implement the methods declared in TicTacToe.h Finally add a source file main.cpp and implement the main function.

Output examples:

- 0 1 2 0 . . . 1 . X . 2 0 . . X's turn: 1,1 That space is already taken!

X's turn: 2,0

That space is already taken!

X's turn: 1,0 - 0 1 2 0 . . . 1 X X . 2 0 . . 0's turn:

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