scottbedard / minx

A model to represent the state of dodecahedral twisty puzzles
https://speedcube.site
MIT License
1 stars 0 forks source link

State management #2

Open scottbedard opened 5 years ago

scottbedard commented 5 years ago

The primary function of this library will be to manage the state of any size N-minx puzzle, where the number of layers is greater than 1. We can't quite piggy back off how this works in our cube repo, because unlike cubes we cannot represent each face as a simple two dimensional table. We'll be dealing with the following types of faces...

The simplest way I can think of to store this data is to think of each face as having a specific orientation, and storing each sticker value spiraling outward from the center. For example, a megaminx (3 layer) style puzzle might look something like this...

{
    values: [
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    ],
}

Each face will have a unique identifier and orientation. On first thought, something like this might work.

The sticker index will begin in the center of the face, and spiral clockwise outward starting with the corner opposite that faces orientation. For example, the F face on a standard gigaminx would have the following index positions. We start from this position because it will always be a corner, which puzzles of any size are guaranteed to have.

Using this spiral, we can extract "rings" from our faces, which can then by sliced to get a particular intersection. To build off the example above, this face would have the following rings of index positions.

[0]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
scottbedard commented 5 years ago

To help visualize how the spirals will map to different size faces, I whipped up some quick desmos constructions. We'll need to create a function that can take these spirals and chunk them into their individual rings.

One important thing to note here is that there is a slight difference between our even and odd layered puzzles. The ring logic should be the same, with an exception of odd layered puzzles starting with center piece.

Update: The chunk function is written, click here to see the spec.

2 3 4 5 6 7

scottbedard commented 5 years ago

Now that we have the ability to rotate pentagonal faces, it's time to work out the relationships between faces. In order to know how the other faces are effected by a turn, we'll need to use our orientation and relationship with other faces to extract and move around these kinds of rings.

2 3 4

At a minimum we'll need the following things...

scottbedard commented 5 years ago

Working on this more, here is a larger map of the even-layer minx spiral

even-minx

To give some context to our slice function, here is an example slice with a depth of three on this map.

2, 3, 10, 15, 28, 37, 56, 69
scottbedard commented 5 years ago

Here is the same sort of map for odd-layered minx puzzles

Screen Shot 2019-07-03 at 2 19 59 PM