From 851cb160f0d2838c75af43dcc7b6fad9969d925c Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Sep 2022 17:48:03 +0300 Subject: feat: add castle to generate moves --- src/config.h | 4 ++-- src/main.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/config.h b/src/config.h index f994cee..0b54698 100644 --- a/src/config.h +++ b/src/config.h @@ -5,6 +5,6 @@ #define INFINITY 2000 #define MAX_ZOBRIST_SEEDS 1500 #define TRANSPOSITION_TABLE_SIZE 1000000 -#define PLAYER 3 +#define PLAYER WHITE #define FILENAME "record.txt" -#define MOVE_TIME 15 +#define MOVE_TIME 10 diff --git a/src/main.c b/src/main.c index 13013f8..4327b2e 100644 --- a/src/main.c +++ b/src/main.c @@ -546,6 +546,25 @@ int generate_pseudolegal_moves(Move* moves, int* board, int color) { moves_count++; } } + + // Castling + if (piece == (KING | WHITE) && origin == 4) { + if (board[1] == EMPTY && board[2] == EMPTY && board[3] == EMPTY && board[0] == (ROOK | WHITE)) { + if (moves) moves[moves_count] = (Move){ origin, origin - 2, 0 }; + moves_count++; + } if (board[5] == EMPTY && board[6] == EMPTY && board[7] == (ROOK | WHITE)) { + if (moves) moves[moves_count] = (Move){ origin, origin + 2, 0 }; + moves_count++; + } + } else if (piece == (KING | BLACK) && origin == 116) { + if (board[113] == EMPTY && board[114] == EMPTY && board[115] == EMPTY && board[112] == (ROOK | BLACK)) { + if (moves) moves[moves_count] = (Move){ origin, origin - 2, 0 }; + moves_count++; + } if (board[117] == EMPTY && board[118] == EMPTY && board[119] == (ROOK | BLACK)) { + if (moves) moves[moves_count] = (Move){ origin, origin + 2, 0 }; + moves_count++; + } + } } } } @@ -747,7 +766,7 @@ Move iterative_deepening(int* board, int color, long hash, Transposition* transp } printf("Max depth (%i) reached in %.2f seconds\n", MAX_DEPTH, (double)(clock() - start) / CLOCKS_PER_SEC); - return best_move; + return move; } int main() { -- cgit v1.2.3