UCT: Fix scoring after pass-pass in tree
[pachi/json.git] / tactics.h
blob2f320ac6dfd4bb4c85d8e61e24af44af67e6826f
1 #ifndef ZZGO_TACTICS_H
2 #define ZZGO_TACTICS_H
4 /* Advanced tactical checks non-essential to the board implementation. */
6 #include "board.h"
8 /* Check if this move is undesirable self-atari (resulting group would have
9 * only single liberty and not capture anything; ko is allowed); we mostly
10 * want to avoid these moves. The function actually does a rather elaborate
11 * tactical check, allowing self-atari moves that are nakade, eye falsification
12 * or throw-ins. */
13 static bool is_bad_selfatari(struct board *b, enum stone color, coord_t to);
15 /* Check if escaping on this liberty by given group in atari would play out
16 * a simple ladder. */
17 /* Two ways of ladder reading can be enabled separately; simple first-line
18 * ladders and trivial middle-board ladders. */
19 static bool is_ladder(struct board *b, coord_t coord, group_t laddered,
20 bool border_ladders, bool middle_ladders);
22 /* Checks if there are any stones in n-vincinity of coord. */
23 bool board_stone_radar(struct board *b, coord_t coord, int distance);
25 /* Construct a "common fate graph" from given coordinate; that is, a weighted
26 * graph of intersections where edges between all neighbors have weight 1,
27 * but edges between neighbors of same color have weight 0. Thus, this is
28 * "stone chain" metric in a sense. */
29 /* The output are distanes from start stored in given [board_size2()] array;
30 * intersections further away than maxdist have all distance maxdist+1 set. */
31 void cfg_distances(struct board *b, coord_t start, int *distances, int maxdist);
33 /* Compute an extra komi describing the "effective handicap" black receives
34 * (returns 0 for even game with 7.5 komi). */
35 /* This is just an approximation since in reality, handicap seems to be usually
36 * non-linear. */
37 float board_effective_handicap(struct board *b);
40 bool is_bad_selfatari_slow(struct board *b, enum stone color, coord_t to);
41 static inline bool
42 is_bad_selfatari(struct board *b, enum stone color, coord_t to)
44 /* More than one immediate liberty, thumbs up! */
45 if (immediate_liberty_count(b, to) > 1)
46 return false;
48 return is_bad_selfatari_slow(b, color, to);
51 bool is_border_ladder(struct board *b, coord_t coord, enum stone lcolor);
52 bool is_middle_ladder(struct board *b, coord_t coord, enum stone lcolor);
53 static inline bool
54 is_ladder(struct board *b, coord_t coord, group_t laddered,
55 bool border_ladders, bool middle_ladders)
57 enum stone lcolor = board_at(b, group_base(laddered));
59 if (DEBUGL(6))
60 fprintf(stderr, "ladder check - does %s play out %s's laddered group %s?\n",
61 coord2sstr(coord, b), stone2str(lcolor), coord2sstr(laddered, b));
63 /* First, special-case first-line "ladders". This is a huge chunk
64 * of ladders we actually meet and want to play. */
65 if (border_ladders
66 && neighbor_count_at(b, coord, S_OFFBOARD) == 1
67 && neighbor_count_at(b, coord, lcolor) == 1)
68 return is_border_ladder(b, coord, lcolor);
70 if (middle_ladders)
71 return is_middle_ladder(b, coord, lcolor);
73 return false;
76 #endif