mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-12 17:12:40 +01:00
DroidFish: Better error messages when trying to read invalid FEN/PGN data.
This commit is contained in:
@@ -477,10 +477,13 @@ public class GameTree {
|
||||
Node gameRoot = new Node();
|
||||
Node.parsePgn(scanner, gameRoot, options);
|
||||
|
||||
// Store parsed data in GameTree
|
||||
if ((tagPairs.size() == 0) && (gameRoot.children.size() == 0))
|
||||
return false;
|
||||
if (tagPairs.size() == 0) {
|
||||
gameRoot.verifyChildren(TextIO.readFEN(TextIO.startPosFEN));
|
||||
if (gameRoot.children.size() == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store parsed data in GameTree
|
||||
String fen = TextIO.startPosFEN;
|
||||
int nTags = tagPairs.size();
|
||||
for (int i = 0; i < nTags; i++) {
|
||||
|
||||
@@ -72,10 +72,18 @@ public class TextIO {
|
||||
default: throw new ChessParseError(R.string.err_invalid_piece, pos);
|
||||
}
|
||||
}
|
||||
if (words[1].length() == 0) {
|
||||
|
||||
if (words[1].length() > 0) {
|
||||
boolean wtm;
|
||||
switch (words[1].charAt(0)) {
|
||||
case 'w': wtm = true; break;
|
||||
case 'b': wtm = false; break;
|
||||
default: throw new ChessParseError(R.string.err_invalid_side, pos);
|
||||
}
|
||||
pos.setWhiteMove(wtm);
|
||||
} else {
|
||||
throw new ChessParseError(R.string.err_invalid_side, pos);
|
||||
}
|
||||
pos.setWhiteMove(words[1].charAt(0) == 'w');
|
||||
|
||||
// Castling rights
|
||||
int castleMask = 0;
|
||||
|
||||
Reference in New Issue
Block a user