A Python Rubik’s Cube Solver: Part 1

Finally, I was able to get my own GitHub account, which you can find at https://github.com/mattiagiuri, and my first repository is one containing my latest project: a Rubik’s cube solver in Python.

If you want, you can check it out and have fun with your Rubik’s cube solving tasks.

How does it work? First, I created a class that describes all the single moves, intended as clockwise or anticlockwise rotation of a face. Then, there is another class which employs these moves to solve the cube using the standard algorithms I implemented in Python.

Also, there is a cube encoder which creates all the coordinates for the edges and vertexes of the cube.

How To Write A Move

Now let’s see the idea behind writing a move.

As you can see, I manually extract the groups of three squares that move during a rotation. The rotation of the faces (np.rot90) occurs because, in order to perform a proper exchange, I need to orient the groups of three squares in the same way. After that, I make the right exchanges and then bring them back to their original orientation.

The next part is a manual variation of all the coordinates of edges and vertexes.

Finally, I check whether the process has been completed successfully or not and add the move to the sequence that solves the cube.

Scroll to top