diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/cnn1986_treap_cache.c | 3 | ||||
| -rw-r--r-- | include/negamax.c | 32 | ||||
| -rw-r--r-- | include/negamax.h | 2 | ||||
| -rw-r--r-- | include/xorshift64.h | 2 |
4 files changed, 18 insertions, 21 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<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, 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; \ |
