Skip to main content

autobalance

Function autobalance 

Source
pub fn autobalance<S: Clone, R: Sides>(
    stage: &S,
    knobs: &[&dyn Knob<S>],
    entrants: &[&dyn Entrant<S, R>],
    checks: &[Check],
    settings: &BalanceSettings,
) -> Result<Balanced<S>, PlaytestError<R>>
where R::Command: Clone, R::Outcome: Debug,
Expand description

Changes stage with knobs until every rate check of checks puts every one of entrants inside its band, as settings says. The entrants and the checks are never changed: only the stage is.

All deterministic:

  1. Before: the stage as authored plays at settings.tries. In every band already, it stops (Stop::AlreadyInBands).
  2. Pattern search at settings.quick tries, from every knob at 0, each knob’s stride its Knob::stride: in knob order, +stride then -stride (clamped to the range, skipping a step that doesn’t move or that a knob can’t apply). The first step that lowers the distance is taken and the knob order starts again. When none does, every stride above 1 is halved; when every stride is 1, it stops (Stop::Stuck).
  3. Confirm: a setting in every band at quick plays at tries. In every band there too, it is pruned; if not, the pattern search carries on at tries from there.
  4. Prune: each changed knob in order is tried at 0, then nearer 0 one step at a time, keeping each change that stays in every band at tries (Stop::InBands). What is left is the smallest change set this search found, not one proved the smallest.
  5. Budget: every run of the playtest runner is one evaluation, and a setting is never run twice at one try count. When the evaluations run out, it stops (Stop::Budget) with the best setting seen, kept back one evaluation to play it at tries.

A setting that ends no nearer its bands at tries than the stage as authored is dropped: the result is then the stage as authored.

A check naming an entrant not in the run fails before any try is played; a refused command stops the search.

It is autobalance_by, each setting played by playtest::run, never told to stop.