diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -261,6 +261,33 @@ int compute_material_advantage(int* board, int color) { return counter; } +int compute_coverage(int* board, int color) { + int counter = 0; + for (int rank = 7; rank >= 0; rank--) { + for (int file = 0; file < 8; file++) { + int index = rank * 16 + file; + int piece = board[index]; + if (piece != EMPTY && (piece % 2) == color) { + for (int rank_destination = 7; rank_destination >= 0; rank_destination--) { + for (int file_destination = 0; file_destination < 8; file_destination++) { + int index_destination = rank_destination * 16 + file_destination; + int move[2] = { index, index_destination }; + if (validate_move(move, color, board) >= 0) { + counter++; + } + } + } + } + } + } + return counter; +} + +int compute_score(int* board) { + int coverage_score = compute_coverage(board, WHITE) - compute_coverage(board, BLACK); + return compute_material_advantage(board, WHITE) + coverage_score; +} + // Alpha-beta pruning // Value here is white material advantage over black // Alpha is the best value for maximizer (white) @@ -294,7 +321,7 @@ int find_best_move(int* board, int color, int depth, int alpha, int beta) { int value = depth < MAX_DEPTH ? find_best_move(fake_board, 1 - color, depth + 1, alpha, beta) - : compute_material_advantage(fake_board, 0); // Always for maximizer (white) + : compute_score(fake_board); if (is_maximizer) { if (value > best_value) { @@ -341,7 +368,7 @@ int main() { int color = 0; while (1) { - printf("Current board advantage is %i\n", compute_material_advantage(board, 0)); + printf("Current score is %i\n", compute_score(board)); find_best_move(board, color, 0, -INFINITY, +INFINITY); printf("Enter a move for %s:\n", COLORS[color]); input_move(move); |