mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 19:34:08 +01:00
DroidFish: Improved handling of invalid en passant square in FEN
parsing.
This commit is contained in:
parent
651e649902
commit
9d5fad30a4
|
@ -130,10 +130,21 @@ public class TextIO {
|
|||
// En passant target square
|
||||
String epString = words[3];
|
||||
if (!epString.equals("-")) {
|
||||
if (epString.length() < 2) {
|
||||
if (epString.length() < 2)
|
||||
throw new ChessParseError(R.string.err_invalid_en_passant_square, pos);
|
||||
int epSq = getSquare(epString);
|
||||
if (epSq != -1) {
|
||||
if (pos.whiteMove) {
|
||||
if ((Position.getY(epSq) != 5) || (pos.getPiece(epSq) != Piece.EMPTY) ||
|
||||
(pos.getPiece(epSq - 8) != Piece.BPAWN))
|
||||
epSq = -1;
|
||||
} else {
|
||||
if ((Position.getY(epSq) != 2) || (pos.getPiece(epSq) != Piece.EMPTY) ||
|
||||
(pos.getPiece(epSq + 8) != Piece.WPAWN))
|
||||
epSq = -1;
|
||||
}
|
||||
pos.setEpSquare(epSq);
|
||||
}
|
||||
pos.setEpSquare(getSquare(epString));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,28 @@ public class TextIOTest extends TestCase {
|
|||
// (excessive memory usage) for the clock history class.
|
||||
pos = TextIO.readFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 10000");
|
||||
assertEquals(10000, pos.fullMoveCounter);
|
||||
|
||||
// Test invalid en passant square detection
|
||||
pos = TextIO.readFEN("rnbqkbnr/pp1ppppp/8/8/2pPP3/8/PPP2PPP/RNBQKBNR b KQkq d3 0 1");
|
||||
assertEquals(TextIO.getSquare("d3"), pos.getEpSquare());
|
||||
|
||||
pos = TextIO.readFEN("rnbqkbnr/pp1ppppp/8/8/2pPP3/8/PPP2PPP/RNBQKBNR w KQkq d3 0 1");
|
||||
assertTrue(pos.equals(TextIO.readFEN("rnbqkbnr/pp1ppppp/8/8/2pPP3/8/PPP2PPP/RNBQKBNR w KQkq - 0 1")));
|
||||
|
||||
pos = TextIO.readFEN("rnbqkbnr/ppp2ppp/8/2Ppp3/8/8/PP1PPPPP/RNBQKBNR w KQkq d6 0 1");
|
||||
assertEquals(TextIO.getSquare("d6"), pos.getEpSquare());
|
||||
|
||||
pos = TextIO.readFEN("rnbqkbnr/ppp2ppp/8/2Ppp3/8/8/PP1PPPPP/RNBQKBNR b KQkq d6 0 1");
|
||||
assertTrue(pos.equals(TextIO.readFEN("rnbqkbnr/ppp2ppp/8/2Ppp3/8/8/PP1PPPPP/RNBQKBNR b KQkq - 0 1")));
|
||||
|
||||
pos = TextIO.readFEN("rnbqkbnr/pppppppp/8/8/3PP3/8/PPP2PPP/RNBQKBNR b KQkq d3 0 1");
|
||||
assertEquals(-1, pos.getEpSquare());
|
||||
|
||||
pos = TextIO.readFEN("rnbqkbnr/ppp2ppp/8/3pp3/8/8/PPPPPPPP/RNBQKBNR w KQkq e6 0 1");
|
||||
assertEquals(-1, pos.getEpSquare());
|
||||
|
||||
pos = TextIO.readFEN("rnbqkbnr/pp1ppppp/8/8/2pPP3/3P4/PP3PPP/RNBQKBNR b KQkq d3 0 1");
|
||||
assertTrue(pos.equals(TextIO.readFEN("rnbqkbnr/pp1ppppp/8/8/2pPP3/3P4/PP3PPP/RNBQKBNR b KQkq - 0 1")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user