C++
The program will call the start_game function with argument O orX to indicate first player and will keep track of the next playerwhile players take turns marking the board until the board is full.This version of the game only plays one game.
Class Specifications
TicTacToe class does not have aconstructor.
Member Functions and Member(variable)Specifications
+ = public
- = private
public/private | New/Update/NoUpdate | Function/Data Member | Functionality of function or data member |
+ | New | bool game_over | No parameters 1) return check_board_full function return value
|
+ | Update | void start_game(string first_player) | 1) first_player function argument value must be X or O;otherwise, throw an Error exception when value is not X or O. ErrorMessage: Player must be X or O. 2)In function set player(private variable) to first_player functionargument. 3) After the conditional branch statement, call the clear_boardfunction |
+ | | void mark_board(int position) | 1) Value of int must be in the range 1 to 9; otherwise, throw anError exception if value not in this range. Error Message: Positionmust be 1 to 9. 2) Private data player can’t be empty “â€, throw an Error exceptionif player variable is “â€. Error Message: Must start gamefirst.
3) Call set_next_player private function |
+ | | string get_player() const | Return the next_player value |
+ | New | void display_board const | No parameters Iterate vector of strings pegs to Display a tic tac toe board in 3x 3 format |
| | | |
| private functions | |
- | | void set_next_player() | Set next_player. If private variable player X, player is O elseplayer is X |
- | New | void check_board_full | No parameters 1) return false if vector of strings pegs has available slot bychecking for a “ “(space)in each element. Otherwise returntrue
|
| | | |
- | New | void clear_board const | No parameters 1) Set all 9 elements to a “ “ (space) |
| | | |
| | Class private Data | |
- | | string player | Class member variable |
| New | vector of string pegs | Class member variable 1) (initialize to 9 “ “(spaces) |
| | | | |
UNIT TEST CASES
Required Test Cases for Assignment (write the code in/homeworks/tic_tac_toe_test/ tic_tac_toe_test.cpp)
Test Case Name | Steps to Test |
Test Mark Position accepts values from 1 to 9 only | 1) Create an instance of TicTacToe game 2) Call the start game function 3) Use REQUIRE_THROWS_AS to verify game.mark_position(0) throws anError 4) Use REQUIRE_THROWS_AS to verify game.mark_position(10) throws anError 5) Call mark board 5 to show that an Error is not thrown. Â Â |
Test game over if 9 slots are selected. | 1)Create an instance of TicTacToe game 2)Call the start game function 3)Call mark board 9 times using numbers 1 to 9 in the followingorder(this test case will eventually be the test for CAT tiecase) |