rubikscube
college code for finding optimal rubiks cube solutions in java
git clone https://9o.is/git/rubikscube.git
commit 792933e68abbead9edc477de139e56c651538ef3 parent 946ebca372979ff668d0d3a0c75709dd658cd5d8 Author: Jul <jul@9o.is> Date: Mon, 5 Nov 2012 23:45:45 -0500 Tweaked RubiksCubeSolver Diffstat:
| M | src/RubiksCubeSolver.java | | | 10 | +++++----- |
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/RubiksCubeSolver.java b/src/RubiksCubeSolver.java @@ -26,7 +26,7 @@ public class RubiksCubeSolver { public String solve(RubiksCube cube) { PriorityQueue<Node> travq = new PriorityQueue<Node>(MAX_DEPTH*MAX_DEPTH); - travq.add(new Node(cube, null, 0, retrieveCubeHeuristic(cube), -1)); + travq.add(new Node(cube, null, 0, heuristic(cube), -1)); Node current = new Node(null, null, -1, -1, -1); int depth = 0; while(!travq.isEmpty()) { @@ -40,7 +40,7 @@ public class RubiksCubeSolver { } } usedNodes.clear(); - return retrievePathToNode(current); + return path(current); } /** @@ -57,7 +57,7 @@ public class RubiksCubeSolver { childState.rotate(i + 1, face); if(!usedNodes.contains(childState)) { int childCost = node.cost + 1; - int heuristic = retrieveCubeHeuristic(childState); + int heuristic = heuristic(childState); int actionId = 6*i + face.toInt(); children.add(new Node(childState, node, childCost, heuristic, actionId)); } @@ -72,7 +72,7 @@ public class RubiksCubeSolver { * @param node The node to start from. * @return The string sequence of moves */ - private String retrievePathToNode(Node node) { + private String path(Node node) { String path = ""; Stack<String> actions = new Stack<String>(); Node traverser = node; @@ -91,7 +91,7 @@ public class RubiksCubeSolver { return color + ((int)action / 6) +1; } - private int retrieveCubeHeuristic(RubiksCube cube) { + private int heuristic(RubiksCube cube) { RubiksState state = cube.getState(); int corners = table.getCorners()[state.getCorners().hashState()];