diff options
Diffstat (limited to 'include/zobrist.c')
| -rw-r--r-- | include/zobrist.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/include/zobrist.c b/include/zobrist.c index 2922abf..5076fe1 100644 --- a/include/zobrist.c +++ b/include/zobrist.c @@ -50,18 +50,19 @@ void zobrist_free(void) { } -// a position's value is from the perspective of the player to move, which flips -// with parity, so we must track this -#define PLY_PARITY_MAGIC 0x9E3779B97F4A7C15ULL +uint64_t zobrist_cell(tak_state_p state, const uint8_t l) { + colour_stack_t c = state->colours[l]; + const uint8_t count = COUNT_AT(state, l); + enum STONE_VARIANT s = STONE_AT(state, l); + uint64_t h = 0; + for (uint8_t hh = 0; hh < count; hh++, c >>= 1) + h ^= zobrist[l * (15 * 2 * 3) + hh * 2 * 3 + (c & 1) * 3 + s]; + return h; +} uint64_t zobrist_compute(tak_state_p state) { uint64_t hash = 0; - for (uint8_t l = 0; l < state->board_size * state->board_size; l++) { - colour_stack_t c = state->colours[l]; - const uint8_t count = COUNT_AT(state, l); - enum STONE_VARIANT s = STONE_AT(state, l); - for (uint8_t h = 0; h < count; h++, c >>= 1) - hash ^= zobrist[l * (15 * 2 * 3) + h * 2 * 3 + (c & 1) * 3 + s]; - } + for (uint8_t l = 0; l < state->board_size * state->board_size; l++) + hash ^= zobrist_cell(state, l); return hash ^ ((state->ply & 1) ? PLY_PARITY_MAGIC : 0); } |
