// $Id: COsBoard.htm 119 2004-05-16 00:02:24Z ggs_mburo $ // This is a GGS file, licensed under the GPL COsBoard

COsBoard

The COsBoard class includes the current board position - board type, position, and yor to move.

Normal Usage

Convert the board to your program's internal format:

Notes

The board is stored as a character array with dummy character border. Characters used include the class enum values

enum { BLACK = '*', WHITE='O', EMPTY='-', DUMMY='d', UNKNOWN='?' };

This convention is also used for the TextGet(), PieceGet(), and TextSet() functions.

Variables

COsBoardTypebtBoard type (size and shape).
stringsBoardPieces on the board, with dummy character buffer.
booliMoverTrue if it is black's move

Functions

Creation
voidClear()Clear all information from the board, including board type.
voidInitialize(const COsBoardType& bt)Set up the board for a given board type.
voidTextSet(const char* sBoard)Sets pieces (or empty) in playable squares, one character per square.
Getting Pieces
char*TextGet(char* sBoard, bool& iMover, bool fTrailingNull=true) constReturns and outputs pieces (or empty) in playable squares, one character per square. The calling function allocates the memory. A trailing '\0' will be appended if fTrailingNull==true (the default).
charPieceGet(int x, int y) constReturn the piece in a given square.
charPieceGet(const CSGSquare& sq) constReturn the piece in a given square.
voidPieceSet(int x, int y, char piece)Set the piece in a given square.
voidPieceSet(int x, int y, char piece)Set the piece in a given square.
Move Information
boolGameOver() constReturns true if neither player has a legal move.
boolHasLegalMove() constReturns true if current player has a legal move.
intIsMoveLegal(const COsMove& move) constReturns nonzero if the move is legal.
intNPass() const0 = no passes, 1=player to move must pass, 2=both players must pass.
vector<COsMove>GetMoves(bool fMover=true) constReturns all legal moves, empty vector if player must pass.
Piece count Information
voidGetPieceCounts(int& nBlack, int& nWhite, int& nEmpty) constOutputs number of black, white, and empty squares.
intNetBlackSquares() constReturns # black squares - # white squares.
intResult(bool fAnti=false) constReturn # black squares - # white squares, with empties going to the winner.
Other
voidUpdate(const COsMove& mv)Updates the board with a move.
I/O
voidIn(istream& is)Reads from a stream in the GGF format, normally use the >> operator.
voidOut(ostream& is) constWrite to a stream in GGF format, normally use the << operator.
voidOutFormatted(ostream& os) constWrite to a stream in human-readable format, useful for debugging.