First time posting here and I'm really, really hoping this is the community I've been looking for.

I'm developing a game, right now I'm in the middle of designing levels as the core mechanics have already been laid out in code. While designing levels I noticed that I could easily add some puzzles because the code was already there.

I've thought about a kind of puzzle that I've seen in many games but I don't know the name so google didn't really helped me.

To make it short you got multiple buttons, every button controls the rotation of some platforms.

In my case, as you can see in the image below:

All the rotations are clockwise, green is the final path, yellow dots are the rotation pivots

  1. Button 1 (B1) controls the rotation of P1, P2 and P3 increasing it of 45 degrees
  2. Button 2 (B2) rotates by 90 degrees P2 and P3
  3. Button 3 (B3) rotates by 90 degrees P1 and P2

Pressing 2 times B1, 2 times B2 and 3 times B3 solves the puzzle.

enter image description here

I don't know if this is the optimal solution and the design of this puzzle was based on mere luck.

What I'm asking here, hoping to find an answer, is if there is some algorithm for this kind of puzzles, some books or resources to learn about the design, because I really enjoy the touch that it gives to the game and would like to explore this puzzle world to find new solutions.

Thanks in advance, hope everything was clear as English is not my first language!


1 Answer 1


This is related to the mathematical field of graph theory, and your puzzle is essentially a finite-state machine. Each platform has 8 possible states, so the entire system has $8^3=512$ states ('vertices' in graph theory). Each button maps one of those 512 states to precisely another one (an arrow, or 'directed edge' in graph theory). It's not recommended to draw such a large graph, but you can imagine that following the 'button 1' edge eight times will lead to the initial vertex/state. For button 2 and 3, it's only a cycle of length four. Also, parts of the graph will be disjoint (separate) from other parts, which means you can never reach them from the initial (solved) position, and consequently if the puzzle is in such a state, you can never solve it.

I haven't looked at your puzzle in detail, but I imagine that there are only $8 \cdot 4 \cdot 4 = 128$ states reachable from the final position (the lengths of the cycles of each button); the puzzle will probably be harder if

  • you make sure every button rotates every platform
  • the other buttons get a cycle length of 8 as well
  • the rotations are longer (e.g. 135 degrees or even 225; longer rotations are harder to visualize for the solver)
  • there's some kind of maximum to the number of times you can press each button
  • you can't press the same button twice in a row

On the other hand, the difficulty level of this puzzle might be perfect for your audience. You never know until your test!

Another way to look at this puzzle, which provides an easy way to solve it, is to look at modular arithmetic, in this case modulo 8. A state of the puzzle is denoted as $(p_1, p_2, p_3)$ where each number denotes the number of 45 degree turns the platforms ($p_1$ for P1, $p_2$ for P2, $p_3$ for P3) have made from the solution. So the depicted situation would be $(0, 4, 2)$. Pushing button 1 adds $(1, 1, 1)$, button 2 adds $(0, 2, 2)$ and button 3 adds $(2, 2, 0)$. Whenever you encounter a number of 8 or higher, just subtract 8. It doesn't matter in which order you push the buttons; let's say you push button 1 $b_1$ times, button 2 $b_2$ times and button 3 $b_3$ times. That means, since we want to reach $(0, 0, 0)$:

$$0 + 1b_1 + 0b_2 + 2b_3 = 0 \pmod 8$$ $$4 + 1b_1 + 2b_2 + 2b_3 = 0 \pmod 8$$ $$2 + 1b_1 + 2b_2 + 0b_3 = 0 \pmod 8$$

or equivalently

$$b_1 + \ \ \ \ \ \ \ \ \ \ 2b_3 = 0 \pmod 8$$ $$b_1 + 2b_2 + 2b_3 = 4 \pmod 8$$ $$b_1 + 2b_2 \ \ \ \ \ \ \ \ \ \ = 6 \pmod 8$$

Subtracting the first equation from the second gives $2b_2 = 4$ so you need to push button 2 two times; substituting that in the second equation gives $b_1 + 2 \cdot 2 = 6$, so $b_1 = 2$ so button 1 two times as well. Putting that in the first equation gives $2 + 2b_3 = 0 \pmod 8$ so $b_3$ must be 3 ($2 + 2 \cdot 3 = 8 = 0 \pmod 8$); you need to push button 3 three times.

  • 1
    $\begingroup$ Wow! This is such and in depth answer that i'm really glad i decided to post it here! I'll have a look in depth at the links you posted, i have some knowledge about graphs but my mind could not make this connection, and funny thing is that i use a graph system and minimum spanning tree logic to design some levels... So you pretty much created a link for me! My next step now is to try to create a process to design this kind of puzzle with some knowledge and less "try-fail" Thanks! $\endgroup$
    – Davide
    Commented May 26, 2020 at 17:57
  • 1
    $\begingroup$ You're welcome! It isn't even complete; my gut feeling says someone comes up with the actual term you're looking for (I don't know it, of course). Stack Exchange is a worldwide network and many people visit the site only once a day. $\endgroup$
    – Glorfindel
    Commented May 26, 2020 at 17:59
  • 1
    $\begingroup$ Yeah, while I was cooking I realized there's another way to look at this problem in a mathematical way. I'll update my answer, stay tuned ... $\endgroup$
    – Glorfindel
    Commented May 26, 2020 at 18:21
  • 4
    $\begingroup$ The second explanation is the same kind of linear algebra that is used in lights_out games, but where instead of coloured lights you have rotating parts, and the buttons are separate. $\endgroup$ Commented May 26, 2020 at 19:38
  • 2
    $\begingroup$ This is incredible, the modulo solution is exactly what i've been looking for, i had to launch the game and check it out and my jaw dropped! I already applied it to another similiar puzzle i was creating and it just worked. Now i feel like i can control it, the difficulty and the outcome, and this is exactly what i was looking for. This time i'll mark it as an answer, because it gave me exactly the insight i was looking for, it gave me the basics to study and references for study materials! I think it will also help whoever will bump in this post in the future! Thanks again $\endgroup$
    – Davide
    Commented May 26, 2020 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.