diff options
-rw-r--r-- | src/main.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -292,8 +292,7 @@ int compute_score(int* board) { // Value here is white material advantage over black // Alpha is the best value for maximizer (white) // Beta is the best value for minimizer (black) -int find_best_move(int* board, int color, int depth, int alpha, int beta) { - int best_move[2]; +int find_best_move(int best_move[2], int* board, int color, int depth, int alpha, int beta) { int fake_board[128]; int is_maximizer = (color == 0); int best_value = is_maximizer ? -INFINITY : INFINITY; @@ -319,8 +318,9 @@ int find_best_move(int* board, int color, int depth, int alpha, int beta) { apply_move(move, fake_board); + int dummy[2]; int value = depth < MAX_DEPTH - ? find_best_move(fake_board, 1 - color, depth + 1, alpha, beta) + ? find_best_move(dummy, fake_board, 1 - color, depth + 1, alpha, beta) : compute_score(fake_board); if (is_maximizer) { @@ -365,13 +365,14 @@ int main() { int move[2]; - int color = 0; + int color = WHITE; while (1) { - 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); + if (color == WHITE) { + printf("Current score is %i\n", compute_score(board)); + printf("Enter a move for %s:\n", COLORS[color]); + input_move(move); + } else find_best_move(move, board, color, 0, -INFINITY, +INFINITY); int error = validate_move(move, color, board); if (error < 0) { |