// undo // 从undoQueue中删除并放到redoQueue中 public String undo() { String last = undoQueue.pollLast(); if (last != null) { redoQueue.addLast(last); } return undoQueue.peekLast(); }
void handleWorkUnitComplete(WorkUnit w) { for (int depId : w.getDependencyIds()) { m_missingDependencies.remove(depId); } // slide this new stack frame drop into the right position // (before any other stack frame drops) if ((w.shouldResumeProcedure()) && (m_readyWorkUnits.peekLast() != null) && (m_readyWorkUnits.peekLast().shouldResumeProcedure())) { ArrayDeque<WorkUnit> deque = new ArrayDeque<WorkUnit>(); while ((m_readyWorkUnits.peekLast() != null) && (m_readyWorkUnits.peekLast().shouldResumeProcedure())) { deque.add(m_readyWorkUnits.pollLast()); } deque.add(w); while (deque.size() > 0) m_readyWorkUnits.add(deque.pollLast()); } else { m_readyWorkUnits.add(w); } }
/** pops from current frame */ private Object pop() { return peekFrame.pollLast(); }
private ArrayDeque popFrame() { ArrayDeque frame = frames.pollLast(); peekFrame = frames.peekLast(); return frame; }
private void endStep() { stepStack.pollLast(); }
public static void recur(int[][] board, int z) { int[][] tempBoard = new int[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { tempBoard[i][j] = board[i][j]; } } Moves.storeNext(); // GUI.ThreesGUI gui = new GUI.ThreesGUI(); ArrayDeque<String> finalmoves = new ArrayDeque<String>(); ArrayDeque<String> temp = new ArrayDeque<String>(); LinkedList<Object> temp2 = new LinkedList<Object>(); LinkedList<Object> temp3 = new LinkedList<Object>(); String nextMove = ""; for (int i = 0; i < z; i++) { temp = new ArrayDeque<String>(AStar(tempBoard, 50)); temp.poll(); temp.poll(); tempBoard = GUI.Threes.board.clone(); temp3 = Moves.doMove(tempBoard, temp, false); temp3.poll(); temp3.poll(); int k = 0; boolean gameon = true; while (!temp.isEmpty() && k < 5 && gameon) { nextMove = temp.pollLast(); if (nextMove.equals("L")) { gameon = GUI.Threes.Left(); } else if (nextMove.equals("R")) { gameon = GUI.Threes.Right(); } else if (nextMove.equals("U")) { gameon = GUI.Threes.Up(); } else if (nextMove.equals("D")) { gameon = GUI.Threes.Down(); } else nextMove = "X"; k++; if (!nextMove.equals("X") && gameon) { finalmoves.addFirst(nextMove); Moves.popNext(); } } // tempBoard = GUI.Threes.board.clone(); // if(!nextMove.equals("X")) // finalmoves.addFirst(nextMove); // Moves.popNext(); if (!gameon) { i = z; } } System.out.println("contents of finalmoves"); int movesize = finalmoves.size(); ArrayDeque<String> printemp = new ArrayDeque<String>(finalmoves); for (int i = 0; i < movesize; i++) { System.out.print(printemp.remove()); } System.out.println(); temp2 = Moves.doMove(board, finalmoves, true); System.out.println("heuristic score was: " + temp2.remove(0)); System.out.println("Final score was: " + temp2.remove(0)); GUI.Threes.finalBoard(); System.out.println("Move string was"); while (!temp2.isEmpty()) { System.out.print(temp2.remove()); } System.out.println(); }