diff options
Diffstat (limited to 'include/zobrist.c')
| -rw-r--r-- | include/zobrist.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/include/zobrist.c b/include/zobrist.c index 1fdd8a9..d8d1856 100644 --- a/include/zobrist.c +++ b/include/zobrist.c @@ -27,13 +27,14 @@ static uint64_t *zobrist; // Exported method implementations // =================================================================== -int zobrist_init(void) { - if (zobrist != NULL) return EXIT_FAILURE; +int zobrist_init(const uint8_t board_size) { + if (zobrist != NULL) + return EXIT_FAILURE; - zobrist = malloc(sizeof(uint64_t)*board_size*board_size*(15*2*3)); + zobrist = malloc(sizeof(uint64_t) * board_size * board_size * (15 * 2 * 3)); // TODO: trap errno - for (int k=0; k<board_size*board_size*(15*2*3); k++) { + for (int k = 0; k < board_size * board_size * (15 * 2 * 3); k++) { XORSHIFT64; zobrist[k] = RANDOM64; } @@ -48,14 +49,14 @@ void zobrist_free(void) { } } -uint64_t zobrist_compute(void) { +uint64_t zobrist_compute(tak_state_p state) { uint64_t hash = 0; - for (uint8_t l=0; l<board_size*board_size; l++) { - colour_stack_t c = colours[l]; - const uint8_t count = COUNT_AT(l); - enum STONE_VARIANT s = STONE_AT(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++) { + 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]; } return hash; } |
