Menu

How I prove every level in my puzzle game is solvable (BFS over every mirror state)
📰

How I prove every level in my puzzle game is solvable (BFS over every mirror state)

DEV Community: flutter·Mofidul Islam·1 day ago
#8G5y1fwn
#devtoflutter#devto#dev#state#shortest
Long article (597 words) — no AI summary yet.
Reading 0:00
15s threshold

I recently shipped PrismTrail , a small laser-maze puzzle game for iOS and Android, built with Flutter. You tap mirrors to flip them between / and \ , and the beam has to reach a prism. Later levels add rings that teleport the beam, one-way glass, linked mirrors that turn together, and gates that open when a matching receiver is lit.

Players forgive a hard level. They don't forgive a broken one. So I set one rule early: no level ships unless a program has proven it is solvable, and knows the shortest solution.

The state space is small, so search all of it

Every level has at most four mirrors. Each mirror has two orientations, so the mirror state fits in a 4-bit mask. Gates add a little more state: once a receiver is lit, its gate latches open. So a game state is (mirror bitmask, set of opened gates) .

That is tiny. Instead of sampling or hand-testing, the generator runs a plain breadth-first search from the starting state over every reachable state.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.