libmap_mq_print(): Look at libmap only if it exists (is enabled)
[pachi.git] / libmap.c
blob969a9a82efdc4f0c4066b740e8864a4e7beb5f17
1 #include <assert.h>
2 #include <limits.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #include "board.h"
7 #include "debug.h"
8 #include "libmap.h"
9 #include "move.h"
10 #include "tactics/util.h"
13 hash_t
14 group_to_libmap(struct board *b, group_t group)
16 hash_t h = 0;
17 #define hbits (sizeof(hash_t)*CHAR_BIT)
19 enum stone color = board_at(b, group);
20 struct group *gi = &board_group_info(b, group);
21 int libs = gi->libs < GROUP_REFILL_LIBS ? gi->libs : GROUP_REFILL_LIBS;
23 for (int i = 0; i < libs; i++) {
24 hash_t hlib = hash_at(b, gi->lib[i], color);
25 /* Rotate the hash based on prospects of the liberty. */
26 int p = immediate_liberty_count(b, gi->lib[i]) +
27 4 * neighbor_count_at(b, gi->lib[i], color);
28 hlib = (hlib << p) | ((hlib >> (hbits - p)) & ((1<<p) - 1));
29 /* Add to hash. */
30 h ^= hlib;
33 return h;