Rubix Cube

Last Updated: December 17, 2013
Originally Published: October 18th, 2010

The graphic part is ensured by the CCubes class and is helped in the classes CMatrix, CSide, CVertex and CVertexList. This gives an example of the functions to be performed to ensure a vision in prospect 3D or in flat unrolled. Rubik's cubic can be moved or deformed by using orders or of the mouse with a surprising fluidity. The Cube state running is stored in a table of 27 elements of the type t_Mask representative in a compacted way the relative position and the orientation of the 27 elementary cubies. Moreover, two 3*3 matrices, external with the CCubes class, lay down the general orientation of the Cube and the relative orientation of the part moving. At the end of a deformation, the table of the 27 elementary cubies is updated and the deformation matrix set to zero.

The application uses Comput(mask) function of the class CCubes to compute the view of the Cube in a move or a deformation. The mask gives the side of cubies as a deformation part.

After, at the end of the move, the application uses the Fixe(mask) function to update the internal data of the classe CCubes (the m_cube[27] table).

It uses Comput2D() function to compute the Rubik's cube in a flat unrolled view


Main window with 3D prospect an flat unrolled view. The Dialog view is used to deformation or resolution of the Cube

To define the Cube display

To define the Cube display.

The general structure uses the MFC architecture. The Commands windows allows you to initialize the state of the Cube from the keyboard or from a flatbed scanner equipped with a TWAIN driver or finally to find an allowing solution of the cleaned up Cube. The report can be saved in a file in binary mode (simple copy the table of the elementary cubies) or ASCII (coding of colors facets) or in the form of 6 images of every face, stored in a file TIFF.

Scanner input Dialog view.

Scanner input Dialog view.

Keyboard input Dialog view.

Keyboard input Dialog view.

The program also includes several function resolutions derived from free versions available on the Web, adapted and optimized to improve speed of resolution and to working in multiprocessor :

  • XSolver(int slide) provides the resolution by steps as is done by hand.
  • KSolve(const CCubes *pCubes, CEdit *pEdit, BYTE nbOfProcs) gives a quick solution, especially optimized if we give it time.
  • Centers::ResolveCenters(DWORD centers, CCmdString &out) const gives a solution to restore order to the centers of faces.
  • QSolve(const CString &cmd, CEdit *pEdit, BYTE numberOfProcessors) determines the shortest solution in terms of quarter turns of faces.

Example of ”Superflip”

Example of ”Superflip” resolution by QSolve (PC with AMD Phenom(tm) II XA p55, 4 processors, 3.20GHz and 3.25Go of RAM).

This program enables communication and exchange of information with other programs and the Internet, thanks to the clipboard, drag & drop possibilities, input or output files and even allows to print a sheet with the displayed Rubik's Cube.

Formats of exchanges for encoding a Rubik's Cube is very different :

  • in TIFF file (*.tif) the 6 images of each face of an Cube
  • in ASCII file (*.txt) the table of 54 colors of facets (sides, colors format ie : L:OWGGORWGB F:YROGGOWRR...),
  • in standard Singmaster format (*.sgm),
  • in Maneuvre format (*.man) formula giving the following movements face necessary,
  • in Images formats (*.bmp, *.jpg, *.gig, *.png) for image of the held flat of Rubik's Cube,
  • in internal format (*.rbx), the copy of the internal m_cube[27] table (one ascii char per cubie),
  • the six used colors code (*.col) coded in hexa.

Finally, through the CGIF89a class that allows to write and read an animated GIF file, this program allows you to create a GIF file showing the preferred sequence of movements.

Example of an animation created, showing the famous Superflip

Example of an animation created, showing the famous Superflip which allows the same command sequence to achieve the figure and then solve it.

Of course, the program includes a dialogue window adapted to define the file name, all the parameters of the animation, the dimensions of the image and the command sequence expressed in the language of the Rubik's Cube.

About the Author

Georges Dumond

Courbevoie (France)



  • Doesn't compile in VC++ 6

    Posted by Georges Dumond on 10/03/2013 04:56am

    Depending on the version of the workshop and the version of Windows, the GDIPlus library is included or not in the development system. That is why, with my delivery, I added this library (GDIPlus directory). But, if the error is detected : "GDIPlus.h not found", you must, either add the path to this library in the setting or copy the library that I have provided at the location "C:\Program Files\Microsoft Visual Studio\GDIPlus\"

  • Doesn't compile in VC++ 6

    Posted by oldcomp on 03/17/2013 08:47am

    Doesn't compile in VC++ 6 fatal error C1083: Cannot open include file: 'Gdiplus.h': No such file or directory

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there's simply not enough quality talent to go around. In response, companies often resort to inferior solutions -- hiring substandard developers and engineers, recruiting talent on a part-time or temporary basis, poaching people from competitors, or burdening an already stressed IT staff for more of their labor. Fortunately, there's a better solution. Read this white paper to learn the business value of …

  • As the mobile enterprise marketplace expands and customer needs grow more diverse, Samsung recognizes that solution partners and developers play an essential role by continually innovating to meet their customers' needs. Samsung works to provide these developers and partners with the latest tools and resources needed to create these solutions. Read this program guide to learn how the Samsung Enterprise Alliance Program provides partners and developers with Samsung enterprise software development kits (SDKs) …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date