Skip to content

Commit

Permalink
Chess960 castling bug (K-C1, R-A1)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexobviously committed Feb 4, 2024
1 parent 72b6cb1 commit 0f00fe5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 1.4.1
- **Potentially breaking**: FEN strings without castling rights specified now default to no castling rights, instead of all castling rights (thanks @govind-maheshwari2).
- Fixed Seirawan chess mating conditions not taking `H` and `E` into account (thanks @malaschitz).
- Fixed Chess960 castling moves not working in some cases where the rook would land on the square after the king (thanks @malaschitz).

### 1.4.0
- Custom move generation and processing (beta):
Expand Down
2 changes: 1 addition & 1 deletion lib/src/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class Game {
for (int j = 1; j <= numRookMidSquares; j++) {
int midFile = rookFile + (i == 0 ? -j : j);
int midSq = size.square(midFile, royalRank);
if (board[midSq].isNotEmpty) {
if (board[midSq].isNotEmpty && midFile != royalFile) {
valid = false;
break;
}
Expand Down
9 changes: 9 additions & 0 deletions test/misc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ void main() {
),
);
});
test('Chess960 K-C1:R-A1 castling', () {
final g = Game(
variant: CommonVariants.chess960(),
fen: 'rnkqbbrn/pppppppp/8/8/8/8/PPPPPPPP/R1K1BBRN w AGag - 0 1',
);
final moves = g.generateLegalMoves();
expect(moves.castlingMoves.length, 1);
expect(moves.from(g.size.squareNumber('c1')).length, 3);
});
}

0 comments on commit 0f00fe5

Please sign in to comment.