public static void main(String[] args) { // AI a = new AI(); String input = "exampleinput.txt"; /* * try{ BufferedReader br = new BufferedReader(new * InputStreamReader(System.in)); * System.out.println("Please enter an input filename location: "); * input = br.readLine(); }catch(IOException io){ io.printStackTrace(); * } */ GUI.Threes.readFile(input); GUI.Threes.set(); Moves.storeNext(); Moves.resetNext(); ArrayDeque<String> Res = AStar(GUI.Threes.board, 400); System.out.println(Res.removeFirst()); System.out.println(Res.removeFirst()); Moves.doMove(GUI.Threes.board, Res, true); System.out.println("Final board is"); // GUI.Threes.finalBoard(); while (!Res.isEmpty()) { System.out.print(Res.removeLast()); } System.out.println(); GUI.Threes.readFile(input); GUI.Threes.set(); Moves.resetNext(); recur(GUI.Threes.board, 10); }
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(); }