Mathematical models and interactive solvers for Prince of Persia speedrun puzzles
A suite of state-space simulators and search algorithms created to find the absolute minimum input sequences for Prince of Persia speedruns. Play with the interactive models below or explore the underlying state machines.
In The Two Thrones, the Prince must navigate a giant statue of his father King Sharaman through the palace courtyard. Each tile on the courtyard track permits specific movements (forward/backward translation or clockwise/anti-clockwise rotation) depending on the direction the statue is facing. The puzzle is solved by moving forward from step 4 while the statue is facing Front.
The Water Pillar puzzle features three stacked rotating tiers (Lower, Middle and Upper), each sitting at position 1–4. A Normal lever move turns every piece. A Freeze move holds back any piece that is at position 4 (clockwise) or position 1 (anti-clockwise); the Upper and Middle tiers each hold back together with a hidden joint piece. The puzzle is solved when all three tiers are at position 4 (the game gives no indication).
A dual interlocking rotary ring puzzle from the Wii version of The Forgotten Sands. Each ring holds eight gems, and the two rings overlap in two slots, so turning one ring also changes the other. A colour is solved when the four gold-ringed slots all hold that colour or the white wildcard (5). Solve all four colours at least once to win.
Gold ring = slot checked for solving · Dashed border = slot shared by both rings · 1 Yellow, 2 Green, 3 Orange, 4 Purple, 5 Wildcard
In speedruns, solving puzzles by intuition or standard intended player routes wastes dozens of seconds. Because each move has a deterministic transition matrix, we can model the entire game puzzle as a directed graph and compute the Breadth-First Search (BFS) shortest path to discover the fastest possible inputs.
The King's Statue puzzle uses a 2D transition table indexed by [rotation][translation]. Certain tiles block forward motion if the statue is facing the walls or dead ends, and the puzzle is only won by moving forward from step 4 while facing Front. The C++ bruteforcer searches these states and finds a shortest solution of 13 moves.
The Forgotten Sands puzzles involve coupled modulo arithmetic (e.g. turn(piece, d) = (piece - 1 + d + 4) % 4 + 1) and rings that share slots. The bruteforcer runs a breadth-first search that merges identical states, so searching up to 15 moves stays fast even for the Wii gems puzzle (about 7.3 million states).