chessCAMO
|
This class describes the chess board on which the game takes place. It contains functions which analyze specific flags to determinewhen to switch turns, display warnings, and even end the game. More...
#include <chess.h>
Public Member Functions | |
Chess () | |
Default constructor with default board parameter initialization - Constructs a new instance. More... | |
~Chess () | |
Destroys the object and frees any dynamically allocated memory ('new') to avoid memory leaks. More... | |
Chess (const Chess &chess_object) | |
Copy constructor - Constructs a new instance and copies the calling object's values to it. More... | |
Chess & | operator= (const Chess &chess_object) |
Copy Assignment operator - assigns values of one object to another existing object. More... | |
vector< Piece * > | getBoard () const |
(Accessor) Gets the board representation at the top of the board positions stack. More... | |
void | setBoard (const vector< Piece * > &board) |
(Mutator) Updates the board representation at the top of the board positions stack. More... | |
vector< Piece * > | getCheckPieces () const |
(Accessor) Gets the check stack information. More... | |
void | setCheckPieces (const vector< Piece * > &check_pieces) |
(Mutator) Sets the check stack information. More... | |
bool | getCheck () const |
(Accessor) Gets the check information. More... | |
void | setCheck (bool check) |
(Mutator) Sets the check information. More... | |
bool | getDoubleCheck () const |
(Accessor) Gets the double check information. More... | |
void | setDoubleCheck (bool double_check) |
(Mutator) Sets the double check information. More... | |
bool | getCheckmate () const |
(Accessor) Gets the checkmate information. More... | |
void | setCheckmate (bool checkmate) |
(Mutator) Sets the checkmate information. More... | |
bool | getStalemate () const |
(Accessor) Gets the stalemate information. More... | |
void | setStalemate (bool stalemate) |
(Mutator) Sets the stalemate information. More... | |
pieceColor | getTurn () const |
(Accessor) Gets the player's turn information. More... | |
void | setTurn (pieceColor turn) |
(Mutator) Sets the player's turn information. More... | |
int | getNumMoves () const |
(Accessor) Gets the number of moves made. More... | |
void | setNumMoves (int num_moves) |
(Mutator) Sets the number of moves made on the board. More... | |
vector< pair< int, char > > | getReservoir () const |
Gets the current reservoir information (pieces and quantity). More... | |
void | setReservoir (const vector< pair< int, char >> &reservoir) |
Sets the piece reservoir after a piece on the current board representation is replaced. More... | |
bool | useReservoirPiece (int src, int dest) |
At any turn, a player can replace one of their pieces with a piece from the reservoir if the resources are available. More... | |
void | boardInit () |
Places the pieces on the board at their correct starting positions. More... | |
bool | makeMove (int src, int dest, istream &in) |
Moves a piece on the board from 'src' to 'dest' if conditions for a legal move are met. More... | |
void | isCheckmate (string check_type) |
Decide if a move caused a checkmate according to 'check_type'. More... | |
bool | isStalemate () |
Decide if a move caused a stalemate. More... | |
Private Member Functions | |
void | makeMoveForType (int src, int dest) |
A move can be one of: attack, castle, en-passant, regular. More... | |
void | pieceSwap (int src, int dest, vector< Piece * > &board) |
Used in Chess::makeMoveForType(int src, int dest) to swap pieces on the board. More... | |
void | handleChangeTurn () |
Indicates who will move next via a message to console. More... | |
void | handleCheckmate () |
Indicates which player won by checkmate via a message to console. More... | |
void | handleStalemate () |
Indicates the game is drawn via a message to console. More... | |
bool | singleCheckPieceIterator (Piece *piece, Piece *king) |
If in a single check, see if piece can defend the king, capture attacking piece, or move the king out of check. Used in isCheckmate("single") More... | |
bool | doubleCheckPieceIterator (Piece *king) |
If in a double check, see if the king can move out of check as this is the only valid move option. Used in isCheckmate("double"). More... | |
pieceColor | switchTurn () |
Decides whose turn it is currently and updates the private member variable ('turn') accordingly. More... | |
Private Attributes | |
vector< Piece * > | board |
vector< Piece * > | check_pieces |
vector< bool > | flags |
vector< pair< int, char > > | reservoir |
pieceColor | turn |
int | num_moves |
Friends | |
ostream & | operator<< (ostream &out, const Chess &chess_object) |
Overloaded extraction operator. More... | |
istream & | operator>> (istream &in, Chess &chess_object) |
Overlaoded insertion operator. More... | |
This class describes the chess board on which the game takes place. It contains functions which analyze specific flags to determinewhen to switch turns, display warnings, and even end the game.
Chess::Chess | ( | ) |
Default constructor with default board parameter initialization - Constructs a new instance.
Chess::~Chess | ( | ) |
Destroys the object and frees any dynamically allocated memory ('new') to avoid memory leaks.
Chess::Chess | ( | const Chess & | chess_object | ) |
Copy constructor - Constructs a new instance and copies the calling object's values to it.
[in] | chess_object | The object whose values will be copied |
Copy Assignment operator - assigns values of one object to another existing object.
[in] | chess_object | The object whose values will be copied |
|
inline |
(Accessor) Gets the board representation at the top of the board positions stack.
|
inline |
(Mutator) Updates the board representation at the top of the board positions stack.
[in] | board | The current board representation |
|
inline |
(Accessor) Gets the check stack information.
|
inline |
(Mutator) Sets the check stack information.
[in] | check_pieces | The check stack which contains the board representations after each move |
|
inline |
(Accessor) Gets the check information.
|
inline |
(Mutator) Sets the check information.
[in] | check | The check flag |
|
inline |
(Accessor) Gets the double check information.
|
inline |
(Mutator) Sets the double check information.
[in] | double_check | The double check flag |
|
inline |
(Accessor) Gets the checkmate information.
|
inline |
(Mutator) Sets the checkmate information.
[in] | checkmate | The checkmate flag |
|
inline |
(Accessor) Gets the stalemate information.
|
inline |
(Mutator) Sets the stalemate information.
[in] | stalemate | The stalemate flag |
|
inline |
(Accessor) Gets the player's turn information.
|
inline |
(Mutator) Sets the player's turn information.
[in] | turn | The turn |
|
inline |
(Accessor) Gets the number of moves made.
|
inline |
(Mutator) Sets the number of moves made on the board.
[in] | num_moves | The number of moves made |
|
inline |
Gets the current reservoir information (pieces and quantity).
|
inline |
Sets the piece reservoir after a piece on the current board representation is replaced.
[in] | reservoir | The new piece reservoir information |
bool Chess::useReservoirPiece | ( | int | src, |
int | dest | ||
) |
At any turn, a player can replace one of their pieces with a piece from the reservoir if the resources are available.
[in] | src | The piece's source square (this will be an ASCII code in [110, 114] depending on the character the user enters) |
[in] | dest | The piece's destination square (piece that will be replaced on the board) |
void Chess::boardInit | ( | ) |
Places the pieces on the board at their correct starting positions.
bool Chess::makeMove | ( | int | src, |
int | dest, | ||
istream & | in | ||
) |
Moves a piece on the board from 'src' to 'dest' if conditions for a legal move are met.
[in] | src | The source square (piece's current location) |
[in] | dest | The destination square (piece's ending location) |
in | input stream type (stdin or file) |
void Chess::isCheckmate | ( | string | check_type | ) |
Decide if a move caused a checkmate according to 'check_type'.
[in] | check_type | Either "single" or "double" corresponding to the check on the board |
bool Chess::isStalemate | ( | ) |
Decide if a move caused a stalemate.
|
private |
A move can be one of: attack, castle, en-passant, regular.
[in] | src | The source square of piece |
[in] | dest | The destination square of piece |
|
private |
Used in Chess::makeMoveForType(int src, int dest) to swap pieces on the board.
[in] | src | The source square of piece |
[in] | dest | The destination square of piece |
board | The current board representation |
|
private |
Indicates who will move next via a message to console.
|
private |
Indicates which player won by checkmate via a message to console.
|
private |
Indicates the game is drawn via a message to console.
If in a single check, see if piece can defend the king, capture attacking piece, or move the king out of check. Used in isCheckmate("single")
If in a single check, see if piece can defend the king, capture attacking piece, or move the king out of check. Used in Chess::isCheckmate("single")
piece | The piece that is attacking the king currently |
king | The king that is being attacked currently |
|
private |
If in a double check, see if the king can move out of check as this is the only valid move option. Used in isCheckmate("double").
If in a double check, see if the king can move out of check as this is the only valid move option. Used in Chess::isCheckmate("double").
king | The king that is being attacked currently |
|
private |
Decides whose turn it is currently and updates the private member variable ('turn') accordingly.
|
friend |
Overloaded extraction operator.
out | The output type (ex. ofstream or cout) | |
[in] | chess_object | The chess object |
|
friend |
Overlaoded insertion operator.
in | The input type (ex. ifstream or cin) |
chess_object | The chess object |
|
private |
The current board representation of the pieces in the correct positions
|
private |
The pieces involved in a check
|
private |
Check, Double Check, Checkmate, Stalemate flags
|
private |
For deciding whose turn it is to make a move for a given board representation
|
private |
The number of moves made already