Merge branch 'master' into libmap
[pachi.git] / libmap.h
blob8832fb1be3c7e0c8504b0ad71b5ce9802cf86e7a
1 #ifndef PACHI_LIBMAP_H
2 #define PACHI_LIBMAP_H
4 /* "Liberty map" - description of a particular liberty structure of a group.
5 * The idea is that we can use this as a hash index to track local tactical
6 * effectivity of various moves within the particular liberty structure
7 * context. */
9 #include <assert.h>
10 #include <stdbool.h>
12 #include "board.h"
13 #include "mq.h"
14 #include "stats.h"
16 #define LM_DEBUG if (0)
19 /* Computation and representation of the libmap hash. */
21 hash_t group_to_libmap(struct board *b, group_t group);
24 /* Set of moves ("libmap context") grouped by libmap, with some statistics. */
25 /* Hash structure storing info about move effectivity. */
27 struct libmap_move {
28 struct move move;
29 struct move_stats stats;
32 struct libmap_context {
33 hash_t hash;
34 int visits;
35 /* We add moves in multiple threads. But at most, on conflict we will
36 * end up with tiny amount of misappropriated playouts. */
37 int moves;
38 struct libmap_move move[GROUP_REFILL_LIBS];
41 /* Get statistics of particular move in given libmap structure. */
42 static struct move_stats *libmap_move_stats(struct libmap_context *lc, struct move move);
45 static inline struct move_stats *
46 libmap_move_stats(struct libmap_context *lc, struct move move)
48 if (!lc) return NULL;
49 for (int i = 0; i < lc->moves; i++) {
50 if (lc->move[i].move.coord == move.coord
51 && lc->move[i].move.color == move.color)
52 return &lc->move[i].stats;
54 return NULL;
57 #endif