DroidFish: Added option to not keep variations in the move list.

This commit is contained in:
Peter Osterlund 2012-09-29 14:17:25 +00:00
parent 4541e83cf0
commit 03342fb46b
7 changed files with 66 additions and 15 deletions

View File

@ -279,6 +279,8 @@ you are not actively using the program.\
<string name="prefs_scrollSensitivity_summary">Scrolling speed for game navigation</string> <string name="prefs_scrollSensitivity_summary">Scrolling speed for game navigation</string>
<string name="prefs_invertScrollDirection_title">Invert Scroll Direction</string> <string name="prefs_invertScrollDirection_title">Invert Scroll Direction</string>
<string name="prefs_invertScrollDirection_summary">Enable this if you think scrolling moves in the wrong direction</string> <string name="prefs_invertScrollDirection_summary">Enable this if you think scrolling moves in the wrong direction</string>
<string name="prefs_discardVariations_title">Discard variations</string>
<string name="prefs_discardVariations_summary">Discard non-mainline moves from move list</string>
<string name="prefs_leftHanded_title">Left-handed mode</string> <string name="prefs_leftHanded_title">Left-handed mode</string>
<string name="prefs_leftHanded_summary">Controls on left side in landscape mode</string> <string name="prefs_leftHanded_summary">Controls on left side in landscape mode</string>
<string name="prefs_squareSelectType_title">Square selection</string> <string name="prefs_squareSelectType_title">Square selection</string>

View File

@ -496,7 +496,13 @@
android:summary="@string/prefs_invertScrollDirection_summary" android:summary="@string/prefs_invertScrollDirection_summary"
android:defaultValue="false"> android:defaultValue="false">
</CheckBoxPreference> </CheckBoxPreference>
</PreferenceCategory> <CheckBoxPreference
android:key="discardVariations"
android:title="@string/prefs_discardVariations_title"
android:summary="@string/prefs_discardVariations_summary"
android:defaultValue="false">
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/prefs_other"> android:title="@string/prefs_other">
<PreferenceScreen <PreferenceScreen

View File

@ -170,6 +170,7 @@ public class DroidFish extends Activity implements GUIInterface {
private boolean boardFlipped; private boolean boardFlipped;
private boolean autoSwapSides; private boolean autoSwapSides;
private boolean playerNameFlip; private boolean playerNameFlip;
private boolean discardVariations;
private TextView status; private TextView status;
private ScrollView moveListScroll; private ScrollView moveListScroll;
@ -829,6 +830,7 @@ public class DroidFish extends Activity implements GUIInterface {
scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2")); scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2"));
invertScrollDirection = settings.getBoolean("invertScrollDirection", false); invertScrollDirection = settings.getBoolean("invertScrollDirection", false);
discardVariations = settings.getBoolean("discardVariations", false);
boolean fullScreenMode = settings.getBoolean("fullScreenMode", false); boolean fullScreenMode = settings.getBoolean("fullScreenMode", false);
Util.setFullScreenMode(this, fullScreenMode); Util.setFullScreenMode(this, fullScreenMode);
useWakeLock = settings.getBoolean("wakeLock", false); useWakeLock = settings.getBoolean("wakeLock", false);
@ -1419,6 +1421,11 @@ public class DroidFish extends Activity implements GUIInterface {
return playerName; return playerName;
} }
@Override
public boolean discardVariations() {
return discardVariations;
}
/** Report a move made that is a candidate for GUI animation. */ /** Report a move made that is a candidate for GUI animation. */
public void setAnimMove(Position sourcePos, Move move, boolean forward) { public void setAnimMove(Position sourcePos, Move move, boolean forward) {
if (animateMoves && (move != null)) if (animateMoves && (move != null))

View File

@ -100,4 +100,7 @@ public interface GUIInterface {
/** Get the default player name. */ /** Get the default player name. */
public String playerName(); public String playerName();
/** Return true if only main-line moves are to be kept. */
public boolean discardVariations();
} }

View File

@ -834,8 +834,14 @@ public class DroidChessController {
boolean gamePaused = !gameMode.clocksActive() || (humansTurn() && guiPaused); boolean gamePaused = !gameMode.clocksActive() || (humansTurn() && guiPaused);
game.setGamePaused(gamePaused); game.setGamePaused(gamePaused);
updateRemainingTime(); updateRemainingTime();
boolean addFirst = gameMode.clocksActive(); Game.AddMoveBehavior amb;
game.setAddFirst(addFirst); if (gui.discardVariations())
amb = Game.AddMoveBehavior.REPLACE;
else if (gameMode.clocksActive())
amb = Game.AddMoveBehavior.ADD_FIRST;
else
amb = Game.AddMoveBehavior.ADD_LAST;
game.setAddFirst(amb);
} }
} }

View File

@ -34,7 +34,7 @@ public class Game {
TimeControl timeController; TimeControl timeController;
private boolean gamePaused; private boolean gamePaused;
/** If true, add new moves as mainline moves. */ /** If true, add new moves as mainline moves. */
private boolean addFirst; private AddMoveBehavior addMoveBehavior;
PgnToken.PgnTokenReceiver gameTextListener; PgnToken.PgnTokenReceiver gameTextListener;
@ -61,9 +61,19 @@ public class Game {
} }
} }
/** Controls behavior when a new move is added to the game.*/
public static enum AddMoveBehavior {
/** Add the new move first in the list of variations. */
ADD_FIRST,
/** Add the new move last in the list of variations. */
ADD_LAST,
/** Remove all variations not matching the new move. */
REPLACE
};
/** Set whether new moves are entered as mainline moves or variations. */ /** Set whether new moves are entered as mainline moves or variations. */
public final void setAddFirst(boolean addFirst) { public final void setAddFirst(AddMoveBehavior amb) {
this.addFirst = addFirst; addMoveBehavior = amb;
} }
/** Sets start position and discards the whole game tree. */ /** Sets start position and discards the whole game tree. */
@ -137,7 +147,7 @@ public class Game {
} }
private final void addToGameTree(Move m, String playerAction) { private final void addToGameTree(Move m, String playerAction) {
if (m.equals(new Move(0, 0, 0))) { // Don't create more than one null move at a node if (m.equals(new Move(0, 0, 0))) { // Don't create more than one game-ending move at a node
List<Move> varMoves = tree.variations(); List<Move> varMoves = tree.variations();
for (int i = varMoves.size() - 1; i >= 0; i--) { for (int i = varMoves.size() - 1; i >= 0; i--) {
if (varMoves.get(i).equals(m)) { if (varMoves.get(i).equals(m)) {
@ -146,20 +156,38 @@ public class Game {
} }
} }
List<Move> varMoves = tree.variations();
boolean movePresent = false; boolean movePresent = false;
int varNo; int varNo;
for (varNo = 0; varNo < varMoves.size(); varNo++) { {
if (varMoves.get(varNo).equals(m)) { ArrayList<Move> varMoves = tree.variations();
movePresent = true; int nVars = varMoves.size();
break; if (addMoveBehavior == AddMoveBehavior.REPLACE) {
boolean modified = false;
for (int i = nVars-1; i >= 0; i--) {
if (!m.equals(varMoves.get(i))) {
tree.deleteVariation(i);
modified = true;
}
}
if (modified) {
varMoves = tree.variations();
nVars = varMoves.size();
}
}
for (varNo = 0; varNo < nVars; varNo++) {
if (varMoves.get(varNo).equals(m)) {
movePresent = true;
break;
}
} }
} }
if (!movePresent) { if (!movePresent) {
String moveStr = TextIO.moveToUCIString(m); String moveStr = TextIO.moveToUCIString(m);
varNo = tree.addMove(moveStr, playerAction, 0, "", ""); varNo = tree.addMove(moveStr, playerAction, 0, "", "");
} }
int newPos = addFirst ? 0 : varNo; int newPos = 0;
if (addMoveBehavior == AddMoveBehavior.ADD_LAST)
newPos = varNo;
tree.reorderVariation(varNo, newPos); tree.reorderVariation(varNo, newPos);
tree.goForward(newPos); tree.goForward(newPos);
int remaining = timeController.moveMade(System.currentTimeMillis(), !gamePaused); int remaining = timeController.moveMade(System.currentTimeMillis(), !gamePaused);

View File

@ -96,9 +96,8 @@ public class GameTree {
} }
private final void updateListener() { private final void updateListener() {
if (gameStateListener != null) { if (gameStateListener != null)
gameStateListener.clear(); gameStateListener.clear();
}
} }
/** PngTokenReceiver implementation that generates plain text PGN data. */ /** PngTokenReceiver implementation that generates plain text PGN data. */