[TUTORIAL] How to create NxNxN simulators

  • Thread starter Thread starter Deleted member 36445
  • Start date Start date
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.


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:

1748654908543.png


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:
I have no coding knowledge but I remember spending a few hours trying to get Grok to code a virtual cube for me, it kept getting so close but there was always something wrong with it and I eventually just gave up on it.
What's the point of that? Just download a NxNxN simulator from github
 
What's the point of that? Just download a NxNxN simulator from github
I wanted to see if it could do it, I know it was pretty pointless since other people have already made stuff like that but I feel AI reached a new level of ability once it can code something like that itself.
 
I wanted to see if it could do it, I know it was pretty pointless since other people have already made stuff like that but I feel AI reached a new level of ability once it can code something like that itself.
Even if people made projects like that in the past, you can learn a lot by trying to implement it.

There are people that learn programming by trying to create a spotify or netflix mockup or a simplified Minecraft clone.

I believe it was not "pointless" or that you should "just download it from github".

By going through the process you learn patterns and develop problem solving skills.

Some people hate AI without reason, but as you said, it is a really good tool and can break barriers so keep using it because prompt engineering is going to be more and more useful as time passes by and if people don't learn it it will be a wasted opportunity for no valid reason.
 
Back
Top