Previous: The Board State, Up: API
All the functions in the engine that manipulate Positions have names
prefixed by gnugo_
. These functions still use the two-dimensional
representation of the board (see The Board Array). Here is a complete
list, as prototyped in gnugo.h:
void init_gnugo(float memory)
Initialize the gnugo engine. This needs to be called once only.
void gnugo_clear_board(int boardsize)
Clear the board.
void gnugo_set_komi(float new_komi)
Set the komi.
void gnugo_add_stone(int i, int j, int color)
Place a stone on the board
void gnugo_remove_stone(int i, int j)
Remove a stone from the board
int gnugo_is_pass(int i, int j)
Return true if (i,j) is PASS_MOVE
void gnugo_play_move(int i, int j, int color)
Play a move and start the clock
int gnugo_undo_move(int n)
Undo n permanent moves. Returns 1 if successful and 0 if it fails. If n moves cannot be undone, no move is undone.
int gnugo_play_sgfnode(SGFNode *node, int to_move)
Perform the moves and place the stones from the SGF node on the board. Return the color of the player whose turn it is to move.
int gnugo_play_sgftree(SGFNode *root, int *until, SGFNode **curnode)
Play the moves in ROOT UNTIL movenumber is reached. Return the color of the player whose turn it is to move.
int gnugo_is_legal(int i, int j, int color)
Interface to is_legal()
.
int gnugo_is_suicide(int i, int j, int color)
Interface to is_suicide()
.
int gnugo_placehand(int handicap)
Interface to placehand. Sets up handicap pieces and returns the number of placed handicap stones.
void gnugo_recordboard(SGFNode *root)
Interface to sgffile_recordboard()
int gnugo_sethand(int handicap, SGFNode *node)
Interface to placehand. Sets up handicap stones and returns the number of placed handicap stones, updating the sgf file
float gnugo_genmove(int *i, int *j, int color, int *resign)
Interface to genmove()
.
int gnugo_attack(int m, int n, int *i, int *j)
Interface to attack()
.
int gnugo_find_defense(int m, int n, int *i, int *j)
Interface to find_defense()
.
void gnugo_who_wins(int color, FILE *outfile)
Interface to who_wins()
.
float gnugo_estimate_score(float *upper, float *lower)
Put upper and lower score estimates into*upper
,*lower
and return the average. A positive score favors white. In computing the upper bound,CRITICAL
dragons are awarded to white; in computing the lower bound, they are awarded to black.
void gnugo_examine_position(int color, int how_much)
Interface to examine_position
.
int gnugo_get_komi()
Report the komi.
void gnugo_get_board(int b[MAX_BOARD][MAX_BOARD])
Place the board into the `b' array.
int gnugo_get_boardsize()
Report the board size.
int gnugo_get_move_number()
Report the move number.
The functions (in see Positional Functions) are all that are needed to create a fully functional go program. But to make the life easier for the programmer, there is a small set of functions specially designed for handling ongoing games.
The data structure describing an ongoing game is the Gameinfo
. It
is defined as follows:
typedef struct { int handicap; int to_move; /* whose move it currently is */ SGFTree game_record; /* Game record in sgf format. */ int computer_player; /* BLACK, WHITE, or EMPTY (used as BOTH) */ char outfilename[128]; /* Trickle file */ FILE *outfile; } Gameinfo;
The meaning of handicap
should be obvious. to_move
is the
color of the side whose turn it is to move.
The SGF tree game_record
is used to store all the moves in the entire
game, including a header node which contains, among other things, komi
and handicap.
If one or both of the opponents is the computer, the field
computer_player
is used. Otherwise it can be ignored.
GNU Go can use a trickle file to continuously save all the moves of an
ongoing game. This file can also contain information about internal
state of the engine such as move reasons for various locations or move
valuations. The name of this file should
be stored in outfilename
and the file pointer to the open file is
stored in outfile
. If no trickle file is used,
outfilename[0]
will contain a null character and outfile
will be set to NULL
.
All the functions in the engine that manipulate Gameinfos have names
prefixed by gameinfo_
. Here is a complete list, as prototyped in
gnugo.h:
void gameinfo_clear(Gameinfo *ginfo, int boardsize, float komi)
Initialize the Gameinfo
structure.
void gameinfo_print(Gameinfo *ginfo)
Print a gameinfo.
void gameinfo_load_sgfheader(Gameinfo *gameinfo, SGFNode *head)
Reads header info from sgf structure and sets the appropriate variables.
void gameinfo_play_move(Gameinfo *ginfo, int i, int j, int color)
Make a move in the game. Return 1 if the move was legal. In that case the move is actually done. Otherwise return 0.
int gameinfo_play_sgftree_rot(Gameinfo *gameinfo, SGFNode *head, const char *untilstr, int orientation)
Play the moves in an SGF tree. Walk the main variation, actioning the properties into the playing board. Returns the color of the next move to be made. Head is an sgf tree. Untilstr is an optional string of the form either 'L12' or '120' which tells it to stop playing at that move or move number. When debugging, this is the location of the move being examined.
int gameinfo_play_sgftree(Gameinfo *gameinfo, SGFNode *head, const char *untilstr)
Same as previous function, using standard orientation.