D
Deleted member 36445
Guest
Since I started learning to solve the Rubik's Cube in 2010, I've been interested in developing a cube simulator. However, it was challenging for me to grasp the concept of transforming the cube into code.
Over the years, I've tested various implementations, such as VisualCube, for example.
I also learned a lot about cubing theory and improved my programming skills.
If you access this link, you can find some of my achievements, including some simulators I developed.
https://filipeteixeira.com.br/cube-links/
Now I want to share some tips on how to create a cube simulator.
You can use the order of faces and sticker indexes that you find most suitable.
For the 3x3x3, for example, you only need to implement the U, x, and y movements. Once you have them, you can use x and y to make the z movement. If you have x, you can apply it twice for x2, and three times for x'. The same applies to y, z, and U. Now you can combine rotations and U moves to generate any movement you want.
You can cache the resulting transformations to avoid excessive calculations.
To implement cube rotations like x and y, you need a function to completely swap arbitrary faces and a function to 2D rotate an array. Then, observe what movements the physical cube performs when you rotate it, and reproduce that to create those movements. Don't forget to test everything properly or you will have unpleasant surprises later!
Imagine a slice move. It is simply some arrays permuting among themselves. (A permutation of 4 groups of stickers)
You can programmatically make a layer move by combining a 2D array rotation of a face with a movement of the nearest slice.
For example, a U move will be the clockwise rotation of the U face stickers plus the clockwise rotation of the nearest slice. (In this case, just a "strip" of stickers)
To generate any size of Rubik's Cube, you can create them procedurally by finding all the slices of the given cube and also the faces of the cube, then defining the basic moves.
Ft NxNxN simulator:
https://github.com/shuantsu/ft_cube/blob/main/cube_sim/assets/js/Cube.js
...
Also, check VisualCube (written in PHP); it's really interesting to see how it was implemented.
https://github.com/Cride5/visualcube/blob/master/visualcube.php
Over the years, I've tested various implementations, such as VisualCube, for example.
I also learned a lot about cubing theory and improved my programming skills.
If you access this link, you can find some of my achievements, including some simulators I developed.
https://filipeteixeira.com.br/cube-links/
Now I want to share some tips on how to create a cube simulator.
Use Simple Data
A cube can be described as an array of 6 arrays, each being two-dimensional. You can enumerate the stickers incrementally, accumulating them throughout the faces of the cube. More or less like this:You can use the order of faces and sticker indexes that you find most suitable.
Implementing Movements
For movements, try to implement one movement at a time and use the movements you create to make new ones.For the 3x3x3, for example, you only need to implement the U, x, and y movements. Once you have them, you can use x and y to make the z movement. If you have x, you can apply it twice for x2, and three times for x'. The same applies to y, z, and U. Now you can combine rotations and U moves to generate any movement you want.
You can cache the resulting transformations to avoid excessive calculations.
To implement cube rotations like x and y, you need a function to completely swap arbitrary faces and a function to 2D rotate an array. Then, observe what movements the physical cube performs when you rotate it, and reproduce that to create those movements. Don't forget to test everything properly or you will have unpleasant surprises later!
Displaying the Cube
Now that you have all the movements, it will be easy to map an algorithm string to execute each movement independently. After that, you'll be left to display your data as a visual representation of the cube, which you can do in many ways, like a 2D net or a 3D visualization.For Larger Cubes
For cubes larger than a 3x3x3, you can combine some basic transformations to generate movements. For example:Imagine a slice move. It is simply some arrays permuting among themselves. (A permutation of 4 groups of stickers)
You can programmatically make a layer move by combining a 2D array rotation of a face with a movement of the nearest slice.
For example, a U move will be the clockwise rotation of the U face stickers plus the clockwise rotation of the nearest slice. (In this case, just a "strip" of stickers)
To generate any size of Rubik's Cube, you can create them procedurally by finding all the slices of the given cube and also the faces of the cube, then defining the basic moves.
References
For reference, you can check my simulator code:Ft NxNxN simulator:
https://github.com/shuantsu/ft_cube/blob/main/cube_sim/assets/js/Cube.js
...
Also, check VisualCube (written in PHP); it's really interesting to see how it was implemented.
https://github.com/Cride5/visualcube/blob/master/visualcube.php
Last edited by a moderator: