TESTS: 9x9 a0f85
[pachi/json.git] / tactics.h
blob7e6cbad75f334dd24abfc55b850fe8164bd84563
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);
34 bool is_bad_selfatari_slow(struct board *b, enum stone color, coord_t to);
35 static inline bool
36 is_bad_selfatari(struct board *b, enum stone color, coord_t to)
38 /* More than one immediate liberty, thumbs up! */
39 if (immediate_liberty_count(b, to) > 1)
40 return false;
42 return is_bad_selfatari_slow(b, color, to);
45 bool is_border_ladder(struct board *b, coord_t coord, enum stone lcolor);
46 bool is_middle_ladder(struct board *b, coord_t coord, enum stone lcolor);
47 static inline bool
48 is_ladder(struct board *b, coord_t coord, group_t laddered,
49 bool border_ladders, bool middle_ladders)
51 enum stone lcolor = board_at(b, group_base(laddered));
53 if (DEBUGL(6))
54 fprintf(stderr, "ladder check - does %s play out %s's laddered group %s?\n",
55 coord2sstr(coord, b), stone2str(lcolor), coord2sstr(laddered, b));
57 /* First, special-case first-line "ladders". This is a huge chunk
58 * of ladders we actually meet and want to play. */
59 if (border_ladders
60 && neighbor_count_at(b, coord, S_OFFBOARD) == 1
61 && neighbor_count_at(b, coord, lcolor) == 1)
62 return is_border_ladder(b, coord, lcolor);
64 if (middle_ladders)
65 return is_middle_ladder(b, coord, lcolor);
67 return false;
70 #endif