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 end of move, the application uses Fixe(mask) function to update the internal data of the classe CCubes (the m_cube 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
The general structure uses the MFC architecture. Commands windows allow 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 the cleaned up of the Cube. The report can be saved in a file in binary mode (simple copy of the table of the elementary cubies) or ASCII (coding of colors facets) or in the form of 6 images of every faces, stored in a file TIFF.
Scanner input Dialog view
Keyboard input Dialog view
Resolution program (Resolve() function) is resulting from a free version available on the Web, simply adapted and optimized to obtain a solution of 20 moves or less, in less than a minute (Solver Sources files & Solver header files folders). This output formula is givens in a standard language for the Rubik's cube players. Its always enable to play this commands on a Cube simulator (CDiagCmd::ExeCmd() function).
File example.txt gives typicals formulas for encoding a Rubik's Cube. You can use "copy/paste" facility to copy one of these formulas in the Command window "Deformations Resolution".
Finally, this program provides interfaces examples between different modes of encoding a Rubik's cube: 27 cubes method, table of 54 colors of facets, ASCII string.
For example, the OnFileOpen and OnFileSaveAs functions of the class CChildView reads or saves the different formats :
- 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 internal format (*.rbx), the copy of the internal m_cube table (one ascii char per cubie),
- the six used colors code (*.col) coded in hexa.
The original algorithm has been rewritten with a new code, improves the search speed. Then, in a second time, it is supplemented by taking advantage of multiprocessor performance of new PCs. Indeed, the first solution found to create a new Cube symmetrical to the original, which then search for a solution is conducted in parallel, allowing faster to find the shortest solution.