Do My Homework / Homework Help Answers / Coding Homework Help / C++ Create Tic Tac Toe game with vectors

C++ Create Tic Tac Toe game with vectors

Need help with this question or any other Coding assignment help task?

Implement a tic-tac-toe game. 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 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 (comments) 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. In other words, submit as you go. Use the submission feedback and walk through your code to fix problems. Submit and achieve a full score on each function before implementing the main game algorithm. Suggested order of completion: initVector: Define, test, and submit this function before moving on. (Should now have 2 points.) Now call initVector and drawBoard functions where told to in main (before getting first play) to see your first board output. Submit. (Should now have 4 points.) convertPosition: You'll need this to get the first play, so define, test, and submit this one before tackling getPlay function. (Should now have 6 points.) validPlacement: Again, you'll need this to get the first play, so define, test, and submit this one before tackling getPlay function. (Should now have 8 points.) getPlay: Now that you have convertPosition and validPlacement working, use these functions to help you define the getPlay function. Be sure this function continues to ask the user for input (does not return) until they provide a valid board position. Test and submit for feedback. (Should now have 10 points.) Now call getPlay function in main to get just 1 play. Use the return value to place an X in that spot and call drawBoard again. Do not try to get the loop working yet. Just call getPlay once. (Should now have 12 points.) gameWon: Define, test, and submit this function. (Should now have 16 points.) boardFull: Define, test, and submit this function. (Should now have 18 points.) You now have all functions fully tested and working. Go ahead and complete the main function. Get the loop working. Figure out how to switch who's turn it is and implement that. Output the winner or tie game after the loop exits. (Should now have full points!) Add onto this template: #include #include using namespace std; /// @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) { 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 2 then it will have characters a to b. /// If the vector is size 6 then it will have characters a to f. /// 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. /// Continues asking for a position until a valid position has been entered. /// /// @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 the 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; }
There are no answers to this question.
Login to buy an answer or post yours. You can also vote on other others

Get Help With a similar task to - C++ Create Tic Tac Toe game with vectors

Related Questions

Similar orders to C++ Create Tic Tac Toe game with vectors
72
Views
2
Answers
61
Views
2
Answers
106
Views
2
Answers
Popular Services
Tutlance Experts offer help in a wide range of topics. Here are some of our top services: