Here are some common utility functions from `engine/utils.c'.
int pushgo()
Pushes the position onto the stack.
int popgo()
Pops the movestack.
int trymove(int i, int j, int color, const char *message, int k, int l)
Returns true if
(i,j)
is a legal move for color. In that case, it pushes the move on the stack and makes the move, incrementingstackp
. If the reading code is recording reading variations (as with --decide_string or with -o), the string*message
will be inserted in the SGF file as a comment. The comment will also refer to the string at(k,l)
if these are not(-1,-1)
. Use like this:if (trymove(i, j, color, [message], k, l)) { ... popgo(); }
int TRY_MOVE()
Wrapper around trymove which suppresses
*message
and(k,l)
. Used in `helpers.c'
tryko(int i, int j, int color, const char *message)
Pushes the position onto the stack, and makes a move at
(i,j)
ofcolor
. The move is allowed even if it is an illegal ko capture. It is to be imagined thatcolor
has made an intervening ko threat which was answered and now the continuation is to be explored.
dump_stack(void)
Handy for debugging the reading code under GDB. Prints the move stack.
vgprintf(FILE* outputfile, const char *fmt, va_list ap)
This function underpins all the
TRACE
andDEBUG
stuff. Accepts%c
,%d
and%s
as usual. But it also accepts%m
, which takes TWO integers and writes a move NASTY BODGE:%o
at start means outdent (ie cancel indent).
void TRACE(const char *fmt, ...)
Basic tracing function. Variants
RTRACE
, etc. are documented in the source.
int legal(int i, int j, int color)
Returns true if
(i,j)
is legal forcolor
.
int count(int i, int j, int color, char mx[MAX_BOARD][MAX_BOARD], int maxlib, char mark)
Count liberties of color piece at location
(i, j)
and return value in global variablelib
(which is also the return value of the function). Return size of connected component insize
. Ifk<lib
, then(libi[k],libj[k])
points to one of the liberties of the string. FIXME: We should get rid of these global variables. This function is usually called with a stone ofcolor
at(i,j)
. It may also be called with(i,j)
EMPTY
. If this is the case, the function (essentially) places a stone of (color) on the board and does the calculation.
void change_dragon_status(int x, int y, int status)
Change the status of the dragon at
(x,y)
.
void change_defense(int ai, int aj, int ti, int tj)
Moves the point of defense of
(ai, aj)
to(ti, tj)
. FIXME: At present can only set defend_code equal to 1 or 0.
void change_attack(int ai, int aj, int ti, int tj)
Moves the point of attack of the worm at
(ai, aj)
to(ti, tj)
. FIXME: At present can only set attack_code equal to 1 or 0.
int connection_value(int ai, int aj, int bi, int bj, int ti, int tj)
This important function assigns a value to the connection of two dragons. The move at
(ti,tj)
is the connecting move. It is checked whether this move will result in a dragon having two eyes.
int cut_possible(int i, int j, int color)
Returns true if color can cut at
(i,j)
. This information is collected byfind_cuts()
, using theB
patterns in the connections database.
int does_attack(int ti, int tj, int ai, int aj)
Returns true if the move at
(ti, tj)
attacks(ai, aj)
. This means that it captures the string, and that(ai, aj)
is not already dead. As currently written, this function assumesstackp==0
, though this could be easily changed.
int does_defend(int ti, int tj, int ai, int aj)
Returns true if the move at
(ti, tj)
defends(ai, aj)
. This means that it defends the string, and that(ai, aj)
can be captured if no defense is made. As currently written, this function assumesstackp==0
, though this could be easily changed.
int find_lunch(int m, int n, int *wi, int *wj, int *ai, int *aj)
Looks for a worm adjoining the string at
(m,n)
which can be easily captured. Whether or not it can be defended doesn't matter (see section Worms and Dragons). Returns the location of the string in(*wi, *wj)
, and the location of the attacking move in(*ai, *aj)
.
int is_ko(int i, int j, int color)
Return true if the move
(i,j)
bycolor
is a ko capture (whether capture is a legal ko capture on this move or not).
int singleton(int i, int j)
Return true if
(i,j)
is an isolated stone.
int confirm_safety(int i, int j, int color, int value)
This important function will detect some blunders. Returns 1 if a move by
color
at(i,j)
does not diminish the safety of any worm, nor tend to rescue inadvertantly an opponent stone.