Access over 20 million homework & study documents

search

6 18 PROGRAM 8 Vectors Tic Tac ToeImplement a tic tac toe game

Content type
User Generated
Rating
Showing Page:
1/7
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:
Starting Template:

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/7
Solution
#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) { v.at(0) = \'a\'; v.at(1) = \'b\'; v.at(2) = \'c\';

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/7

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 7 pages?
Access Now
Unformatted Attachment Preview
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 wi nning 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 f ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Excellent resource! Really helped me get the gist of things.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Documents