From 93f66971f66c14f18aba743b6d0f8b0f557351ca Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Sat, 23 Jan 2021 20:48:34 -0500 Subject: Hash collisions --- include/negamax.c | 72 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'include/negamax.c') diff --git a/include/negamax.c b/include/negamax.c index e1c2991..3e57165 100644 --- a/include/negamax.c +++ b/include/negamax.c @@ -8,44 +8,62 @@ const float infty = 3.0; char negamax_ptn[9]; uint8_t negamax_search_depth = 3; +uint32_t cache_fails = 0; + // =================================================================== // Zobrist hashing // =================================================================== -uint64_t *zobrist = NULL; +uint64_t *zobrist[4]; +uint64_t *zobrist_empty[4]; 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 k=0; k>= 1; } } } - return result; } // =================================================================== @@ -126,9 +144,15 @@ 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(); + uint64_t hash[4]; + negamax_compute_zobrist(hash); - if (cnn1986_cache_seek(hash, &alpha) == EXIT_FAILURE) { + float stored_alpha; + int lookup = cnn1986_cache_seek(hash, &stored_alpha); + + /* + * if (cnn1986_cache_seek(hash, &alpha) == EXIT_FAILURE) { + */ const uint8_t black = (ply & 1), material = (black) ? black_count : white_count, flat = material & 127, @@ -323,10 +347,17 @@ float negamax(const uint8_t cur_depth, float alpha, float beta, } negamax_display_progress(cur_depth); } - } + /* + * } + */ // Insert into the cache - cnn1986_cache_insert(hash, alpha); } + if (lookup == EXIT_FAILURE) + cnn1986_cache_insert(hash, alpha); + else { + if (stored_alpha != alpha) + cache_fails++; + } return alpha; } @@ -336,6 +367,9 @@ negamax_generate(void) { // values are wins const float safe_infty = infty + 1; + + cache_fails=0; + cnn1986_cache_init(); float result = negamax(0, -safe_infty, safe_infty, (ply&1)?1.0:-1.0); cnn1986_cache_free(); -- cgit v1.3.1