Skip to content

SimulationScript

namespace Griff.Simulations;
public abstract class SimulationScript

A balance simulation written as a script, for what the no-code matchup doesn’t cover: a gauntlet of fights with gold and XP carried from one to the next, an economy, a dungeon run. Derive a class from it and name it in a simulation’s Script; Griff makes a new one for each run and calls Run with the run’s pair of rows. Rand and dice rolls give the run’s own numbers, so the same seed plays the same runs on any machine and any number of cores.

In a scene run (a simulation with a Scene) it’s a strategy instead: each run plays the real game headless, calling Setup before the game’s first step, Act every Act Every seconds of game time (to play through the game’s own components, as a player would), IsOver after each step, and Done as it ends. Game is the game being played.

public class HireEarly : SimulationScript
{
public override void Setup(SimulationRun run) => run.Game!.SetFlag("SkipIntro");
public override void Act(SimulationRun run)
{
var shop = run.Game!.Find<Shop>()!; // the game's own component
if (shop.Cash >= shop.WorkerCost) shop.HireWorker();
}
public override void Done(SimulationRun run)
{
if (run.Game!.Find<Shop>()!.Cash > 0) run.Win(); else run.Lose();
}
}
public virtual void Act(SimulationRun run)

In a scene run, called after the game’s first step, then every Act Every seconds of game time, and on each step a panel pauses the game: play the game through its own components (sign offers, hire, buy, move), close or answer a panel, Track a value or End the run.

public virtual void Done(SimulationRun run)

In a scene run, called as it ends, with the game as it was at the end: say how it went (Win, Lose, Earn).

public virtual bool IsOver(SimulationRun run)

In a scene run, asked after each step: true ends the run there (cash run out, a goal reached).

public virtual void Run(SimulationRun run)

Plays one run, saying how it went through run (Win, Earn…). Left as it is, it plays the simulation’s scene with this script as its strategy (Play).

public virtual void Setup(SimulationRun run)

In a scene run, called on the new game before its first step: set flags or save data (run.Game.SetFlag, run.Game.SaveData), change its components, or set run.Game.Time.Scale for coarser steps where that’s safe.