diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-07 23:09:56 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-07 23:33:12 +0300 |
commit | 8653b86cae4c9879a9ba8fedc43c141667c93a2d (patch) | |
tree | ab38b59c9c900827a77962a6cd7e4df5d6a4bbdf | |
parent | 7e3289cb5968cd4d115ce117b1c9e318b00d875a (diff) | |
download | c-chess-8653b86cae4c9879a9ba8fedc43c141667c93a2d.tar.gz |
fix: only allow castling with rooks
-rw-r--r-- | src/main.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -255,13 +255,13 @@ int validate_move(Move move, int color, int* board) { // Handle castling if ((piece & NO_COLOR) == KING) { if (piece % 2 == WHITE && move.origin == 4) { - if (move.destination == 2) { + if (move.destination == 2 && board[0] == (ROOK | WHITE)) { if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 1; i < 4; i++) { if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; } return 0; - } else if (move.destination == 6) { + } else if (move.destination == 6 && board[7] == (ROOK | WHITE)) { if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 5; i < 7; i++) { if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; @@ -269,13 +269,13 @@ int validate_move(Move move, int color, int* board) { return 0; } } else if (piece % 2 == BLACK && move.origin == 116) { - if (move.destination == 114) { + if (move.destination == 114 && board[112] == (ROOK | BLACK)) { if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; - for (int i = 114; i < 116; i++) { + for (int i = 113; i < 116; i++) { if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; } return 0; - } else if (move.destination == 118) { + } else if (move.destination == 118 && board[119] == (ROOK | BLACK)) { if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 117; i < 119; i++) { if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; |