From c0ffcf118ca558c066b2ff6b15d2c3b3742d0cf8 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Sep 2022 12:01:56 +0300 Subject: feat: add aspiration window --- src/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index a6ef917..1c5664a 100644 --- a/src/main.c +++ b/src/main.c @@ -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++; } -- cgit v1.2.3