ZZ Solver

Musturd

Regular
Joined
Mar 3, 2008
Messages
247
WCA ID
2009KASE01
YouTube
Visit Channel
My ZZ Solver is finally complete! (sort of) (coded in Java)
It is still slower than I'd like it to be, but it is working!

There are currently 2 main things I would like help with:
Speeding up the solver: I need my solver to be faster. I originally coded my solver using ArrayLists, and I originally though that once I changed the ArrayLists to arrays the code would speed up. It did speed up, but not as much as I would have liked. I don't know how else I can alter my code in order to dramatically increase performance. If there is not really anything Java-wise that could be done to really increase the speed than I would like some ideas as to how I can narrow down my search for each of the individual steps.

Stepping through the BL pair: My solver checks if an invariant has been reached by checking all of the previous invariants to make sure that each is still true. For example: If the computer found a way to solve the BR pair but in it's solution left the cube without a cross, it did not REALLY solve the BR pair. After the computer reached the cross invariant it needs to be solved at every other step in the solution. The BL pair is special, however, because I had to narrow down the search for the BL pair. Unfortunately, this means that it will not always find the optimal solution for the BL pair. I added an intermediate step, telling the computer to first put the BL edge on the top layer before trying the solve the BL pair. This step reduces the maximum move count to 9 (I believe, I don't have any proof other than the fact that I haven't seen it reach 10 moves). In my step through code, I check the first invariant that is not true and solve to that invariant. Unfortunately, my intermediate step gets teated as an invariant. Thus, whenever the BL pair is solved the intermediate step is not, and the computer solved the intermediate step, un-solving the BL pair. I was forced to skip this step. I want to know how I can get around skipping this step.
^^This is a lot more confusing to explain than I though it would be, so please ask questions and I will try to answer them.


Features:
  • Controllable cube with hi-games.net controls
  • Solves the whole cube using the (or my) ZZ method
  • Solves individual steps using the (or my) ZZ method
  • You can solve certain steps and have the computer solve others

To Do:
  • Speed up solver
  • Add an option to go back to a previous invariant that was reached.
  • Add an option to step through solve forwards and backwards at your own pace using the left and right arrow keys
  • Add notification upon successful solve
  • Perhaps change graphics to CubeExplorer style 2D or possibly 3D
  • Improve UI -- a lot
  • Maybe add options for other LLs
  • Maybe add options for other methods
  • Make it an applet

Known Bugs:
  • Will usually take a very very long time to solve the BL pair as an individual step (if you plan on stepping through the solve, make sure you have almost solved the BL Pair before you ask the computer to solve it)
  • Still a little slow at solving BL and FL pairs

Instructions:
Keep all files in the same directory.
You will start of with a solved Rubik's Cube with the top stickers on the top of the screen, left stickers all the way to the left, front stickers right of the left ones, right stickers right of the front stickers, and back stickers right of the right stickers. Imagine that the cube was unwrapped, thus the stickers on the left of the back face correspond with the RIGHT face and the stickers on the right of the back face correspond with the LEFT face. If you ask the computer to solve the cube the program will seem to hang until it finds the solution (which could take several minutes), then the cube will animate and solve itself stating the step that it's on in the bottom-right corner of the screen. If you expect the computer to help you, solve the cube in this order: EO, Cross, BL pair, FL pair, BR pair, FR pair, OLL, PLL.

If you just double-click on the jar file (not recommended):
If you ask the computer to solve the cube the program will seem to hang until it finds the solution (which could take several minutes), then the cube will animate and solve itself stating the step that it's on in the bottom-right corner of the screen. If you turn any of the faces of the cube while it is solving it will stop solving at that point and you will need to again wait for the computer to solve the next step or the rest of the steps before continuing with the automated solving.

If you run the file in the command prompt/shell (recommended):
In Windows: go to search/run in the start menu and type "cmd" (without quotes) and open up the command prompt. Go to the directory where you saved the jar file by typing "cd C:\folder\folder" (without the quotes where folder is the name of the folder of the jar file. Then type "java -jar ZZSolver.jar" (without the quotes).
In Linux/Mac: <Can someone write this for me, I don't know how to do it>

If you ask the computer to solve the cube the window will seem to hang until it finds the solution (which could take several minutes), but the command prompt will show you where it currently is in the solution. Invariants 0-6 are: EO, Cross, Bring BL edge to top, BL pair, FL pair, BR pair, FR pair respectively. Then the cube will animate and solve itself stating the step that it's on in the bottom-right corner of the screen. If you turn any of the faces of the cube while it is solving it will stop solving at that point and you will need to again wait for the computer to solve the next step or the rest of the steps before continuing with the automated solving.

Warning:
Do not ruin EO (do single F, B, B', F' turns) in your solving the next step and expect the computer to be okay. It will first solve EO, possibly ruining where you were in your solve.

Controls:
(any Letter without a prime (') is clockwise, with a prime is counter-clockwise)
R = 'i'
R' = 'k'
L = 'd'
L' = 'e'
U = 'j'
U' = 'f'
D = 's'
D' = 'l'
F = 'h'
F' = 'g'
B = 'w'
B' = 'o'
the 'z' key scrambles
the '4' key solves/does the next step in the solvee
the '5' key solves/does the entire cube

DOWNLOAD:
Stable:
v1.0 jar src
v1.1 jar src

If you have any comments/questions/concerns/bug reports/suggestions, please post here. Also, please look at my source code if you are a proficient coder and maybe offer some suggestions.

Thanks.

CHANGES:
  • Fixed: Doesn't step through whole solve
  • Fixed: Forgot to add ability to solved OLL / PLL in the step through mode
  • Cleaned up source code a little bit
 
Last edited:
I get the output:
Code:
C:\Documents and Settings\Duncks\Desktop>java -jar ZZSolver.jar
File not found
Err!
java.lang.NullPointerException
        at RubiksCube.loadLLs(RubiksCube.java:172)
        at RubiksCube.<init>(RubiksCube.java:165)
        at Solver.<init>(Solver.java:79)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at JComponentWithEvents.newInstance(JComponentWithEvents.java:439)
        at JComponentWithEvents.launch(JComponentWithEvents.java:738)
        at Solver.main(Solver.java:239)
Err!
java.lang.NullPointerException
        at JComponentWithEvents.launch(JComponentWithEvents.java:739)
        at Solver.main(Solver.java:239)
 
I got the same error running the jar, but had some luck with the source. However, the solver seems to get stuck after the second F2L pair: Here's a trace of my console output>

Code:
F' U2 D F' B2 R' B2 D' U R F' L' U2 L' F2 L' U R' F2 R' In moveToInvariant 0
   maxMoves = 0 1 2 3 4   solved!
R U R F 

In moveToInvariant 1
   maxMoves = 0 1 2 3 4 5   solved!
U' R2 U2 F2 L 

In moveToInvariant 3
   maxMoves = 0 1 2 3 4 5 6 7   solved!
R L2 U2 L U2 R' L2 

In moveToInvariant 3
   maxMoves = 0   solved!


In moveToInvariant 3
   maxMoves = 0   solved!


In moveToInvariant 3
   maxMoves = 0   solved!


In moveToInvariant 3
   maxMoves = 0   solved!



Also, just a little nitpick. Solving with the cross isn't technically ZZ. That would be a ZZ-Fridrich Hybrid :p

EDIT: If you're looking for a nice 3D applet, have a look at Cube Twister. Werner Randelshofer has kindly released the source code and a nice JavaDoc API to make it easy to add into your program. It also contains the Kociemba two-phase algorithm which would certainly speed up the solver.
 
Last edited:
I get the output:
Code:
C:\Documents and Settings\Duncks\Desktop>java -jar ZZSolver.jar
File not found
Err!
java.lang.NullPointerException
        at RubiksCube.loadLLs(RubiksCube.java:172)
        at RubiksCube.<init>(RubiksCube.java:165)
        at Solver.<init>(Solver.java:79)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at JComponentWithEvents.newInstance(JComponentWithEvents.java:439)
        at JComponentWithEvents.launch(JComponentWithEvents.java:738)
        at Solver.main(Solver.java:239)
Err!
java.lang.NullPointerException
        at JComponentWithEvents.launch(JComponentWithEvents.java:739)
        at Solver.main(Solver.java:239)

I got the jar file wrong, sorry about that, I'll update it.
It should work now
 
Last edited:
I got the same error running the jar, but had some luck with the source. However, the solver seems to get stuck after the second F2L pair: Here's a trace of my console output>

Code:
F' U2 D F' B2 R' B2 D' U R F' L' U2 L' F2 L' U R' F2 R' In moveToInvariant 0
   maxMoves = 0 1 2 3 4   solved!
R U R F 

In moveToInvariant 1
   maxMoves = 0 1 2 3 4 5   solved!
U' R2 U2 F2 L 

In moveToInvariant 3
   maxMoves = 0 1 2 3 4 5 6 7   solved!
R L2 U2 L U2 R' L2 

In moveToInvariant 3
   maxMoves = 0   solved!


In moveToInvariant 3
   maxMoves = 0   solved!


In moveToInvariant 3
   maxMoves = 0   solved!


In moveToInvariant 3
   maxMoves = 0   solved!



Also, just a little nitpick. Solving with the cross isn't technically ZZ. That would be a ZZ-Fridrich Hybrid :p
Are you stepping through?
I guess my stepping is broken EDIT: it works now
Try pressing '5'.

AND
Like I said, my ZZ :p
EDIT:Maybe I didn't say it
 
Last edited:
EDIT: If you're looking for a nice 3D applet, have a look at Cube Twister. Werner Randelshofer has kindly released the source code and a nice JavaDoc API to make it easy to add into your program. It also contains the Kociemba two-phase algorithm which would certainly speed up the solver.

Hi, can anyone explain to me how this API works? I'm not a programmer nor a webdesigner, but I think the potential of using this as a webbased solver with an animated cube could be rather useful.
 
Back
Top