pattern.c: Introduce CAPTURE_COUNTSTONES_MAX
[pachi/t.git] / tactics / ladder.h
blobad53f80ecfcda233d3865cd4f972c147c5603d07
1 #ifndef PACHI_TACTICS_LADDER_H
2 #define PACHI_TACTICS_LADDER_H
4 /* Reading ladders. */
6 #include "board.h"
7 #include "debug.h"
9 /* Check if escaping on this liberty by given group in atari would play out
10 * a simple ladder. */
11 /* Two ways of ladder reading can be enabled separately; simple first-line
12 * ladders and trivial middle-board ladders. */
13 static bool is_ladder(struct board *b, coord_t coord, group_t laddered, bool test_middle);
15 /* Check if a 2-lib group of color @lcolor escaping at @escapelib would be
16 * caught in a ladder given opponent stone at @chaselib. */
17 bool wouldbe_ladder(struct board *b, group_t group, coord_t escapelib, coord_t chaselib, enum stone lcolor);
20 bool is_border_ladder(struct board *b, coord_t coord, enum stone lcolor);
21 bool is_middle_ladder(struct board *b, coord_t coord, group_t group, enum stone lcolor);
22 static inline bool
23 is_ladder(struct board *b, coord_t coord, group_t laddered, bool test_middle)
25 enum stone lcolor = board_at(b, group_base(laddered));
27 if (DEBUGL(6))
28 fprintf(stderr, "ladder check - does %s play out %s's laddered group %s?\n",
29 coord2sstr(coord, b), stone2str(lcolor), coord2sstr(laddered, b));
31 /* First, special-case first-line "ladders". This is a huge chunk
32 * of ladders we actually meet and want to play. */
33 if (neighbor_count_at(b, coord, S_OFFBOARD) == 1
34 && neighbor_count_at(b, coord, lcolor) == 1) {
35 bool l = is_border_ladder(b, coord, lcolor);
36 if (DEBUGL(6)) fprintf(stderr, "border ladder solution: %d\n", l);
37 return l;
40 bool l = test_middle && is_middle_ladder(b, coord, laddered, lcolor);
41 if (DEBUGL(6)) fprintf(stderr, "middle ladder solution: %d\n", l);
42 return l;
45 #endif