Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Start Game: ----- 1 2 3 4 5 6 7 8 9 ----- Player A, Please Enter move: 5 ----- 1

ID: 3630354 • Letter: S

Question



Start Game:
-----
1 2 3
4 5 6
7 8 9
-----
Player A, Please Enter move: 5
-----
1 2 3
4 X 6
7 8 9
-----
Player B, Please Enter move: 3
-----
1 2 O
4 X 6
7 8 9
-----
Player A, Please Enter move: 1
-----
X 2 O
4 X 6
7 8 9
-----
Player B, Please Enter move: 5
That space is taken, try again.
-----
X 2 O
4 X 6
7 8 9
-----
Player B, Please Enter move: 0
Invalid move, try again.
-----
X 2 O
4 X 6
7 8 9
-----
Player B, Please Enter move: 9
-----
X 2 O
4 X 6
7 8 O
-----
Player A, Please Enter move: 6
... ...
... ...
Player A, Please Enter move: 7
-----
O X O
X X O
X O X
-----
Game over!

You can start your program with the following steps. Make sure you understand each step and entire logic. It does not require to check for a win at this moment, since the main purpose is to practice with an array. You may try if you want.


// This function displays a board on the screen. It outputs each
// character in the array, putting a newline every three characters.

void showBoard(char board[])
{
cout << "-----" << endl;
for (int i=0; i<9;i++)
{
cout << board[i] << " ";
if ((i+1) % 3 == 0)
cout << endl;
}
cout << "-----" << endl;
}

// ====================
// main function
// ====================

int main()
{
char board[9]; // Holds digits, X, or O
int move, numMoves = 0; // Number of moves
char whoseTurn = 'X', player; // Current player's move

// Initialize board to character digits 1-9

// Loop to Get a move until all 9 moves used

// showBoard

// Decide Who is the player A or B to prompt

// Receive move

// Check if the move is not valid,
// let the player try again

// if the move is valid, 1 to 9

// Update move to index, as the array is 0 based, not 1 based

// if board[move] is filled by X or O, let the player try again

// if the move is OK to fill

// Assign 'X' or 'O' in whoseTurn to board[move]

// Switch turns - change whoseTurn

// Update numMoves

// End of Loop

// showBoard
// Say Game over!
}

At this moment, 5 points will be honored. If you are comfortable with all, go next to the challenging job by checking winner at each time you update the board. The suggested function is


bool CheckWin(char board[]);

Explanation / Answer

#include using namespace std; int main() { //PROTOTYPES void showBoard(char board[]); bool CheckWin(char board[]); //LOCAL DECLARATIONS char board[9]; int move; int numMoves = 0; char whoseTurn = 'X'; bool checkWin = false; //PROCEDURES for (int i = 0; i < 9; i++) { board[i] = i + 49; //See ANSCII Table: 49 = '1' = 0 + 49, 50 = '2' = 1 + 49, etc. } cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote