TESTS: 19x19 67561, f1c52, 08c0a historical results
[pachi.git] / tactics.h
blobdfe9c8fa1e15f3727638c411fbc164fd7b1665a5
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;
47 if (board_playing_ko_threat(b))
48 return false; // all is fair in a ko
50 return is_bad_selfatari_slow(b, color, to);
53 bool is_border_ladder(struct board *b, coord_t coord, enum stone lcolor);
54 bool is_middle_ladder(struct board *b, coord_t coord, enum stone lcolor);
55 static inline bool
56 is_ladder(struct board *b, coord_t coord, group_t laddered,
57 bool border_ladders, bool middle_ladders)
59 if (board_playing_ko_threat(b))
60 return false; // all is fair in a ko
62 enum stone lcolor = board_at(b, group_base(laddered));
64 if (DEBUGL(6))
65 fprintf(stderr, "ladder check - does %s play out %s's laddered group %s?\n",
66 coord2sstr(coord, b), stone2str(lcolor), coord2sstr(laddered, b));
68 /* First, special-case first-line "ladders". This is a huge chunk
69 * of ladders we actually meet and want to play. */
70 if (border_ladders
71 && neighbor_count_at(b, coord, S_OFFBOARD) == 1
72 && neighbor_count_at(b, coord, lcolor) == 1)
73 return is_border_ladder(b, coord, lcolor);
75 if (middle_ladders)
76 return is_middle_ladder(b, coord, lcolor);
78 return false;
81 #endif