Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class Solver
- Object
- Solver
Proves a level can be finished by finding a run that finishes it.
The simulation is deterministic, so a run is just its input, and any state a run reached can be reached again by replaying that input from the start. The solver keeps an archive of the places it has reached (a tile, whether the hero stood, the keys held and the switches thrown), each with the shortest input that got there. Every round it goes back to one of them – favouring the ones nearest the goal and the ones it has tried least – and presses buttons at random from there for a moment, archiving whatever is new. This is the “Go-Explore” idea, and platformers suit it well: being somewhere new is almost always progress.
Run it before a level is published (an editor, or a server checking a level a language model wrote), over every shipped level in a test, or offline to record the run a menu’s attract mode plays.
A game whose progress is something the solver cannot see – an ability
picked up, a counter its GameRules keep – says so with setProgress, so
reaching the same tile with more of it counts as a new place.
It drives one player. A level for several players needs its own search.
Nested types
interface Solver.Progress | What a game counts as progress besides where the hero stands. |
interface Solver.Worlds | Makes the world each run starts from, for a game whose levels need more than LevelData#createWorld(long): an EntityFactory, GameRules. |
Constructors
public Solver(LevelData level, long seed, long searchSeed) | A solver for one level and seed. |
Methods
public void setChords(int[] chords) | The button chords the search may hold, for a game whose input is not the whole pad – an auto-runner holds right and only chooses to jump. |
public void setWorlds(Solver.Worlds worlds) | Builds each run’s world with worlds instead of the level alone. |
public void setMaxTicks(int ticks) | The longest run the solver will consider, in ticks. |
public void setProgress(Solver.Progress progress) | Adds the game’s own progress to what makes a place new. |
public long getSimulatedTicks() | Ticks simulated so far, the solver’s measure of effort. |
public InputLog solve(long budgetTicks) | Searches for a finishing run. |
public int[] getClosest() | Where the search came closest to the goal, for telling a level’s author where it got stuck. |
public int getExplored() | How many distinct places the search has reached. |
Inherited methods
Constructor details
Solver
public Solver(LevelData level, long seed, long searchSeed)Parameters
levelLevelData- the level
seedlong- the world seed runs use
searchSeedlong- seeds the solver’s own choices, so a search repeats
Method details
setChords
public void setChords(int[] chords)Parameters
chordsint[]Inputbit combinations; null restores the default set
setWorlds
public void setWorlds(Solver.Worlds worlds)worlds instead of the level alone. The
world must be the one the game plays, or a found route will not replay.Parameters
worldsSolver.Worlds- the world maker, or null for
LevelData#createWorld(long)
setMaxTicks
public void setMaxTicks(int ticks)Parameters
ticksint- the cap
setProgress
public void setProgress(Solver.Progress progress)Parameters
progressSolver.Progress- the game’s measure, or null
getSimulatedTicks
public long getSimulatedTicks()Returns
solve
public InputLog solve(long budgetTicks)Parameters
budgetTickslong- how many ticks of simulation to spend before giving up
Returns
getClosest
public int[] getClosest()Returns
{column, row, distance in tiles}, or null before a searchgetExplored
public int getExplored()