1 #ifndef PACHI_TACTICS_DRAGON_H
2 #define PACHI_TACTICS_DRAGON_H
4 /* Functions for dealing with dragons, ie virtually connected groups of stones.
5 * Used for some high-level tactics decisions, like trying to detect useful lost
6 * ladders or whether breaking a 3-stones seki is safe.
7 * Currently these are fairly expensive (dragon data is not cached) so shouldn't be
8 * called by low-level / perf-critical code. */
11 /* Like group_at() but returns unique id for all stones in a dragon.
12 * Depending on the situation what is considered to be a dragon here may or
13 * may not match what we'd intuitively call a dragon: there are connections
14 * it doesn't understand (dead cutting stones for instance) so it'll usually
15 * be smaller. Doesn't need to be perfect though. */
16 group_t
dragon_at(struct board
*b
, coord_t to
);
18 /* Returns total number of liberties of dragon at @to. */
19 int dragon_liberties(struct board
*b
, enum stone color
, coord_t to
);
21 /* Print board highlighting given dragon */
22 void dragon_print(struct board
*board
, FILE *f
, group_t dragon
);
24 /* Like board_print() but use a different color for each dragon */
25 void board_print_dragons(struct board
*board
, FILE *f
);
27 /* Pick a color for dragon with index @i. Returns ansi color code.
28 * Useful for writing custom board_print_dragons()-like functions. */
29 char *pick_dragon_color(int i
, bool bold
, bool white_ok
);
31 /* Try to find out if dragon has 2 eyes. Pretty conservative:
32 * big eye areas are counted as one eye, must be completely enclosed and
33 * have all surrounded stones connected. Doesn't need to be perfect though. */
34 bool dragon_is_safe(struct board
*b
, group_t g
, enum stone color
);
36 /* Like group_is_safe() but passing already visited stones / eyes. */
37 bool dragon_is_safe_full(struct board
*b
, group_t g
, enum stone color
, int *visited
, int *eyes
);
39 /* Try to detect big eye area, ie:
40 * - completely enclosed area, not too big,
41 * - surrounding stones all connected to each other
42 * - size >= 2 (so no false eye issues)
43 * Returns size of the area, or 0 if doesn't match. */
44 int big_eye_area(struct board
*b
, enum stone color
, coord_t around
, int *visited
);
46 /* Try to find out if dragon is completely surrounded:
47 * Look for outwards 2-stones gap from our external liberties.
48 * (hack, but works pretty well in practice) */
49 bool dragon_is_surrounded(struct board
*b
, coord_t to
);
52 #endif /* PACHI_TACTICS_DRAGON_H */