Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please follow the instructions.. c++ 6.18 PROGRAM 8: Vectors - Tic Tac Toe Implement a tic-tac-toe game. At the bottom of these specifications you will

please follow the instructions..

c++

6.18 PROGRAM 8: Vectors - Tic Tac Toe

Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to cloud9. Do not change the provided complete functions, or the function stub headers / return values.

Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what each function should do and when each should be called. Add variables where you see fit.

Implementation Strategies:

The template has variables and two global constants for you to utilize.

The template has string literals for winning or tie game output in comments with provided file.

The template has comments to help you develop the necessary algorithm for 2 users playing tic-tac-toe on a computer. Use these comments along with the function descriptions below to help develop your program. One or more lines of your code should exist below each comment. Remove the TODO part when you have completed that step.

DO NOT try to implement the entire game at once. Instead, develop and test one function at a time. Understand how to walk through your code by hand as well as executing it in unit tests.

The system will test your functions as you attempt to complete each. Use the feedback and walk through your code to fix problems.

Submit and achieve a full score on each function before implementing the main game algorithm.

Tie Game Example:

c a | b | c -----|-----|----- d | e | f -----|-----|----- g | h | i Please choose a position: a c X | b | c -----|-----|----- d | e | f -----|-----|----- g | h | i Please choose a position: e c X | b | c -----|-----|----- d | O | f -----|-----|----- g | h | i Please choose a position: e Please choose a position: b c X | X | c -----|-----|----- d | O | f -----|-----|----- g | h | i Please choose a position: c c X | X | O -----|-----|----- d | O | f -----|-----|----- g | h | i Please choose a position: g c X | X | O -----|-----|----- d | O | f -----|-----|----- X | h | i Please choose a position: d c X | X | O -----|-----|----- O | O | f -----|-----|----- X | h | i Please choose a position: f c X | X | O -----|-----|----- O | O | X -----|-----|----- X | h | i Please choose a position: h c X | X | O -----|-----|----- O | O | X -----|-----|----- X | O | i Please choose a position: i c X | X | O -----|-----|----- O | O | X -----|-----|----- X | O | X No one wins 

Starting Template:

#include  #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  &v) { // TODO: implement function return; } /// @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 &gameBoard, int positionIndex) { // 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 &gameBoard) { // 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 &gameBoard) { // 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 &gameBoard) { // 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 gameBoard(9); int curPlay; int whosTurn = PLAYER1; // Player 1 always goes first and is 'X' /// 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago