Class 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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhat a game counts as progress besides where the hero stands.static interfaceMakes the world each run starts from, for a game whose levels need more thanLevelData#createWorld(long): anEntityFactory,GameRules. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]Where the search came closest to the goal, for telling a level's author where it got stuck.intHow many distinct places the search has reached.longTicks simulated so far, the solver's measure of effort.voidsetChords(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.voidsetMaxTicks(int ticks) The longest run the solver will consider, in ticks.voidsetProgress(Solver.Progress progress) Adds the game's own progress to what makes a place new.voidsetWorlds(Solver.Worlds worlds) Builds each run's world withworldsinstead of the level alone.solve(long budgetTicks) Searches for a finishing run.
-
Constructor Details
-
Solver
A solver for one level and seed.
Parameters
level: the levelseed: the world seed runs usesearchSeed: seeds the solver's own choices, so a search repeats
-
-
Method Details
-
setChords
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.
Parameters
chords:Inputbit combinations; null restores the default set
-
setWorlds
Builds each run's world with
worldsinstead of the level alone. The world must be the one the game plays, or a found route will not replay.Parameters
worlds: the world maker, or null forLevelData#createWorld(long)
-
setMaxTicks
public void setMaxTicks(int ticks) The longest run the solver will consider, in ticks. Five minutes by default.
Parameters
ticks: the cap
-
setProgress
Adds the game's own progress to what makes a place new.
Parameters
progress: the game's measure, or null
-
getSimulatedTicks
public long getSimulatedTicks()Ticks simulated so far, the solver's measure of effort.
Returns
the tick count
-
solve
Searches for a finishing run.
Parameters
budgetTicks: how many ticks of simulation to spend before giving up
Returns
the input of a run that reaches the goal, or null when none was found in the budget
-
getClosest
public int[] getClosest()Where the search came closest to the goal, for telling a level's author where it got stuck.
Returns
{column, row, distance in tiles}, or null before a search -
getExplored
public int getExplored()How many distinct places the search has reached.
Returns
the archive size
-