diff options
Diffstat (limited to 'include/negamax.c')
| -rw-r--r-- | include/negamax.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/include/negamax.c b/include/negamax.c index bc912ad..e1c2991 100644 --- a/include/negamax.c +++ b/include/negamax.c @@ -17,15 +17,9 @@ uint64_t *zobrist = NULL; static int negamax_init_zobrist(void) { if (zobrist != NULL) return EXIT_FAILURE; zobrist = malloc(sizeof(uint64_t)*board_size*board_size*16*3*2); - for (int l=0; l<board_size*board_size; l++) { - for (int h=0; h<16; h++) { - for (int c=0; c<2; c++) { - for (int s=0; s<3; s++) { - XORSHIFT; - zobrist[l*board_size*board_size+h*16+c*2+s] = RANDOM64; - } - } - } + for (int k=0; k<board_size*board_size*16*3*2; k++) { + XORSHIFT64; + zobrist[k] = RANDOM64; } return EXIT_SUCCESS; } @@ -40,14 +34,15 @@ static void negamax_free_zobrist(void) { uint64_t negamax_compute_zobrist(void) { uint64_t result = 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++) { - result ^= zobrist[l*board_size*board_size - +h*16 +(c&1)*2 +s]; - s = STONE_FLAT; - c >>= 1; + if (count) { + colour_stack_t c = colours[l]; + enum STONE_VARIANT s = STONE_AT(l); + for (uint8_t h=0; h<count; h++) { + result ^= zobrist[l*16*2*3 + h*3*2 + (c&1)*3 + s]; + s = STONE_FLAT; + c >>= 1; + } } } return result; @@ -61,7 +56,8 @@ uint64_t negamax_compute_zobrist(void) { // Movement steps, orderd with the enum: UP DOWN LEFT RIGHT static int8_t deltas[4]; -void negamax_init_size(void) { +void negamax_init(const uint8_t new_board_size) { + board_size = new_board_size; deltas[0] = +board_size; deltas[1] = -board_size; deltas[2] = -1; @@ -129,7 +125,9 @@ static enum WIN_TYPE w; float negamax(const uint8_t cur_depth, float alpha, float beta, const float colour) { + uint64_t hash = negamax_compute_zobrist(); + if (cnn1986_cache_seek(hash, &alpha) == EXIT_FAILURE) { const uint8_t black = (ply & 1), material = (black) ? black_count : white_count, |
