From 3a9cdaa176370edd81653d62812c836f9bb00219 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 18 Aug 2022 10:10:51 +0300 Subject: feat: make game interactive --- src/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index edb553b..c66ab37 100644 --- a/src/main.c +++ b/src/main.c @@ -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) { -- cgit v1.2.3