// $Id: COsBoard.htm 119 2004-05-16 00:02:24Z ggs_mburo $ // This is a GGS file, licensed under the GPL
The COsBoard class includes the current board position - board type, position, and yor to move.
Convert the board to your program's internal format:
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.
COsBoardType | bt | Board type (size and shape). |
string | sBoard | Pieces on the board, with dummy character buffer. |
bool | iMover | True if it is black's move |
Creation | ||
void | Clear() | Clear all information from the board, including board type. |
void | Initialize(const COsBoardType& bt) | Set up the board for a given board type. |
void | TextSet(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) const | Returns 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). |
char | PieceGet(int x, int y) const | Return the piece in a given square. |
char | PieceGet(const CSGSquare& sq) const | Return the piece in a given square. |
void | PieceSet(int x, int y, char piece) | Set the piece in a given square. |
void | PieceSet(int x, int y, char piece) | Set the piece in a given square. |
Move Information | ||
bool | GameOver() const | Returns true if neither player has a legal move. |
bool | HasLegalMove() const | Returns true if current player has a legal move. |
int | IsMoveLegal(const COsMove& move) const | Returns nonzero if the move is legal. |
int | NPass() const | 0 = no passes, 1=player to move must pass, 2=both players must pass. |
vector<COsMove> | GetMoves(bool fMover=true) const | Returns all legal moves, empty vector if player must pass. |
Piece count Information | ||
void | GetPieceCounts(int& nBlack, int& nWhite, int& nEmpty) const | Outputs number of black, white, and empty squares. |
int | NetBlackSquares() const | Returns # black squares - # white squares. |
int | Result(bool fAnti=false) const | Return # black squares - # white squares, with empties going to the winner. |
Other | ||
void | Update(const COsMove& mv) | Updates the board with a move. |
I/O | ||
void | In(istream& is) | Reads from a stream in the GGF format, normally use the >> operator. |
void | Out(ostream& is) const | Write to a stream in GGF format, normally use the << operator. |
void | OutFormatted(ostream& os) const | Write to a stream in human-readable format, useful for debugging. |