diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-05 01:17:06 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-05 01:17:06 +0300 |
commit | 7259cb839abc42142ad88e237b2561a62058f961 (patch) | |
tree | 69f02aed8410157e6820af3091f1252f36c4a9e1 | |
parent | 6351ab0f49ba8f1d4c103baa849b2be8c1826455 (diff) | |
download | c-chess-7259cb839abc42142ad88e237b2561a62058f961.tar.gz |
refactor: always use relative depth
-rw-r--r-- | src/main.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -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); |