From 9eb1a379853b088df0ab3a4beae4e79eaead4823 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Sat, 23 Jan 2021 18:55:48 -0500 Subject: Fixed some important bugs --- include/cnn1986_treap_cache.c | 3 +-- include/negamax.c | 32 +++++++++++++++----------------- include/negamax.h | 2 +- include/xorshift64.h | 2 +- src/ctaklm.c | 4 ++-- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/include/cnn1986_treap_cache.c b/include/cnn1986_treap_cache.c index 94eda58..941ec1c 100644 --- a/include/cnn1986_treap_cache.c +++ b/include/cnn1986_treap_cache.c @@ -101,8 +101,7 @@ TreapNode new_treap_node(const float in_result, const uint64_t key) { n->left = NULL; n->right = NULL; n->parent = NULL; - n->weight = RANDOM32; - XORSHIFT; + XORSHIFT64; n->weight = RANDOM32; // Set value n->result = in_result; return n; 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>= 1; + if (count) { + colour_stack_t c = colours[l]; + enum STONE_VARIANT s = STONE_AT(l); + for (uint8_t h=0; h>= 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, diff --git a/include/negamax.h b/include/negamax.h index fbdf8da..d00780d 100644 --- a/include/negamax.h +++ b/include/negamax.h @@ -9,7 +9,7 @@ extern char negamax_ptn[9]; extern uint8_t negamax_search_depth; extern inline void negamax_display_progress(const uint8_t); -void negamax_init_size(void); +void negamax_init(const uint8_t new_board_size); uint64_t negamax_compute_zobrist(void); // Do negamax to depth negamax_search_depth and return PTN of best move diff --git a/include/xorshift64.h b/include/xorshift64.h index a12a38d..ee41abc 100644 --- a/include/xorshift64.h +++ b/include/xorshift64.h @@ -5,7 +5,7 @@ extern uint64_t xors; -#define XORSHIFT { \ +#define XORSHIFT64 { \ xors ^= xors >> 12; \ xors ^= xors << 25; \ xors ^= xors >> 27; \ diff --git a/src/ctaklm.c b/src/ctaklm.c index 59e0e2e..f7a58d9 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -424,10 +424,10 @@ main(int argc, char **argv) { */ // Test harness - negamax_init_size(); negamax_search_depth = 5; new_game(5); - for (int k=0; k<8; k++) negamax_turn(); + negamax_init(5); + for (int k=0; k<2; k++) negamax_turn(); return 0; // Test harness -- cgit v1.2.3