go_away

### Author Topic: How do you program a rubiks cube algorithm?  (Read 18617 times)

0 Members and 1 Guest are viewing this topic.

#### S. Karim

• Robot Overlord
• Posts: 155
##### How do you program a rubiks cube algorithm?
« on: May 24, 2008, 12:12:57 PM »
First of all let me start of by saying I can solve a rubiks cube in about 4 different methods and my faster time is 30.01 seconds. Therefore, dont hesitate to use rubiks notation or terminology with me if you feel its necessary.

Second, I have light sensors, line-following sensors (probably can be used to detect shade of color), a camera (which can only detect 3 colors at a time, and the color models can be changed dynamically).

So how do I go about programming a rubiks solving machine? Ive seen a whole bunch online but cant seem to find how they programmed it. The building is no problem, I have tons of motors/servos but I just dont wanna build it until I know I can program it.

Thanks for the help.
« Last Edit: May 24, 2008, 06:42:31 PM by S. Karim »

#### SixRingz

• Full Member
• Posts: 76
• Bit's and pc's = Robot.
##### Re: How do you program a rubiks cube algorithm?
« Reply #1 on: May 24, 2008, 07:13:18 PM »
Hats off to your great solving time!    It takes me about 2-5 minutes to solve one depending on the initial shuffle...
Well, to build a rubik solver isn't trivial at all. I would be happy just to make the rotations of the cube working with servos and all. But say you have that, you could maybe hook up mirrors or something to get your camera to get view of all sides. Some imaging processing on that to get the color of all the pieces and then "just" apply your favourite rubik method and -presto! your cube solver is done. Not that hard now that I gave you the full solution right?!?
Grounding things properly means burying them in the backyard...

#### S. Karim

• Robot Overlord
• Posts: 155
##### Re: How do you program a rubiks cube algorithm?
« Reply #2 on: May 24, 2008, 09:53:57 PM »
Hats off to your great solving time!    It takes me about 2-5 minutes to solve one depending on the initial shuffle...
Well, to build a rubik solver isn't trivial at all. I would be happy just to make the rotations of the cube working with servos and all. But say you have that, you could maybe hook up mirrors or something to get your camera to get view of all sides. Some imaging processing on that to get the color of all the pieces and then "just" apply your favourite rubik method and -presto! your cube solver is done. Not that hard now that I gave you the full solution right?!?
Love the enthusiasm, but its not that simple. Especially if I'm making my own solver from scratch.

Sure, I can process the image and keep numbers to track every corner and edge, but I cant "just" apply my favorite method and presto! To get what I'm talking about, why dont you come up with a specific solution for how to program it in depth and you'll realize how tough it is.

I can keep track of 54 colors, but I have no clue how to tell the robot what colors match what and where they belong .

#### pomprocker

• Supreme Robot
• Posts: 1,431
• Sorry miss, I was giving myself an oil-job.
##### Re: How do you program a rubiks cube algorithm?
« Reply #3 on: May 24, 2008, 11:26:52 PM »
how about the wavefront pathfinding type algorithm using a map?

#### S. Karim

• Robot Overlord
• Posts: 155
##### Re: How do you program a rubiks cube algorithm?
« Reply #4 on: May 25, 2008, 10:38:46 AM »
how about the wavefront pathfinding type algorithm using a map?
Could you elaborate?

#### Brandon121233

• Contest Winner
• Supreme Robot
• Posts: 320
• "Genius is %1 inspiration and %99 perspiration"
##### Re: How do you program a rubiks cube algorithm?
« Reply #5 on: May 25, 2008, 11:08:05 AM »
I have seen a couple videos of rubiks cube solving machines and they all usually spin the cube in every direction first to catalog the orientation of all the colors, from there you wouldnt need any more feedback cause you could use something like this http://www.wrongway.org/cube/solve.html and take the source code from it http://www.wrongway.org/?rubiksource so from there it would just be a matter of breaking that up into executable rotate and twist functions.
Hell, there are no rules here—we're
trying to accomplish something.

—Thomas Edison

#### JesseWelling

• Expert Roboticist
• Supreme Robot
• Posts: 707
• Only You Can Build A Robot!
##### Re: How do you program a rubiks cube algorithm?
« Reply #6 on: May 25, 2008, 12:34:18 PM »
I'm imagining a breadth first search as it has been proven that any random Rubiks cube can be solved in 25 moves or less by the time you get to your 26th level of the tree you should have a solution. Assuming this is a 3X3X3 cube:

One move can result in a 'disk' (cross section?) to rotate into 3 new positions.
There are effectively 9 'disks'.
There are 3*9 moves to expand off of every new node.
So for every move made there are 26 new possible moves (Why would you want search a 'undo' and create an infinte cycle.... bleh  )
so that's only 27+26^24 = 9106685769537214956799814036095003 combinations you would have to search to find the optimal solution

But like my comment before, if you could recognize configurations you have already been and halt the search of that part of the tree there (if you have already been there there was already a shorter path to that point, so if that leads you to a solution, you are already searching that path) I'm sure the number of un-searched limbs will dwindle quickly....

does this make sense to any one else

« Last Edit: May 25, 2008, 12:35:45 PM by JesseWelling »

#### S. Karim

• Robot Overlord
• Posts: 155
##### Re: How do you program a rubiks cube algorithm?
« Reply #7 on: May 25, 2008, 07:48:24 PM »
I'm imagining a breadth first search as it has been proven that any random Rubiks cube can be solved in 25 moves or less by the time you get to your 26th level of the tree you should have a solution. Assuming this is a 3X3X3 cube:

One move can result in a 'disk' (cross section?) to rotate into 3 new positions.
There are effectively 9 'disks'.
There are 3*9 moves to expand off of every new node.
So for every move made there are 26 new possible moves (Why would you want search a 'undo' and create an infinte cycle.... bleh  )
so that's only 27+26^24 = 9106685769537214956799814036095003 combinations you would have to search to find the optimal solution

But like my comment before, if you could recognize configurations you have already been and halt the search of that part of the tree there (if you have already been there there was already a shorter path to that point, so if that leads you to a solution, you are already searching that path) I'm sure the number of un-searched limbs will dwindle quickly....

does this make sense to any one else

Makes perfect sense...but I just have no clue how to do that using this program called Interactive C that I'm using to program.
« Last Edit: May 25, 2008, 07:49:21 PM by S. Karim »

#### JesseWelling

• Expert Roboticist
• Supreme Robot
• Posts: 707
• Only You Can Build A Robot!
##### Re: How do you program a rubiks cube algorithm?
« Reply #8 on: May 26, 2008, 12:00:03 AM »
If you are going to do this proper like, you will want to use proper horse power to crunch away at the tree, so you want to program I/O on a MCU and then have your main brain solving on a PC and just send serial commands like turn this, twist that. You can bet your bottom dollar that an MCU doesn't have enough memory to accomplish what I just proposed.

If you are going to program in C I suggest you make a decent structure to hold the 'state' of the cube. Since there could be potentially a lot of these stored values I suggest you use an array of 8 bit unsigned integers like this:
Code: [Select]
` #ifndef RUBIK_H #define RUBIK_H   typedef struct {    uint8_t cube [3][3][6]; }RubikCube_T;   typedef enum {    FRONT=0,    BACK,    LEFT,    RIGHT,    TOP,    BOTTOM }RubikSide_T; typedef enum{    GREEN=0,    YELLOW,    BLUE,    RED,    WHITE,    ORANGE // Is that right?}RubikColor_T; #endif`
Then you have to go about defining the rules to make a move in a function and come up with a way to portray that movement. Always a good thing to do is to make a function that returns all possible moves, and then weed out the configurations you may have seen before.

#### S. Karim

• Robot Overlord
• Posts: 155
##### Re: How do you program a rubiks cube algorithm?
« Reply #9 on: May 26, 2008, 12:38:27 PM »
Very little of that went through my head. I'm not coding with full blown C, but a basic version of it. I have arrays, variables, definitions, functions, etc. The turning functions are easy, I just need something to return a solve algorithm

#### Webbot

• Expert Roboticist
• Supreme Robot
• Posts: 2,166
##### Re: How do you program a rubiks cube algorithm?
« Reply #10 on: May 26, 2008, 12:49:27 PM »
Google will give you lots of examples including the 'how to solve the Rubik cube' algorithm. As well as concrete examples - e.g. the Lego Mindstorms Rubik Cube solver.

If you just wish to find how to 'solve' it then there are lots of booklets - probably available from Amazon and the like
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

#### S. Karim

• Robot Overlord
• Posts: 155
##### Re: How do you program a rubiks cube algorithm?
« Reply #11 on: May 26, 2008, 12:56:16 PM »
Google will give you lots of examples including the 'how to solve the Rubik cube' algorithm. As well as concrete examples - e.g. the Lego Mindstorms Rubik Cube solver.

If you just wish to find how to 'solve' it then there are lots of booklets - probably available from Amazon and the like
No no I dont need the algorithm on how to solve, I need the the computer to find an algorithm. I can look at the cube and know what goes where, my problem is telling the processor to figure out how to do that.

#### awally88

• Robot Overlord
• Posts: 212
##### Re: How do you program a rubiks cube algorithm?
« Reply #12 on: June 02, 2008, 01:32:02 AM »
Hey,

My made a program which did this. His was only a digital cube rather than an actual mechanical solution but this is how it worked.

He made an array for each face. This could be input directly or had a cool method of inputting turns to randomise it by hand.
He then made general functions to change a selected face backwards or forwards (note L'=3L)
Then the program would solve the cube constrained to the different methods of solving.

There was also a random few turns added in every 100 or so turns to get out of infinate loops which sometimes occurred (hack method but it worked )

If you can get information of each side from camera or colour sensors and then just input it into the array it should work the same way except instead of moving only numbers it would rotated servos as well!

Good luck with the project, it looks like fun!
Awally88

#### mklrobo

• Supreme Robot
• Posts: 503
• From Dream to Design at the speed of Imagination!
##### Re: How do you program a rubiks cube algorithm?
« Reply #13 on: January 21, 2015, 07:20:28 AM »
Hello! I have a suggestion. (I was on my way to do this myself)
I started to use a method like Awally88.
You can aquire a free "digital" cube solving software on the internet.
Then, the work begins.
I tried to find color sensors, and match them up to the emplacment on the cube.
In parallel, program the digital cube in the software to the same color/state emplacement.
Program the digital cube to step though the solution; in each step, program the robot
to move the real cube accordingly. Thus, the cube will be solved for you, with little or no
The trick is, of course, to interface the software. That is where the work will be. Making your
own systems of equations to solve the cube will be a JOB.  I wanted to rent my cube solving robot to
a near circus, for amusement, but no one wanted to entertain the idea. Good luck with your project!

#### mklrobo

• Supreme Robot
• Posts: 503