43444546474849505152
* Moves cards from one pile to another, if the move is valid. */ public boolean move(Pile fromPile, Pile toPile) { int cardsMoved = toPile.moveFrom(fromPile); if (cardsMoved > 0) { moveTracker.addMove(new MoveAction(fromPile, toPile, cardsMoved)); return true; } return false; }
167168169170171172173174175
public boolean hasLastMove() { return !previousMoves.isEmpty(); } public MoveAction getLastMove() { MoveAction lastMove = previousMoves.pop(); nextMoves.push(lastMove); return lastMove; }
177178179180181182183184185
public boolean hasNextMove() { return !nextMoves.isEmpty(); } public MoveAction getNextMove() { MoveAction nextMove = nextMoves.pop(); previousMoves.push(nextMove); return nextMove; }
183184185186187188189190191192193
previousMoves.push(nextMove); return nextMove; } public void addMove(MoveAction move) { MoveAction nextMove = nextMoves.peek(); /* * if new move differs from saved next move, * clear the remaining next moves */ if (move.equals(nextMove)) {