The COsBoard class includes the current board position - board type, position, and color 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 GetText(), Piece(), and SetText() functions.
COsBoardType | bt | Board type (size and shape). |
string | sBoard | Pieces on the board, with dummy character buffer. |
bool | fBlackMove | 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 | SetText(const char* sBoard) | Sets pieces (or empty) in playable squares, one character per square. |
Getting Pieces | ||
char* | GetText(char* sBoard, bool& fBlackMove, 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 | Piece(int row, int col) const | Return the piece in a given square. |
void | SetPiece(int row, int col, 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. |