From e729c408f4af4fe4315eecf80211ca17917b1cb2 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 20 Aug 2022 14:17:18 +0300 Subject: feat: improve move ordering --- src/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index fe1836e..bfe2017 100644 --- a/src/main.c +++ b/src/main.c @@ -471,7 +471,7 @@ int compute_score(int* board) { return material_advantage + coverage_score + positioning_score; } -int list_available_moves(Move moves[MAX_AVAILABLE_MOVES], int* board, int color) { +int list_available_moves(Move* moves, int* board, int color) { int moves_count = 0; for (int rank = 7; rank >= 0; rank--) { @@ -519,11 +519,11 @@ int compare_moves(const void* a, const void* b) { return ((Move*)a)->value - ((Move*)b)->value; } -void sort_moves(Move moves[MAX_AVAILABLE_MOVES], int moves_count, int* board) { +void sort_moves(Move* moves, int moves_count, int* board) { for (int i = 0; i < moves_count; i++) { int origin_value = get_piece_raw_value(board[moves[i].origin]); int destination_value = get_piece_raw_value(board[moves[i].destination]); - moves[i].value = destination_value - origin_value; + moves[i].value = 10 * destination_value - origin_value; } qsort(moves, moves_count, sizeof(Move), compare_moves); @@ -544,7 +544,6 @@ Move find_best_move(int* board, int color, int depth, int alpha, int beta, int* Move available_moves[MAX_AVAILABLE_MOVES]; int availabel_moves_count = list_available_moves(available_moves, board, color); sort_moves(available_moves, availabel_moves_count, board); - if (depth == 0 && available_moves[0].value == 0) printf("Sort did not help or was wrong!"); for (int i = 0; i < availabel_moves_count; i++) { *metrics += 1; -- cgit v1.2.3