Don't try to fixup invalid e.p. square if the position is invalid

En passant fixup requires generating a list of legal moves, which can
fail with an array index out of bounds exception if there is a pawn on
the first/last rank.
This commit is contained in:
Peter Osterlund 2020-01-03 10:32:49 +01:00
parent 61317fa78d
commit 1afda36d85

View File

@ -442,6 +442,7 @@ public class EditBoard extends Activity {
private void setPosFields() {
setEPFile(getEPFile()); // To handle sideToMove change
if (isValid())
TextIO.fixupEPSquare(cb.pos);
TextIO.removeBogusCastleFlags(cb.pos);
}
@ -478,6 +479,16 @@ public class EditBoard extends Activity {
return false;
}
/** Return true if the position is valid. */
private boolean isValid() {
try {
TextIO.readFEN(TextIO.toFEN(cb.pos));
return true;
} catch (ChessParseError e) {
return false;
}
}
private String getParseErrString(ChessParseError e) {
if (e.resourceId == -1)
return e.getMessage();