Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.3

- Fix `Crazyhouse.isGameOver` and `Crazyhouse.isCheckmate` in positions where all legal moves are drop moves.

## 0.12.2

- Add `SquareSet explosionSquares(Move move)` method to Atomic class.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,10 @@ abstract class Crazyhouse extends Position {
@override
Outcome? get variantOutcome => null;

@override
bool get hasSomeLegalMoves =>
legalDrops.isNotEmpty || super.hasSomeLegalMoves;

@override
void validate({bool? ignoreImpossibleCheck}) {
super.validate(ignoreImpossibleCheck: ignoreImpossibleCheck);
Expand Down
55 changes: 14 additions & 41 deletions test/position_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,17 @@ void main() {
}
});

test('game is not over when all valid moves are drop moves', () {
final pos = Crazyhouse.fromSetup(Setup.parseFen(
'r1bQqk1R/ppp2ppp/3p4/6n1/2B5/5P2/PPP3PP/3n1K1R[PPNBBpnr] b - - 3 23'));
expect(pos.legalMoves.values,
everyElement((SquareSet squareSet) => squareSet.isEmpty));
expect(pos.legalDrops, const SquareSet.fromSquare(Square.g8));
expect(pos.hasSomeLegalMoves, true);
expect(pos.isGameOver, false);
expect(pos.isCheckmate, false);
});

test('en passant capture', () {
final pos = Crazyhouse.fromSetup(Setup.parseFen(
'r1bqkbnr/ppppp1pp/2n5/4Pp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3'))
Expand Down Expand Up @@ -1010,47 +1021,9 @@ void main() {
});

test('castle checkmates', () {
Position position = Crazyhouse.initial;
final moves = [
'd4',
'f5',
'Nc3',
'Nf6',
'Nf3',
'e6',
'Bg5',
'Be7',
'Bxf6',
'Bxf6',
'e4',
'fxe4',
'Nxe4',
'b6',
'Ne5',
'O-O',
'Bd3',
'Bb7',
'Qh5',
'Qe7',
'Qxh7+',
'Kxh7',
'Nxf6+',
'Kh6',
'Neg4+',
'Kg5',
'h4+',
'Kf4',
'g3+',
'Kf3',
'Be2+',
'Kg2',
'Rh2+',
'Kg1',
'O-O-O#',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veloce FYI this was not actually checkmate, since black can block the check by dropping a piece here :D That's why I had to change this test as well

];
for (final move in moves) {
position = position.play(position.parseSan(move)!);
}
Position position = Crazyhouse.fromSetup(Setup.parseFen(
'rnbq1r2/pbppq1p1/1p2pN2/7p/2PP2NP/1P4P1/P3BP1R/R3K1k1[PPNB] w Q - 1 21'));
position = position.play(position.parseSan('O-O-O#')!);
expect(position.isCheckmate, equals(true));
});
});
Expand Down