uct_dead_group_list(): Stop pondering
[pachi.git] / pattern3.h
blob330fb25bac7a95e1077a0bd271e3f7df09b4ef66
1 #ifndef ZZGO_PATTERN3_H
2 #define ZZGO_PATTERN3_H
4 /* Fast matching of simple 3x3 patterns. */
6 #include "board.h"
7 #include "tactics.h"
9 /* (Note that this is completely independent from the general pattern
10 * matching infrastructure in pattern.[ch]. This is fast and simple.) */
12 struct board;
13 struct move;
15 struct pattern3s {
16 /* Hashtable: 2*8 bits (ignore middle point, 2 bits per intersection) */
17 /* Value: 0: no pattern, 1: black pattern,
18 * 2: white pattern, 3: both patterns */
19 char hash[65536];
22 /* Source pattern encoding:
23 * X: black; O: white; .: empty; #: edge
24 * x: !black; o: !white; ?: any
26 * extra X: pattern valid only for one side;
27 * middle point ignored. */
29 void pattern3s_init(struct pattern3s *p, char src[][11], int src_n);
31 /* Compute pattern3 hash at local position. */
32 static int pattern3_hash(struct board *b, coord_t c);
34 /* Check if we match any pattern centered on given move; includes
35 * self-atari test. */
36 static bool test_pattern3_here(struct pattern3s *p, struct board *b, struct move *m);
39 static inline int
40 pattern3_hash(struct board *b, coord_t c)
42 int pat = 0;
43 int x = coord_x(c, b), y = coord_y(c, b);
44 pat |= (board_atxy(b, x - 1, y - 1) << 14)
45 | (board_atxy(b, x, y - 1) << 12)
46 | (board_atxy(b, x + 1, y - 1) << 10);
47 pat |= (board_atxy(b, x - 1, y) << 8)
48 | (board_atxy(b, x + 1, y) << 6);
49 pat |= (board_atxy(b, x - 1, y + 1) << 4)
50 | (board_atxy(b, x, y + 1) << 2)
51 | (board_atxy(b, x + 1, y + 1));
52 return pat;
55 /* TODO: Make use of the incremental spatial matching infrastructure
56 * in board.h? */
57 static inline bool
58 test_pattern3_here(struct pattern3s *p, struct board *b, struct move *m)
60 #ifdef BOARD_PAT3
61 int pat = b->pat3[m->coord];
62 #else
63 int pat = pattern3_hash(b, m->coord);
64 #endif
65 //fprintf(stderr, "(%d,%d) hashtable[%04x] = %d\n", x, y, pat, p->hash[pat]);
66 return (p->hash[pat] & m->color) && !is_bad_selfatari(b, m->color, m->coord);
69 #endif