From 03342fb46b19010c801c75cc544ff732496b889e Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 29 Sep 2012 14:17:25 +0000 Subject: [PATCH] DroidFish: Added option to not keep variations in the move list. --- DroidFish/res/values/strings.xml | 2 + DroidFish/res/xml/preferences.xml | 8 +++- .../src/org/petero/droidfish/DroidFish.java | 7 +++ .../org/petero/droidfish/GUIInterface.java | 3 ++ .../gamelogic/DroidChessController.java | 10 +++- .../org/petero/droidfish/gamelogic/Game.java | 48 +++++++++++++++---- .../petero/droidfish/gamelogic/GameTree.java | 3 +- 7 files changed, 66 insertions(+), 15 deletions(-) diff --git a/DroidFish/res/values/strings.xml b/DroidFish/res/values/strings.xml index ed93399..d7f8454 100644 --- a/DroidFish/res/values/strings.xml +++ b/DroidFish/res/values/strings.xml @@ -279,6 +279,8 @@ you are not actively using the program.\ Scrolling speed for game navigation Invert Scroll Direction Enable this if you think scrolling moves in the wrong direction + Discard variations + Discard non-mainline moves from move list Left-handed mode Controls on left side in landscape mode Square selection diff --git a/DroidFish/res/xml/preferences.xml b/DroidFish/res/xml/preferences.xml index fcac8df..b72bde3 100644 --- a/DroidFish/res/xml/preferences.xml +++ b/DroidFish/res/xml/preferences.xml @@ -496,7 +496,13 @@ android:summary="@string/prefs_invertScrollDirection_summary" android:defaultValue="false"> - + + + varMoves = tree.variations(); for (int i = varMoves.size() - 1; i >= 0; i--) { if (varMoves.get(i).equals(m)) { @@ -146,20 +156,38 @@ public class Game { } } - List varMoves = tree.variations(); boolean movePresent = false; int varNo; - for (varNo = 0; varNo < varMoves.size(); varNo++) { - if (varMoves.get(varNo).equals(m)) { - movePresent = true; - break; + { + ArrayList varMoves = tree.variations(); + int nVars = varMoves.size(); + 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) { String moveStr = TextIO.moveToUCIString(m); 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.goForward(newPos); int remaining = timeController.moveMade(System.currentTimeMillis(), !gamePaused); diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/GameTree.java b/DroidFish/src/org/petero/droidfish/gamelogic/GameTree.java index d54d978..e6839ac 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/GameTree.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/GameTree.java @@ -96,9 +96,8 @@ public class GameTree { } private final void updateListener() { - if (gameStateListener != null) { + if (gameStateListener != null) gameStateListener.clear(); - } } /** PngTokenReceiver implementation that generates plain text PGN data. */