Beamies: How a Solver Measures and Raises Difficulty
By Nesim Razon, independent mobile developer · 2026-11-26
Beamies has 400 levels that nobody drew by hand. A solver measures how hard each one is, a hill climb makes it harder, and a test replays every stored solution before the game ships. This post follows that chain: why my first levels were too easy, what a move even means here, how two different solvers do two different jobs, and where the finished pack still falls short of its own plan.
Too simple, and the numbers agreed
Beamies is a puzzle where you slide a teleport gate across a board and it beams aliens of its own color home. The gate moves one cell at a time. It can only pass over aliens of its own color, other colors, other gates and walls block it, and it disappears when its capacity is full. When the last alien is gone, the level is done. My first generator placed pieces at random, solved the result and kept the best of many tries.
It worked, and I played through to level 334. My verdict was that it was nice but far too easy, the kind of game an ordinary player would finish in a few hours. The numbers agreed. The fewest drags needed to finish a level, which the game calls par, was mostly between 4 and 10, and the solver got through after expanding only 7 to 40 states. Adding more gates did not raise par. Picking the best of many random layouts does not create depth. It only picks the best of the shallow ones.
What counts as a move
A drag is one stretch of moving the same gate. Every step moves a gate by one cell, but a run of steps with the same gate counts as a single move, and a new move starts only when you switch to another gate. The game counts it that way even if you lift your finger and carry on with the same gate.
Level 1 shows the idea. It has one gate with room for six aliens, and its stored solution is eight single-cell steps, which makes one drag. Par is the fewest drags over all possible solutions. That is the number I try to raise, because it matches how effort feels to a player: not how many cells you cross, but how many times you have to stop, think and choose a different gate.
Two solvers for two jobs
The first solver measures par. It is an A star search where continuing with the same gate costs nothing and switching gates costs one. The state includes which gate moved last, so the search knows when a switch happens. Its guess for the remaining cost is the number of gates still on the board, minus one if the gate you just moved is still there. That guess never overestimates, because every remaining gate needs at least one drag, so the answer is the true minimum. A budget of expanded states keeps the search from running forever.
Levels with patrolling asteroids, edge portals or rotating gates can blow that budget, because time becomes part of the state. For those the program falls back to a second solver, a weighted A star. With weight zero it is a plain breadth-first search over single steps. With a positive weight it uses a cheaper guess, six per remaining alien plus each gate's distance to the nearest alien of its color, and it finds a good solution fast but not always the shortest. So on timed levels the stored par is an upper bound: the best solution found, not a proof of the minimum.
The weighted solver also runs on the phone: after each move it searches in the background. If it exhausts the whole search space without a win, the position is a dead end, the game says so and undo becomes free. If it merely runs out of budget, the game stays quiet. The hint button uses the same search and plays the first drag of what it finds.
Building backwards, then climbing
Construction starts from the end. The generator takes the solved board, with every gate gone, and plays in reverse: a gate appears, steps back one cell and leaves aliens behind on the cells it just uncovered. Each reverse step matches a legal forward move, so the level that comes out can be solved by construction, and its solution is the steps in reverse order. Patrols are added only if replaying that solution still works. Edge portals change the solution, so those levels are checked by the solver instead.
That gives solvable levels, not deep ones. The deepening step is a hill climb. It makes a small random change: move an alien to another empty cell, shift a gate's start by up to two cells, add one capacity and one alien of that color, or add or remove a wall. About half of the changes move an alien. After each change the solver measures par again, and the change is kept when par does not go down. Accepting equal values lets the layout wander across flat stretches. The climb stops when par reaches the target for that level, after a set number of tries, or at a time limit. In the first experiment, 400 tries lifted par from 4 to 12, 4 to 11, 4 to 10 and 5 to 19.
If a level cannot be built with the full rules of its region, the generator drops features in up to six stages, portals and patrols first, and the last resort is a tiny always-solvable level. For easy and medium levels from level 8 on, ten random playthroughs of 10 to 40 moves must all end in positions the solver can still finish, so a beginner cannot trap themselves. It is a preference: hard levels may keep an unavoidable trap, and undo is free when you are stuck.
The target curve, and what the pack delivers
The target par for a level depends only on its position. The 400 levels are 40 regions of ten. The base grows with the region as 3 plus 21 times the region number divided by 39, raised to the power 0.85, and a multiplier by position inside the region shapes the wave: 0.5, 0.6, 0.8, 0.95, 1.1, then 0.5 as a breather, then 1.0, 1.25, 1.5 and 2.0 for the boss. So level 1 aims for par 2, level 10 for 6, and level 400 for 48.
A target is a wish and the file is the fact, so I measured the pack with a small script that counts drags the way the game does. Par ranges from 1 to 49, with a mean of 14.9 and a median of 13. Averages for each block of 50 levels are 5.5, 8.3, 12.5, 12.0, 18.1, 20.5, 23.2 and 19.0. The wave is there: averaged by position inside the region, the breather level has 8.1 and the boss level has 26.8.
It is not perfect. 317 of the 400 levels reach or pass their target, and 58 stay under 80 percent of it. The last block is the weakest: its average dips to 19.0, and level 400 has par 21 against a target of 48. Late levels combine many element types, and in those regions only about 5 to 20 percent of build attempts succeed. A fix mode reruns weak levels with more time, but the gap I measured is still open.
Stars come from par
Nobody finds the best solution on the first try, so the star limits are generous. Three stars up to 1.5 times par rounded up, plus 1. Two stars up to 2.5 times par rounded up, plus 2. Otherwise one star. For par 6 the limits are 10 and 17, for par 13 they are 21 and 35, and for par 20 they are 31 and 52. Every level carries its own par, so nothing needs hand tuning.
Testing the pack
The pack is one text file with 400 lines. Each line holds size, walls, gates, start positions, aliens, patrols, portals, paint, fog and the stored solution, separated by hash signs, with the solution written as a gate number plus a direction letter, like 0R0R0D. PackTest has five tests. Three run only when the GEN_PACK environment variable is set: one generates all 400 levels in parallel and writes the file, one fixes weak levels, one regenerates levels whose stored solution stopped being legal after a rule change. The two that always run are a round trip that encodes and decodes sample levels, and the pack check, which requires 400 lines and replays every stored solution through the real game rules. A level whose solution does not win fails the test.
The solver also had a bad day in production. Version 1.0.3 ran the weighted search after every move for the stuck check, with a budget of 300,000 states, and ran hints on the main thread with 400,000, without a memory limit. On level 180 the search frontier outgrew the heap, and Crashlytics showed many OutOfMemoryError reports. Version 1.0.4 added a cap on stored states, cancellation when a new move arrives, a stop when the heap passes 55 percent, and moved hints to a background thread. SolverGuardTest runs the limited search on level 180 and requires it to finish in under 30 seconds with less than 120 MB of heap growth. My notes recorded 218 milliseconds and about 46 MB.
What I would change
Two difficulty measures live in the code. The older one counts how many states a breadth-first search expands. The shipped pack uses par. I have not proven which tracks player frustration better, and the game now records when a player leaves a level unfinished, with moves and time, so real data can answer that.
The late regions need a faster way to build deep levels, and timed levels need a tighter bound than a weighted search gives. Beamies: Beam Home is the Android puzzle where all of this lives, with 400 levels from the Moon to the Galaxy.
Frequently asked questions
What does par mean in Beamies?
It is the fewest drags needed to finish a level. Moving the same gate in a row counts as one drag, and switching to another gate starts a new one.
Why does the game use two solvers?
An exact A star search measures par. A weighted A star is faster and is used for hints, dead-end detection and levels with timed elements, but it does not always find the shortest solution.
How are levels made harder?
A hill climb makes small random changes and keeps a change when par does not drop, until par reaches the target for that level.
How are the three stars decided?
Three stars up to 1.5 times par rounded up plus 1, two stars up to 2.5 times par rounded up plus 2, otherwise one star.
How is the pack tested?
A unit test checks that the file has 400 lines and replays every stored solution through the real game rules, so a level that cannot be won fails the test.
More from the blog
- Moving From GitHub Pages to Your Own Domain Without Losing SEO
- Kotlin/Native and Swift: The 'Different Argument Labels' Error
- Kotlin Multiplatform: Platform Features as a Nullable Interface
300 Maze Levels With Monsters, Checked by a Solver
Testing a Camera App on Several Phones: Flash and Lens Position
How to Host a Tombala Night at Home: An Organizer's Guide