DroidFish: Don't crash if the engine wants to play an invalid move.

This commit is contained in:
Peter Osterlund 2017-06-11 22:37:01 +02:00
parent 97662f067e
commit e51c86f621
3 changed files with 33 additions and 31 deletions

View File

@ -2805,27 +2805,20 @@ public class DroidFish extends Activity
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
int gameModeType = -1;
/* only flip site in case the player was specified resp. changed */
boolean flipSite = false;
boolean matchPlayerNames = false;
switch (item) {
case 0: gameModeType = GameMode.ANALYSIS; break;
case 1: gameModeType = GameMode.EDIT_GAME; break;
case 2: gameModeType = GameMode.PLAYER_WHITE; flipSite = true; break;
case 3: gameModeType = GameMode.PLAYER_BLACK; flipSite = true; break;
case 2: gameModeType = GameMode.PLAYER_WHITE; matchPlayerNames = true; break;
case 3: gameModeType = GameMode.PLAYER_BLACK; matchPlayerNames = true; break;
case 4: gameModeType = GameMode.TWO_PLAYERS; break;
case 5: gameModeType = GameMode.TWO_COMPUTERS; break;
default: break;
}
dialog.dismiss();
if (gameModeType >= 0) {
Editor editor = settings.edit();
String gameModeStr = String.format(Locale.US, "%d", gameModeType);
editor.putString("gameMode", gameModeStr);
editor.commit();
gameMode = new GameMode(gameModeType);
maybeAutoModeOff(gameMode);
ctrl.setGameMode(gameMode);
setBoardFlip(flipSite);
newGameMode(gameModeType);
setBoardFlip(matchPlayerNames);
}
}
});
@ -3831,6 +3824,12 @@ public class DroidFish extends Activity
@Override
public void movePlayed(Position pos, Move move, boolean computerMove) {
if (move == null) {
Toast.makeText(getApplicationContext(), R.string.engine_error,
Toast.LENGTH_SHORT).show();
newGameMode(GameMode.EDIT_GAME);
return;
}
if ("sound".equals(moveAnnounceType)) {
if (computerMove) {
if (moveSound != null)
@ -3963,8 +3962,6 @@ public class DroidFish extends Activity
/** Set automatic move forward/backward mode. */
void setAutoMode(AutoMode am) {
// System.out.printf("%.3f DroidFish.setAutoMode(): %s\n",
// System.currentTimeMillis() * 1e-3, am.toString());
autoMode = am;
switch (am) {
case BACKWARD:

View File

@ -741,12 +741,14 @@ public class DroidComputerPlayer {
case PONDER:
case ANALYZE: {
String[] tokens = tokenize(s);
int nTok = tokens.length;
if (nTok > 0) {
if (tokens[0].equals("info")) {
parseInfoCmd(tokens);
} else if (tokens[0].equals("bestmove")) {
String bestMove = tokens[1];
String bestMove = nTok > 1 ? tokens[1] : "";
String nextPonderMoveStr = "";
if ((tokens.length >= 4) && (tokens[2].equals("ponder")))
if ((nTok >= 4) && (tokens[2].equals("ponder")))
nextPonderMoveStr = tokens[3];
Move nextPonderMove = TextIO.UCIstringToMove(nextPonderMoveStr);
@ -757,6 +759,7 @@ public class DroidComputerPlayer {
searchRequest = null;
handleIdleState();
}
}
break;
}
case STOP_SEARCH: {

View File

@ -1027,11 +1027,13 @@ public class DroidChessController {
updateGameMode();
gui.movePlayed(game.prevPos(), res.second, true);
listener.clearSearchInfo(searchId);
if (res.first) {
updateComputeThreads();
setSelection();
setAnimMove(oldPos, game.getLastMove(), true);
updateGUI();
}
}
public final void repeatLastMove() {
gui.movePlayed(game.prevPos(), game.tree.currentNode.move, true);