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/main.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main.c') 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