class boardboard object contains information about the state of a game
of tic-tac-toe. You can represent this information within a board object
any way you like (you can use a 2-d array as in HW1, or whatever else you
might think of), but you must provide the following methods:
| Method prototype | Description |
|---|---|
board(void); |
constructor. This must initialize the board to an empty game. |
void print(void); |
This method prints out the current game to stdout. Feel free to use the code provided with HW1 to accomplish this. |
int getval(int r, int c); |
A function that returns the current value of the element of the
board at row r and column c. If the row or
column specified are not legal (for example if the row is 24) the return value of this method should be -1. If the row and column are valid, the
return value must be either 0, 1 or 2.
|
int setval(int r, int c, int newval); |
This function changes the value of the board element at row
r and column c to the value newval.
The return value should be newval if the move is a legal move,
or -1 if the move is not legal.
An illegal move must be detected by this method. If
|
class playerplayer will contain methods that can be used to make
a move in a game of tic-tac-toe. Within your class definition you can
do anything you want (as far as defining data members and methods),
but you must support the following methods:
| Method prototype | Description |
|---|---|
player(int playernum); |
constructor that takes a single argument that specifies whether the object is player 1 or player 2 (playernum will be a 1 or a 2). |
bool makemove(board &b); |
This method changes the board object so that one of the
zeros in the board is changed to the player's number (the player makes a move).
If a move is not possible the method returns false, otherwise
the board should be updated and the method returns true.
|
bool has_won( board b); |
A boolean function that returns true if the player has won, otherwise returns false.
|
bool has_lost( board b); |
A boolean function that returns true if the player has lost
the game, otherwise returns false.
|
board and player classes and send the
file as an attachment via email to:
You must include the homework number on the subject line (anything like "subject: HW2" will work great).
Please use the above email address to submit - this email address is routed to a program that collects your submission and will send you back a receipt right away. If you submit to any other email address we will ask you to resubmit!
You may submit up to 10 times, we will grade the last submission received.
Send email to cpp@cs.rpi.edu if you have questions or trouble emailing your submission.