mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-13 01:22:41 +01:00
DroidFish: Made the move variation up/down functions work also when the the current position is not a branch point in the game tree.
This commit is contained in:
@@ -2449,8 +2449,10 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS);
|
lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS);
|
||||||
}
|
}
|
||||||
lst.add(getString(R.string.truncate_gametree)); actions.add(REMOVE_SUBTREE);
|
lst.add(getString(R.string.truncate_gametree)); actions.add(REMOVE_SUBTREE);
|
||||||
if (ctrl.numVariations() > 1) {
|
if (ctrl.canMoveVariationUp()) {
|
||||||
lst.add(getString(R.string.move_var_up)); actions.add(MOVE_VAR_UP);
|
lst.add(getString(R.string.move_var_up)); actions.add(MOVE_VAR_UP);
|
||||||
|
}
|
||||||
|
if (ctrl.canMoveVariationDown()) {
|
||||||
lst.add(getString(R.string.move_var_down)); actions.add(MOVE_VAR_DOWN);
|
lst.add(getString(R.string.move_var_down)); actions.add(MOVE_VAR_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -477,6 +477,16 @@ public class DroidChessController {
|
|||||||
return game.numVariations();
|
return game.numVariations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return true if the current variation can be moved closer to the main-line. */
|
||||||
|
public final synchronized boolean canMoveVariationUp() {
|
||||||
|
return game.canMoveVariation(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true if the current variation can be moved farther away from the main-line. */
|
||||||
|
public final synchronized boolean canMoveVariationDown() {
|
||||||
|
return game.canMoveVariation(1);
|
||||||
|
}
|
||||||
|
|
||||||
/** Get current variation in current position. */
|
/** Get current variation in current position. */
|
||||||
public final synchronized int currVariation() {
|
public final synchronized int currVariation() {
|
||||||
return game.currVariation();
|
return game.currVariation();
|
||||||
@@ -504,7 +514,8 @@ public class DroidChessController {
|
|||||||
|
|
||||||
/** Move current variation up/down in the game tree. */
|
/** Move current variation up/down in the game tree. */
|
||||||
public final synchronized void moveVariation(int delta) {
|
public final synchronized void moveVariation(int delta) {
|
||||||
if (game.numVariations() > 1) {
|
if (((delta > 0) && canMoveVariationDown()) ||
|
||||||
|
((delta < 0) && canMoveVariationUp())) {
|
||||||
game.moveVariation(delta);
|
game.moveVariation(delta);
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,20 +289,55 @@ public class Game {
|
|||||||
|
|
||||||
/** Move current variation up/down in the game tree. */
|
/** Move current variation up/down in the game tree. */
|
||||||
public final void moveVariation(int delta) {
|
public final void moveVariation(int delta) {
|
||||||
if (tree.currentNode == tree.rootNode)
|
int nBack = 0;
|
||||||
return;
|
boolean found = false;
|
||||||
tree.goBack();
|
while (tree.currentNode != tree.rootNode) {
|
||||||
int varNo = tree.currentNode.defaultChild;
|
tree.goBack();
|
||||||
int nChildren = tree.variations().size();
|
nBack++;
|
||||||
int newPos = varNo + delta;
|
if (((delta < 0) && tree.currentNode.defaultChild > 0) ||
|
||||||
newPos = Math.max(newPos, 0);
|
((delta > 0) && tree.currentNode.defaultChild < tree.variations().size() - 1)) {
|
||||||
newPos = Math.min(newPos, nChildren - 1);
|
found = true;
|
||||||
tree.reorderVariation(varNo, newPos);
|
break;
|
||||||
tree.goForward(newPos);
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
int varNo = tree.currentNode.defaultChild;
|
||||||
|
int nChildren = tree.variations().size();
|
||||||
|
int newPos = varNo + delta;
|
||||||
|
newPos = Math.max(newPos, 0);
|
||||||
|
newPos = Math.min(newPos, nChildren - 1);
|
||||||
|
tree.reorderVariation(varNo, newPos);
|
||||||
|
tree.goForward(newPos);
|
||||||
|
nBack--;
|
||||||
|
}
|
||||||
|
while (nBack > 0) {
|
||||||
|
tree.goForward(-1);
|
||||||
|
nBack--;
|
||||||
|
}
|
||||||
pendingDrawOffer = false;
|
pendingDrawOffer = false;
|
||||||
updateTimeControl(true);
|
updateTimeControl(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return true if the current variation can be moved up/down. */
|
||||||
|
public final boolean canMoveVariation(int delta) {
|
||||||
|
int nBack = 0;
|
||||||
|
boolean found = false;
|
||||||
|
while (tree.currentNode != tree.rootNode) {
|
||||||
|
tree.goBack();
|
||||||
|
nBack++;
|
||||||
|
if (((delta < 0) && tree.currentNode.defaultChild > 0) ||
|
||||||
|
((delta > 0) && tree.currentNode.defaultChild < tree.variations().size() - 1)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (nBack > 0) {
|
||||||
|
tree.goForward(-1);
|
||||||
|
nBack--;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
/** Delete whole game sub-tree rooted at current position. */
|
/** Delete whole game sub-tree rooted at current position. */
|
||||||
public final void removeSubTree() {
|
public final void removeSubTree() {
|
||||||
if (getLastMove() != null) {
|
if (getLastMove() != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user