Question: #include #include using namespace std; const bool CLEAR_SCREEN = true; /// @brief Utilizes an escape character sequence to clear the screen void clearScreen() { cout
#include
using namespace std;
const bool CLEAR_SCREEN = true;
/// @brief Utilizes an escape character sequence to clear the screen void clearScreen() { cout << endl;
if (CLEAR_SCREEN) { cout << "\033c"; }
cout << endl;
return; }
/// @brief Draws the provided tic-tac-toe board to the screen // @param board is the tic-tac-toe board that should be drawn void drawBoard(const vector < char >&gameBoard) { clearScreen(); for (int i = 0; i < 9; i += 3) { cout << " " << gameBoard.at(i) << " | " << gameBoard.at(i + 1) << " | " << gameBoard.at(i + 2) << " " << endl; if (i < 6) { cout << "-----|-----|-----" << endl; } } cout << endl;
return; }
/// @brief Fills vector with characters starting at lower case a. /// /// If the vector is size 3 then it will have characters a to c. /// If the vector is size 5 then it will have characters a to e. /// If the vector is size 26 then it will have characters a to z. /// /// @param v the vector to initialize /// @pre-condition the vector size will never be over 26 void initVector(vector
/// @brief Converts a character representing a cell to associated vector index /// @param the position to be converted to a vector index /// @return the integer index in the vector, should be 0 to (vector size - 1) int convertPosition(char boardPosition) {
// TODO: implement function return -1; }
/// @brief Predicate function to determine if a spot in board is available. /// @param board the current tic-tac-toe board /// @param position is an index into vector to check if available /// @return true if position's state is available (not marked) AND is in bounds bool validPlacement(const vector
// TODO: implement function return false; } /// @brief Acquires a play from the user as to where to put her mark /// /// Utilizes convertPosition and validPlacement functions to convert the /// user input and then determine if the converted input is a valid play. /// /// @param board the current tic-tac-toe board /// @return an integer index in board vector of a chosen available board spot int getPlay(const vector
// TODO: implement function char boardPosition = ' ';
cout << "Please choose a position: ";
return -1; }
/// @brief Predicate function to determine if the game has been won /// /// Winning conditions in tic-tac-toe require three marks from same /// player in a single row, column or diagonal. /// /// @param board the current tic-tac-toe board /// @return true if the game has been won, false otherwise bool gameWon(const vector
// TODO: implement function return false; }
/// @brief Predicate function to determine if the board is full /// @param board the current tic-tac-toe board /// @return true iff the board is full (no cell is available) bool boardFull(const vector
// TODO: implement function return false; }
// Global constants for player representation const int PLAYER1 = 0; const int PLAYER2 = 1;
int main() { // Variables that you may find useful to utilize vector
/// TODO: Initialize board to empty state
/// TODO: Display empty board
/// TODO: Play until game is over
/// TODO: Get a play
/// TODO: Set the play on the board
/// TODO: Switch the turn to the other player
/// TODO: Output the updated board
/// TODO: Determine winner and output appropriate message
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
