diff options
| author | tslil clingman <tslil@posteo.de> | 2021-01-28 13:54:10 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 6e6cdc4d9f0d7e4afdda67c97e7d7f13959e6134 (patch) | |
| tree | 15322705ce1dd73c1eb863678360a0e403490337 /include/negamax.c | |
| parent | 55b45cc666c2ef883efe3831b96ac40623622582 (diff) | |
| parent | 1be9fac33c8227564079356c63840d227c88725f (diff) | |
Merge branch 'zobrist'
Diffstat (limited to 'include/negamax.c')
| -rw-r--r-- | include/negamax.c | 62 |
1 files changed, 2 insertions, 60 deletions
diff --git a/include/negamax.c b/include/negamax.c index 061b629..cfe2643 100644 --- a/include/negamax.c +++ b/include/negamax.c @@ -8,74 +8,15 @@ const float infty = 3.0; char negamax_ptn[9]; uint8_t negamax_search_depth = 3; -static uint64_t *zobrist[15]; - // =================================================================== // Helpers // =================================================================== -static void -zobrist_free(void); - -static int -zobrist_init(void); - -static uint64_t -zobrist_compute(void); - static float negamax(const uint8_t cur_depth, float alpha, float beta, const float colour); // =================================================================== -// Zobrist hashing -// =================================================================== - -static uint64_t -zobrist_compute(void) { - 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<15; h++) { - if (h<count) { - hash ^= zobrist[h][l*(2*3+1)+(c&1)*3+s]; - c >>= 1; - } - } - } - return hash; -} - -static int -zobrist_init(void) { - for (int k=0; k<15; k++) { - if (zobrist[k] != NULL) return EXIT_FAILURE; - } - - for (int j=0; j<15; j++) { - zobrist[j] = malloc(sizeof(uint64_t)*board_size*board_size*(2*3+1)); - for (int k=0; k<board_size*board_size*(2*3+1); k++) { - XORSHIFT64; - zobrist[j][k] = RANDOM64; - } - } - - return EXIT_SUCCESS; -} - -static void -zobrist_free(void) { - for (int k=0; k<15; k++) { - if (zobrist[k] != NULL) { - free(zobrist[k]); - zobrist[k] = NULL; - } - } -} - -// =================================================================== // α-β negamax using the cnn1986 evaluation function and transposition // tables using Zobrist hasing and a treap // =================================================================== @@ -119,7 +60,7 @@ negamax(const uint8_t cur_depth, float alpha, float beta, tt_entry_t *entry = tt_seek(hash); // CAUTION: >= breaks search stability - if (entry != NULL && entry->depth == cur_depth) { + if (entry != NULL && entry->depth >= cur_depth) { if (entry->flag == TT_EXACT) { return entry->value; } else if (entry->flag == TT_LOWERBOUND && entry->value > alpha) { @@ -145,6 +86,7 @@ negamax(const uint8_t cur_depth, float alpha, float beta, for (action_node_t *node=list->head; node!=NULL; node=node->next) { action_take(node->action); + // Compute the value of the node float node_value; if (ply >= 2*board_size - 2 && (w = check_win()) < 0xFF) { |
