mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
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:
parent
61317fa78d
commit
1afda36d85
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user