summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-08-20 14:17:18 +0300
committereug-vs <eugene@eug-vs.xyz>2022-08-20 14:17:18 +0300
commite729c408f4af4fe4315eecf80211ca17917b1cb2 (patch)
tree77472bea4f120c0c955211fc4adefbdfc43762cf
parent98a9002bb9bef19843112366e2ab464069fcca58 (diff)
downloadc-chess-e729c408f4af4fe4315eecf80211ca17917b1cb2.tar.gz
feat: improve move ordering
-rw-r--r--src/main.c7
1 files 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;