mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-27 06:10:28 +01:00
DroidFish: Don't crash if the engine wants to play an invalid move.
This commit is contained in:
parent
97662f067e
commit
e51c86f621
|
@ -2805,27 +2805,20 @@ public class DroidFish extends Activity
|
||||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
int gameModeType = -1;
|
int gameModeType = -1;
|
||||||
/* only flip site in case the player was specified resp. changed */
|
boolean matchPlayerNames = false;
|
||||||
boolean flipSite = false;
|
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case 0: gameModeType = GameMode.ANALYSIS; break;
|
case 0: gameModeType = GameMode.ANALYSIS; break;
|
||||||
case 1: gameModeType = GameMode.EDIT_GAME; break;
|
case 1: gameModeType = GameMode.EDIT_GAME; break;
|
||||||
case 2: gameModeType = GameMode.PLAYER_WHITE; flipSite = true; break;
|
case 2: gameModeType = GameMode.PLAYER_WHITE; matchPlayerNames = true; break;
|
||||||
case 3: gameModeType = GameMode.PLAYER_BLACK; flipSite = true; break;
|
case 3: gameModeType = GameMode.PLAYER_BLACK; matchPlayerNames = true; break;
|
||||||
case 4: gameModeType = GameMode.TWO_PLAYERS; break;
|
case 4: gameModeType = GameMode.TWO_PLAYERS; break;
|
||||||
case 5: gameModeType = GameMode.TWO_COMPUTERS; break;
|
case 5: gameModeType = GameMode.TWO_COMPUTERS; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
if (gameModeType >= 0) {
|
if (gameModeType >= 0) {
|
||||||
Editor editor = settings.edit();
|
newGameMode(gameModeType);
|
||||||
String gameModeStr = String.format(Locale.US, "%d", gameModeType);
|
setBoardFlip(matchPlayerNames);
|
||||||
editor.putString("gameMode", gameModeStr);
|
|
||||||
editor.commit();
|
|
||||||
gameMode = new GameMode(gameModeType);
|
|
||||||
maybeAutoModeOff(gameMode);
|
|
||||||
ctrl.setGameMode(gameMode);
|
|
||||||
setBoardFlip(flipSite);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3831,6 +3824,12 @@ public class DroidFish extends Activity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void movePlayed(Position pos, Move move, boolean computerMove) {
|
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 ("sound".equals(moveAnnounceType)) {
|
||||||
if (computerMove) {
|
if (computerMove) {
|
||||||
if (moveSound != null)
|
if (moveSound != null)
|
||||||
|
@ -3963,8 +3962,6 @@ public class DroidFish extends Activity
|
||||||
|
|
||||||
/** Set automatic move forward/backward mode. */
|
/** Set automatic move forward/backward mode. */
|
||||||
void setAutoMode(AutoMode am) {
|
void setAutoMode(AutoMode am) {
|
||||||
// System.out.printf("%.3f DroidFish.setAutoMode(): %s\n",
|
|
||||||
// System.currentTimeMillis() * 1e-3, am.toString());
|
|
||||||
autoMode = am;
|
autoMode = am;
|
||||||
switch (am) {
|
switch (am) {
|
||||||
case BACKWARD:
|
case BACKWARD:
|
||||||
|
|
|
@ -741,12 +741,14 @@ public class DroidComputerPlayer {
|
||||||
case PONDER:
|
case PONDER:
|
||||||
case ANALYZE: {
|
case ANALYZE: {
|
||||||
String[] tokens = tokenize(s);
|
String[] tokens = tokenize(s);
|
||||||
|
int nTok = tokens.length;
|
||||||
|
if (nTok > 0) {
|
||||||
if (tokens[0].equals("info")) {
|
if (tokens[0].equals("info")) {
|
||||||
parseInfoCmd(tokens);
|
parseInfoCmd(tokens);
|
||||||
} else if (tokens[0].equals("bestmove")) {
|
} else if (tokens[0].equals("bestmove")) {
|
||||||
String bestMove = tokens[1];
|
String bestMove = nTok > 1 ? tokens[1] : "";
|
||||||
String nextPonderMoveStr = "";
|
String nextPonderMoveStr = "";
|
||||||
if ((tokens.length >= 4) && (tokens[2].equals("ponder")))
|
if ((nTok >= 4) && (tokens[2].equals("ponder")))
|
||||||
nextPonderMoveStr = tokens[3];
|
nextPonderMoveStr = tokens[3];
|
||||||
Move nextPonderMove = TextIO.UCIstringToMove(nextPonderMoveStr);
|
Move nextPonderMove = TextIO.UCIstringToMove(nextPonderMoveStr);
|
||||||
|
|
||||||
|
@ -757,6 +759,7 @@ public class DroidComputerPlayer {
|
||||||
searchRequest = null;
|
searchRequest = null;
|
||||||
handleIdleState();
|
handleIdleState();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STOP_SEARCH: {
|
case STOP_SEARCH: {
|
||||||
|
|
|
@ -1027,11 +1027,13 @@ public class DroidChessController {
|
||||||
updateGameMode();
|
updateGameMode();
|
||||||
gui.movePlayed(game.prevPos(), res.second, true);
|
gui.movePlayed(game.prevPos(), res.second, true);
|
||||||
listener.clearSearchInfo(searchId);
|
listener.clearSearchInfo(searchId);
|
||||||
|
if (res.first) {
|
||||||
updateComputeThreads();
|
updateComputeThreads();
|
||||||
setSelection();
|
setSelection();
|
||||||
setAnimMove(oldPos, game.getLastMove(), true);
|
setAnimMove(oldPos, game.getLastMove(), true);
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final void repeatLastMove() {
|
public final void repeatLastMove() {
|
||||||
gui.movePlayed(game.prevPos(), game.tree.currentNode.move, true);
|
gui.movePlayed(game.prevPos(), game.tree.currentNode.move, true);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user