flix

0.81.0

Tuning

Reading and writing the demo player's numbers.

Laid out like Scores, and for the same reason: deciding what a tuning is stays pure and needs no handler to test, and only load and save touch a filesystem.

The file is JSON because it is meant to be edited by hand as well as by bin/bench --recalc. Every field is optional on the way in and falls back to the shipped default, so a file naming one parameter is a valid file -- which is what you want when trying a single change, and it means a config written by an older build still loads.

stragglers is the one number that is not in the file, in either direction. It decides whether the bot finishes off a flank column at all, and switching it off is worth about half a level -- so a search that is allowed to write it turns it off, and a config carrying that then silently removes the behaviour from the game. It did exactly that once: the demo went back to leaving the formation at full width, and the cause was a stale config rather than any code. Tuned numbers live in the file; decisions about how the demo behaves live in Demo.defaults, where changing them is a visible edit. Ignoring the key on the way in also means the configs already written with it recover on their own.

Definitions

def decode(base: Tuning, text: String): Result[String, Tuning]§ Source

Reads a tuning, filling anything missing from base.

Only malformed JSON is an error. A field that is absent, or present with the wrong kind of value, quietly takes the default: this file is a set of overrides, and a typo in one number should cost you that number rather than the whole run.

def encode(t: Tuning): String§ Source

Encodes a Tuning configuration record into formatted JSON text.

def load(file: String): Result[String, Tuning] \ FileRead§ Source

Reads the tuning at file, or the shipped defaults if there is not one yet.

def path(): Option[String] \ Env§ Source

The default path, beside the high scores.

def sane(t: Tuning): Tuning§ Source

Clamps all values of a Tuning record to their legal bounds to prevent unplayable state.

def save(file: String, dir: String, t: Tuning): Result[String, Unit] \ FileWrite§ Source

Serializes and writes a Tuning configuration record to disk at the specified path.