From 7259cb839abc42142ad88e237b2561a62058f961 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 5 Sep 2022 01:17:06 +0300 Subject: refactor: always use relative depth --- src/main.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 6abea38..25a6a2f 100644 --- a/src/main.c +++ b/src/main.c @@ -609,16 +609,14 @@ Move minimax_search(int* board, int color, int depth, int alpha, int beta, int* long move_hash = hash_after_move(move, board, zobrist_seed, hash); int captured_piece = make_move(move, board); - int relative_depth = MAX_DEPTH - depth; - - move.value = relative_depth > 0 - ? minimax_search(board, 1 - color, depth + 1, alpha, beta, metrics, hash, transposition_table, zobrist_seed).value + move.value = depth > 0 + ? minimax_search(board, 1 - color, depth - 1, alpha, beta, metrics, hash, transposition_table, zobrist_seed).value : evaluate_position(board, available_moves_count, color); - if (transposition_table[move_hash].depth < relative_depth) { + if (transposition_table[move_hash].depth < depth) { if (transposition_table[move_hash].depth == -1) TRANSPOSITION_TABLE_CARDINALITY++; transposition_table[move_hash].value = move.value; - transposition_table[move_hash].depth = relative_depth; + transposition_table[move_hash].depth = depth; } unmake_move(move, captured_piece, board); @@ -670,7 +668,7 @@ int main() { clock_t start, end; int metrics = 0; start = clock(); - move = minimax_search(board, color, 0, -INFINITY, +INFINITY, &metrics, hash, transposition_table, zobrist_seed); + move = minimax_search(board, color, MAX_DEPTH, -INFINITY, +INFINITY, &metrics, hash, transposition_table, zobrist_seed); end = clock(); printf("[%i positions analyzed in %f seconds]\n", metrics, (double)(end - start) / CLOCKS_PER_SEC); printf("[Transposition table cardinality: %i]\n", TRANSPOSITION_TABLE_CARDINALITY); -- cgit v1.2.3