Question: How do I convert the code below to meet these requirements? // Tic-Tac-Toe #include #include #include #include using namespace std; // global constants const char


How do I convert the code below to meet these requirements?
// Tic-Tac-Toe #include #include #include #include using namespace std; // global constants const char X = 'X'; const char O = 'O'; const char EMPTY = ' '; const char TIE = 'T'; const char NO_ONE = 'N'; // function prototypes void instructions(); char askYesNo(string question); int askNumber(string question, int high, int low = 0); char humanPiece(); char opponent(char piece); void displayBoard(const vector& board); char winner(const vector& board); bool isLegal(const vector& board, int move); int humanMove(const vector& board, char human); int computerMove(vector board, char computer); void announceWinner(char winner, char computer, char human); // main function int main() { int move; const int NUM_SQUARES = 9; vector board(NUM_SQUARES, EMPTY); instructions(); const char human = humanPiece(); const char computer = opponent(human); char turn = X; displayBoard(board); while (winner(board) == NO_ONE) { if (turn == human) { move = humanMove(board, human); board[move] = human; } else { move = computerMove(board, computer); board[move] = computer; } displayBoard(board); turn = opponent(turn); } announceWinner(winner(board), computer, human); return 0; } // functions void instructions() { cout > response; } while (response != 'y' && response != 'n'); return response; } int askNumber(string question, int high, int low) { int number; do { cout > number; } while (number > high || number Write a class called Board that represents a tic-tac-toe board. It should have a 3x3 array as a data member, which will store the locations of the players' moves. It should have a default constructor that initializes the 3x3 array to being empty. It should have a method called makeMove that takes the x and y coordinates of the move (see the example below) and which player's turn it is as parameters. If that location is unoccupied, makeMove should record the move and return true. If that location is already occupied, makeMove should just return false. There should be a method called gameState that takes no parameters and returns one of the four following values: X_WON, O_WON DRAW, or UNFINISHED-use an enum for this, not strings (the enum definition should go in Board.hpp, before the Board class definition). There should also be a method called print, which just prints out the current board to the screen Write a class called TicTacToe that allows two people to play a game. This class will have a field for a Board object and a field to keep track of which player's turn it is. It should have a constructor that takes a char parameter that specifies whether 'x' or 'o' should have the first move. It should have a method called play that starts the game. The play method should keep looping, asking the correct player for their move and sending it to the board (with makeMove) until someone has won or it's a draw (as indicated by gameState), and then declare what the outcome was Write a main method (in TicTacToe.cpp) that asks the user which player should go first, creates a new TicTacToe object and starts the game. For this assignment only, you will not comment out your main method. Input validation: If someone tries to take an occupied square, tell them that square is already occupied and ask for a different move. Here's an example portion of a game (already in progress): 012 0 x 2 Player O: please enter your move 1 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
