Solving the Rubik's cube with Houdini and Python

   444   0   0
User Avatar
Member
15 posts
Joined: Sept. 2016
Offline
Hey all,

I am working on a solution for the Rubik's cube. This is my first project with Python, but it's also a very nice and practical way of learning scripting and VEX.

The project is divided up into different steps:

  1. Create and describe the cube in Houdini.
  2. Import the cube into Python.
  3. Solve the cube in Python.
  4. Visualize the solution in Houdini

In this post, I want to give a brief overview how I am going to realize the steps above.

First of all, I needed to describe the cube in a simple way. Unfortunately, there are a lot of different attributes I need to store on points which reflect the cubies (those are the small cubes in the cube). The orientation, the position, the visible sites, the group (edge, mid, corner) etc.
To describe a cube, I am using points to which I am copying a cube at the end. I am only working on the points and mostly on their orientation and position: (This is the middle layer)
{-1,1,0} - {0,1,0} - {1,1,0}
{-1,0,0} - {0,0,0} - {1,0,0}
{-1,-1,0} - {0,-1,0} - {1,-1,0}
This seems obvious, but I needed to learn a lot about rotation and quaternions (also matrixes) to understand why and how I do the rotation for the 12 different turns.

The Turns:
There are 6 turns and 6 “counter-turns” (clockwise and counterclockwise), each of them are stored under a value 1-12. An array on a “helping point” (which doesn't belong to the cube) is storing the array. The solver checks for the current pos in the array, and if it matches the turn, the turn is going to be executed. At the end of the solver the pos is going to be deleted and a next, random number (turn) is replacing it.
This way, the solver can generate a random position for the cube just generating a random array of x numbers. BUT the same solver can also solve the cube with the correct array! Thats where I need Python

Thistlethwaite:
The first step is done, the cube is described matching my needs, and has a random position after running the solver. The next step is to import the current position of each point into Python, and running a script which will solve it
And there it comes, Dr. Thistlethwaite! His description of a solution for the cube is one which can be easily understood and the coding part for python is really not that hard. For more information, please visit this [www.jaapsch.net] site!

Back to Houdini:
After the final moves are found, a new array is going to describe the turns and the solver is going to execute them.


Where I am now?
I have done step 1 to describe the cube and I have understood all the math needed for the cube solver. I have an understanding of Python for being able to code the needed solver. Now, I need to store the point values from Houdini in a Python dictionary and to use it as a starting position for finding the solution. I am preferring a depth first search for the code, but it may vary depending on the results.

I will be back as soon as I have more to present!
Gyula
Check out my profile: https://vimeo.com/user750491 [vimeo.com] Feel free to leave a comment if you like a video :)
  • Quick Links