GClasses
GClasses::GChessBoard Class Reference

Represents the state of a chess board, and provides some basic functionality for implementing a chess game. More...

#include <GChess.h>

Public Types

enum  Piece {
  None = 0, Pawn = 1, Rook = 2, Knight = 3,
  Bishop = 4, Queen = 5, King = 6, PieceMask = 7,
  WhiteMask = 8, AllMask = 15
}
 

Public Member Functions

 GChessBoard ()
 
 GChessBoard (const GChessBoard &that)
 copy-constructor More...
 
 ~GChessBoard ()
 
bool isValidMove (int xSrc, int ySrc, int xDest, int yDest)
 Returns true iff the parameters represent a valid move. More...
 
bool move (int xSrc, int ySrc, int xDest, int yDest)
 Moves the piece from (xSrc, ySrc) to (xDest, yDest). If this move takes a king, then it will remove all pieces of the same color as the king that was taken and return true to indicate that the move ended the game. More...
 
int moves (int *pOutMoves, int col, int row)
 Pass in the coordinates of a square with a piece on it and it will return the number of moves that piece can make and put the coordinates of the moves in pOutMoves (first col, then row, so pOutMoves should be big enough to hold 2 * MAX_PIECE_MOVES values) More...
 
Piece piece (int col, int row, bool *pbWhite)
 Returns the piece located at position (col, row), and sets *pbWhite to true if the piece is white. More...
 
void printBoard (std::ostream &stream)
 Print a representation of the board to the specified stream. More...
 
void resetBoard ()
 Sets up the board for a new game. More...
 
void setPiece (int col, int row, Piece piece, bool white)
 Sets the piece at location (col, row). If piece is None, then it doesn't matter what the value of white is. More...
 

Protected Member Functions

bool checkMove (int *pOutMoves, int *pnMoves, int col, int row, bool bWhite)
 
bool checkPawnMove (int *pOutMoves, int *pnMoves, int col, int row, bool bDiagonal, bool bWhite)
 
int dec (int pos)
 
int inc (int pos)
 

Protected Attributes

unsigned int m_rows [8]
 

Detailed Description

Represents the state of a chess board, and provides some basic functionality for implementing a chess game.

Member Enumeration Documentation

Enumerator
None 
Pawn 
Rook 
Knight 
Bishop 
Queen 
King 
PieceMask 
WhiteMask 
AllMask 

Constructor & Destructor Documentation

GClasses::GChessBoard::GChessBoard ( )
inline
GClasses::GChessBoard::GChessBoard ( const GChessBoard that)
inline

copy-constructor

GClasses::GChessBoard::~GChessBoard ( )
inline

Member Function Documentation

bool GClasses::GChessBoard::checkMove ( int *  pOutMoves,
int *  pnMoves,
int  col,
int  row,
bool  bWhite 
)
protected
bool GClasses::GChessBoard::checkPawnMove ( int *  pOutMoves,
int *  pnMoves,
int  col,
int  row,
bool  bDiagonal,
bool  bWhite 
)
protected
int GClasses::GChessBoard::dec ( int  pos)
inlineprotected
int GClasses::GChessBoard::inc ( int  pos)
inlineprotected
bool GClasses::GChessBoard::isValidMove ( int  xSrc,
int  ySrc,
int  xDest,
int  yDest 
)

Returns true iff the parameters represent a valid move.

bool GClasses::GChessBoard::move ( int  xSrc,
int  ySrc,
int  xDest,
int  yDest 
)

Moves the piece from (xSrc, ySrc) to (xDest, yDest). If this move takes a king, then it will remove all pieces of the same color as the king that was taken and return true to indicate that the move ended the game.

int GClasses::GChessBoard::moves ( int *  pOutMoves,
int  col,
int  row 
)

Pass in the coordinates of a square with a piece on it and it will return the number of moves that piece can make and put the coordinates of the moves in pOutMoves (first col, then row, so pOutMoves should be big enough to hold 2 * MAX_PIECE_MOVES values)

Piece GClasses::GChessBoard::piece ( int  col,
int  row,
bool *  pbWhite 
)
inline

Returns the piece located at position (col, row), and sets *pbWhite to true if the piece is white.

void GClasses::GChessBoard::printBoard ( std::ostream &  stream)

Print a representation of the board to the specified stream.

void GClasses::GChessBoard::resetBoard ( )

Sets up the board for a new game.

void GClasses::GChessBoard::setPiece ( int  col,
int  row,
Piece  piece,
bool  white 
)
inline

Sets the piece at location (col, row). If piece is None, then it doesn't matter what the value of white is.

Member Data Documentation

unsigned int GClasses::GChessBoard::m_rows[8]
protected