chesslib: A threefold repetition not detected
The threefold repetition after 5… Bf8 for the below moves is not detected. Why is that the case? Can you please check? The positions, possibilities to capture en passant and castle rights after 1… e5, 3… Bf8 and 5… Bf8 are the same. This is a threefold repetition after 5… Bf8.
final MoveList moveList = new MoveList(); //use MoveList to play moves on the board using SAN
moveList.loadFromSan("1. e4 e5 2. Be2 Be7 3. Bf1 Bf8 4. Bd3 Bd6 5. Bf1 Bf8");
final Board board = new Board();
final Iterator<Move> moves = moveList.iterator();
while (moves.hasNext()) {
board.doMove(moves.next());
}
System.out.println(board.isRepetition()); // false but should be true
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (12 by maintainers)
Commits related to this issue
- Fix repetition detection, fix #39 — committed to bhlangonijr/chesslib by bhlangonijr 4 years ago
There must be something wrong here. Probably only a small problem in the code, I can’t see through, but there is something off.
In the first example, both players lose all castling rights by moving their kings. So the position after 5… Ke8 and the initial position are not the same. The position after 7… N8 is the same as after 5… Ke8, so this is a twofold repetition, but flagged as threefold.
In the second example, there is a pawn two square advance involved. After 3… d5 capturing en passant is not possible. So this is the same position as after 5… Nf6 and 7… Nf6. See “9.2.2.1 at the start of the sequence a pawn could have been captured en passant” in the rules. 7… Nf6 is a threefold repetition but not flagged as such.
For the third example, I chose a real game mentioned in Wikipedia. Wikipedia states that there is a threefold repetition after 38… Kf8. But this is not flagged as threefold. Again there is a pawn two square advance at the beginning of the sequence. But because there is no en passant capture possible the positions after 34…h5 36…Kf8 and 38…Kf8 are the same, which gives the threefold repetition after 38…Kf8.
Should I not overlook something, there is something missing here and your API could improve greatly by addressing this. The method
board.isRepetition()
says in the codeVerify threefold repetition
so is definitely meant for threefold repetition detection!