diff options
| author | eug-vs <eugene@eug-vs.xyz> | 2022-08-18 10:10:51 +0300 | 
|---|---|---|
| committer | eug-vs <eugene@eug-vs.xyz> | 2022-08-18 10:10:51 +0300 | 
| commit | 3a9cdaa176370edd81653d62812c836f9bb00219 (patch) | |
| tree | ba03b13df886fefa3b7a926758d2269a494a0d3c /src | |
| parent | a389dd0562699e36c196d69c578a1f1c373a12ab (diff) | |
| download | c-chess-3a9cdaa176370edd81653d62812c836f9bb00219.tar.gz | |
feat: make game interactive
Diffstat (limited to 'src')
| -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) { | 
