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
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.
Encodes a Tuning configuration record into formatted JSON text.
Reads the tuning at file, or the shipped defaults if there is not one yet.
Clamps all values of a Tuning record to their legal bounds to prevent unplayable state.