diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-08 12:01:56 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-08 12:01:56 +0300 |
commit | c0ffcf118ca558c066b2ff6b15d2c3b3742d0cf8 (patch) | |
tree | 8cdca6e7cdd6afa3cee3e0a39de7831f999fdef6 | |
parent | d9253f1880f4469dace7431acf3ed57504579537 (diff) | |
download | c-chess-c0ffcf118ca558c066b2ff6b15d2c3b3742d0cf8.tar.gz |
feat: add aspiration window
-rw-r--r-- | src/main.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -585,8 +585,8 @@ int order_moves(Move* moves, int moves_count, int* board, long hash, Transpositi */ Move minimax_search(int* board, int color, int depth, int alpha, int beta, int* metrics, long hash, Transposition* transposition_table, long* zobrist_seed, clock_t deadline) { int is_maximizer = (color == 0); - Move best_move = { -100, -100, 0 }; + best_move.value = is_maximizer ? -100 * INFINITY / (depth + 1) : 100 * INFINITY / (depth + 1); // You only have available moves if your king hasn't been taken @@ -638,13 +638,15 @@ Move iterative_deepening(int* board, int color, long hash, Transposition* transp int depth = 0; clock_t start = clock(); clock_t deadline = start + MOVE_TIME * CLOCKS_PER_SEC; + int alpha = -INFINITY; + int beta = +INFINITY; while (depth <= MAX_DEPTH) { best_move = move; printf("Searching with depth %i... [%.2f seconds left]\n", depth, (double)(deadline - clock()) / CLOCKS_PER_SEC); int metrics = 0; - move = minimax_search(board, color, depth, -INFINITY, +INFINITY, &metrics, hash, transposition_table, zobrist_seed, deadline); + move = minimax_search(board, color, depth, alpha, beta, &metrics, hash, transposition_table, zobrist_seed, deadline); if (clock() > deadline) { printf("Out of time! Falling back to result with depth %i\n", depth - 1); @@ -656,6 +658,9 @@ Move iterative_deepening(int* board, int color, long hash, Transposition* transp index_to_notation(move.destination, move_in_notation + 2); printf("Done (%s with evaluation %.2f) [%i positions analyzed]\n", move_in_notation, (double)move.value / 10, metrics); + alpha = move.value - 3; + beta = move.value + 3; + depth++; } |