Code covered by the BSD License

### Highlights from Rubik's Cube Simulator and Solver

4.81818
4.8 | 22 ratings Rate this file 56 Downloads (last 30 days) File Size: 2.44 MB File ID: #31672 Version: 1.9

# Rubik's Cube Simulator and Solver

### Joren Heit (view profile)

04 Jun 2011 (Updated )

This program simulates, manipulates and solves all rubik's cubes. Includes webcam recognition.

File Information
Description

Run: >>digrub

This program allows you to generate a randomly scramble cube of arbitrary dimension which can then be manipulated manually or solved by the computer. You can also input your own state using a webcam (3x3x3), or simply enter the colors of each facelet (2,3,4x.x.).

There are several built-in solving mechanisms available:

- God's Algorithm for the 2x2x2: this is the optimal solution for the given state (in half-turn metric).

- Thistlethwaite 45 (T45) for the 3x3x3: this algorithm will always find a solution of 45 moves or less, averaging at 31.

- Layer-by-Layer (Beginners') Solution: this is the method commonly used by beginners to solve the cube. More intuitive than T45, but also more extensive and less effective.

- 423T45 for the 4x4x4 (read 4 to 3, T45): this algorithm brings the cube to a state which can be handled like it was a 3x3x3 cube. When this is achieved, T45 can be applied to solve it (~180 moves on avg).

- Inverse Scramble for all cubes: it is like cheating, but when the scramble is known, each cube can be solved by inversing the sequence.

All of the above methods (with exception of the inverse scramble, which is trivial) are explained extensively in the included PDF. The PDF also contains a vast theoretical description of the cube.

DESCRIPTION OF INCLUDED FUNCTIONS/FILES:
algrot.m - calculates how an algorithm changes under rotation of the cube.
digrub.fig - GUI figure main program
digrub.m - GUIDE-generated m-file to go with digrub.fig.
editstate.fig - GUI figure for manual input program
editstate.m - GUIDE-generated m-file to go with editstate.fig.
findpeeks.m - Peek-finder that is used to find the cube's position in a webcam image.
GetCorners.m - calculates the corner permutation/orientation of a given 3x3x3 cube.
GetCorners2.m - calculates the corner permutation/orientation of a given 2x2x2 cube.
GetEdges.m - calculates the edge permutation/orientation of a given 3x3x3 cube.
GetFacelets.m - converts a state in the orientation/permutation representation to the facelet repr.
Ind2State.m - converts an index to a state
move2rub.m - converts a move of the form 'x11' to Rubik's Code 'B'.
parity.m - calculates the parity of a permutation.
rub2move.m - converts a move in Rubik's code to axile 'x11' form.
rubcheck.m - checks the validity of a 2x2x2 or 3x3x3 state.
rubcross.m - searches for a cross on the cube.
rubgen.m - generates a cube
rubinfo.m - returns information about the cube state
rubopt.m - optimizes a move-sequence
ruborient.m - orients the cube
rubplot.m - plot a 3D image of the cube
rubrot.m - apply a move to the cube
rubrot2.m - rotate the entire cube
rubsolve.m - solve the cube using a layer by layer approach
Solve45.m - solve the cube using T45
Solve222.m - find God's Algorithm to a 2x2x2 cube
Solve444.m - find a solution to any 4x4x4 cube.

jorenheit[at]gmail.com

Acknowledgements

This file inspired Rubik's Cube® Solver Using An Arduino And Matlab.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Other requirements Fluent functionality of the 3D-animations require a fast CPU.

how to i send the string solution to my arduino ?

Comment only
07 May 2016 inzamam ahmed

### inzamam ahmed (view profile)

Comment only
05 May 2016 WAWAN kurniawan

### WAWAN kurniawan (view profile)

Great mate, its wonderful.

05 May 2016 pepetatay

### pepetatay (view profile)

you get an error when opening the "digrub.fig" file. However, if you open "digrub.m" and run it works perfectly. At least it did to me. Great Work @JorenHeit!!!

20 Apr 2016 Tyson Mann

### Tyson Mann (view profile)

did not work, fix pls.

12 Apr 2016 inzamam ahmed

### inzamam ahmed (view profile)

hello I am getting error while running digrub, error is because of rubgen function. I am using 2013a vesion. Please help me out.

Comment only
11 Apr 2016 PAVANKRISHNA E R

### PAVANKRISHNA E R (view profile)

Hello, I am getting errors while running digrub. I am using 2016a version

Comment only
06 Mar 2015 Luis Orlando Raymundo Castro

### Luis Orlando Raymundo Castro (view profile)

hola,pero no se como se descarga

Comment only
29 Dec 2014 ninior ninio

### ninior ninio (view profile)

thanks very much.really wonderful

Comment only
24 Dec 2014 Hammad ur rehman

### Hammad ur rehman (view profile)

19 Dec 2014 KEO Sothun

### KEO Sothun (view profile)

i don't understand !!! :(

30 Jun 2014 Manjunath M C

### Manjunath M C (view profile)

24 Apr 2014 Shubham Bhatt

### Shubham Bhatt (view profile)

thanks for the code.i m looking for this

07 Feb 2014 paolo

### paolo (view profile)

31 Jan 2014 Nwaobasi Chukwuemeka

### Nwaobasi Chukwuemeka (view profile)

Wonderful

23 Jan 2014 Daniel Camilo Rolón Quintero

27 Dec 2013 Rene

### Rene (view profile)

Super nice !

17 Aug 2013 Joren Heit

### Joren Heit (view profile)

@Kuifeng It's been a long time since I worked on this project, but I can remember trying to add arrows to represent those axes... However, drawing (nice) arrows in Matlab proved not to be as straightforward as you might think, and I gave up (also because of the low priority).

Comment only
17 Aug 2013 Kuifeng

### Kuifeng (view profile)

Very nice work, consider adding X-Y-Z arrows in the cube?

19 Mar 2013 Joren Heit

### Joren Heit (view profile)

@Krisztian You might wanna give the big blue button that says "Download Submission" a try...

Comment only
19 Mar 2013 Krisztian Makar

### Krisztian Makar (view profile)

Comment only
08 Feb 2013 Abdallah Elsherif

### Abdallah Elsherif (view profile)

very nice work, thanks for sharing the code

18 Sep 2012 Oleksandr

### Oleksandr (view profile)

10 Apr 2012 Joren Heit

### Joren Heit (view profile)

Comment only
05 Apr 2012 Avinash k

### Avinash k (view profile)

Comment only
11 Mar 2012 Tharindu

### Tharindu (view profile)

24 Oct 2011 Thiago

### Thiago (view profile)

congratulations! you are a genius! this is really nice of to share the code...thx!

12 Oct 2011 Joachim

### Joachim (view profile)

09 Oct 2011 Mr Smart

### Mr Smart (view profile)

Nice, Thanks for share .

14 Jul 2011 Gurinder pal singh

### Gurinder pal singh (view profile)

done , its nice

Comment only
01 Jul 2011 Aakash

### Aakash (view profile)

01 Jul 2011 prashant kumar

### prashant kumar (view profile)

08 Jun 2011 Pavan

### Pavan (view profile)

I was searching for such a program for a long time...I knew how to solve the Cube but for a long wanted to see a program that could implement it....really nice work

06 Jun 2011 vahid veisy

### vahid veisy (view profile)

06 Jun 2011 1.1

Removed a couple of bugs, improved the ouput solution + animation of the solution. Added the 'Undo' button and option to hide current scramble.

07 Jun 2011 1.2

Added manual method for entering/editing the state and improved Webcam-function using this method (manual correction of captured state).

08 Jun 2011 1.4

Improved step 1 in the solving algorithm, has resulted in more stable solve time (0-2 sec).

03 Jul 2011 1.5

Added option to solve cube using inverse scramble (higher dimension cubes can be solved now). Option to display row numbers on the cube. Added full validity check when editing the cube manually.

08 Oct 2011 1.6

Major changes! New, more efficient solving mechanism, supporting 2x2x2, 3x3x3 and 4x4x4 cubes. New button lay-out and extensive explanatory pdf.

12 Oct 2011 1.8

Added parity.m, which I forgot to include in the last version.

23 Oct 2011 1.9

Updated screenshot (Windows version), minor bugfixes