////// What one benchmarked game came to.////// `ticks` is here so every other number can be turned into a rate. Totals on their own are/// what made three separate measurements in this project's history say the opposite of the/// truth: a change that ends games sooner posts fewer deaths and fewer row drops while being/// strictly worse, and the totals look like an improvement.///pubtypealiasOutcome = { seed = Int64, level = Int32, score = Int32, lives = Int32, deaths = Int32, kills = Int32, drops = Int32, ticks = Int32, invaded = Bool, endgame = Endgame}/// The bot's movement and progress while eight or fewer invaders remain in a formation.pubtypealiasEndgame = {pixels = Float32, ticks = Int32, kills = Int32}////// Measuring the computer player.////// The demo bot carries a dozen interacting constants -- how wide a bomb has to pass to count/// as a threat, what standing in cover costs, how long it holds one judgement, when it stops/// tidying the flanks -- and none of them can be reasoned about reliably in isolation./// Widening the threat corridor from 30px to 60px cut deaths sixfold, which no amount of/// reading the code would have suggested. A more sophisticated dodge, which predicted where/// the cannon would be when each bomb landed, measured *worse* at every tuning.////// So the constants get measured, not argued about, and this is what does the measuring. Run/// it with `bin/bench`.////// The measurement itself is pure: `one` discharges `Game.step`'s `Sound` effect with/// `Sound.runWithNoOp`, and the bot is a pure function of the world and its own hand. Given a/// tuning and its fixed seeds, the benchmark is an ordinary fold with reproducible results.///mod Bench {use Util.GetOpt.{ArgDescr, ArgOrder, OptionDescr, getOpt1, usageInfo}////// The seeds a run reports on.////// Fixed, and more of them than feels necessary. Bomb luck moves a single seed by two/// whole levels, so a change measured on three seeds is measuring noise -- and the/// temptation, having got a pleasing number, is to stop.///pubdefseeds(): List[Int64] =2026i64 :: 7i64 :: 99i64 :: 1234i64 :: 555i64 :: 31i64 :: 17i64 :: 404i64 :: 88i64 :: 5i64 :: Nil////// Sixty seeds, for deciding rather than for iterating.////// Ten games separate things that differ by a level. They do not separate things that/// differ by a third of one, which is the size of every honest improvement this bot has/// had -- and on the ten above, the narrowing rule scores 4.6 against a 4.9 baseline while/// on these it scores 4.95 against 4.52. A change adopted on ten seeds was adopted on a/// coin toss.////// Two families rather than one long run of a single multiplier, so a result cannot be an/// artifact of how the seeds were generated. They are deliberately not the ten above: the/// recorded figures in `docs/ARCHITECTURE.md` are on those, and a sample that quietly/// changed underneath them would make every number in that file incomparable.///pubdefwideSeeds(): List[Int64] = {letthirty = List.range(1, 31);letscaled = factor -> List.map(n -> Int32.toInt64(n) *factor, thirty);letfirstHalf = scaled(7919i64);letsecondHalf = scaled(104729i64);firstHalf:::secondHalf }////// How long a game may run before it is cut short.////// Generous: a good game ends on its own in well under this, and a benchmark that stops/// games itself is measuring its own budget.///pubdefbudget(): Int32 = 30000defalive(w: World): Int32 = Vector.count(inv -> inv#alive, w#invaders)defemptyEndgame(): Endgame = {pixels = 0.0f32, ticks = 0, kills = 0}////// A tick the bot can act on, with eight or fewer invaders left.////// All three figures are gated on the same condition, so they describe one regime. Counting/// ticks more loosely -- during the death pause, or through the three-second wait after a/// formation is cleared -- swept in frozen time when no kill was possible: 6120 of 21161,/// 29%, which reported 72 ticks per kill where live play costs 51. Worse than inflated, it/// was *confounded*, because a change that clears more levels buys more frozen ticks and/// looks slower for it.///defactivelyInEndgame(w: World): Bool =w#phase == Phase.Playing andw#pause ==0andalive(w) <=8defobserveEndgame(before: World, after: World, endgame: Endgame): Endgame =if (notactivelyInEndgame(before))endgameelse { pixels = endgame#pixels +Float32.abs(after#playerX -before#playerX), ticks = endgame#ticks +1,// A cleared formation is restored to 55, which would read as negative kills. kills = endgame#kills +Int32.max(0, alive(before) -alive(after)) }typealiasBenchAccumulator = { deaths = Int32, kills = Int32, drops = Int32, ticks = Int32, endgame = Endgame }////// One run in progress: the ticks left in its budget, the world, the bot's hand, and the/// figures gathered so far.///typealiasBenchState = {left = Int32, world = World, hand = Hand, acc = BenchAccumulator}////// One tick of a run: the bot decides, the world steps, and the figures take note.////// Kills and row drops are counted only while the level does not change, because a cleared/// formation is replaced wholesale -- counting across that boundary reads the restock as/// fifty-five invaders coming back to life.///defstepBench(tuning: Tuning, st: BenchState): BenchState \ Sound = {letw = st#world;letacc = st#acc;let (input, nextHand) = Demo.imperfect(tuning, w, st#hand);letstepped = Game.step(w, input);letsameLevel = stepped#level ==w#level;letnextAcc = { deaths = acc#deaths + (if (stepped#lives <w#lives) 1else0), kills = acc#kills + (if (sameLevel) alive(w) -alive(stepped) else0), drops = acc#drops + (if (sameLevelandstepped#marchDir !=w#marchDir) 1else0), ticks = acc#ticks +1, endgame = observeEndgame(w, stepped, acc#endgame) }; {left = st#left -1, world = stepped, hand = nextHand, acc = nextAcc} }////// Plays one whole game and reports what happened.////// The stopping condition is the same for every run -- the game ends, or the budget does./// Nothing is allowed to stop early on a condition that a change under test could itself/// affect. Stopping at "level 2 reached" is how a measurement of bunker damage once/// reported every bunker perfectly intact: levels reset the bunkers, so the probe was/// sampling the state immediately after the reset.////// A run that ends on the budget is reported as unfinished rather than as a result: it was/// interrupted, not measured. See `unfinished`.///pubdefone(tuning: Tuning, seed: Int64): Outcome = Sound.runWithNoOp(() -> {// A recursion rather than a fold over the budget: this stops when the *game* ends,// which is usually a third of the way in. Folding `budget()` steps would keep calling// a no-op stage for the remaining twenty thousand ticks of every run.defloop(st: BenchState) = {letdone = st#left <=0orst#world#phase == Phase.Lost;if (done) {letendg = st#acc#endgame;letreached = invasionReached(st#world);letw = st#world;leta = st#acc; { seed = seed, level = w#level, score = w#score, lives = w#lives, deaths = a#deaths, kills = a#kills, drops = a#drops, ticks = a#ticks, invaded = reached, endgame = endg } } elseloop(stepBench(tuning, st)) };letinitAcc = {deaths = 0, kills = 0, drops = 0, ticks = 0, endgame = emptyEndgame()};loop({ left = budget(), world = Game.initial(seed), hand = Demo.fresh(seed), acc = initAcc }) })/// Whether the formation reached the cannon's line, as opposed to the lives running out.definvasionReached(w: World): Bool =letlanded = inv -> inv#alive andinv#pos#y >=Rules.invasionLine();Vector.exists(landed, w#invaders)/// Runs the benchmark across the standard set of test seeds.pubdefall(tuning: Tuning): List[Outcome] = allOn(seeds(), tuning)/// Runs the benchmark across the given list of test seeds.pubdefallOn(which: List[Int64], tuning: Tuning): List[Outcome] =letrunner = one(tuning);List.map(runner, which)// -- reading the results ----------------------------------------------------------------//// Pure arithmetic on the outcomes, and the part worth testing: getting a rate wrong is how// a measurement lies convincingly./// Mean level, in tenths, so it can be reported without floating point.pubdefmeanLevelTenths(runs: List[Outcome]): Int32 =if (List.isEmpty(runs))0else {lettotalLevel = List.foldLeft((total, r) -> total+r#level, 0, runs); (totalLevel*10) /List.length(runs) }/// Returns the lowest level reached across all benchmark runs.pubdefworstLevel(runs: List[Outcome]): Int32 = {letstartWorst = Int32.maxValue();List.foldLeft((worst, r) -> Int32.min(worst, r#level), startWorst, runs) }/// Returns the highest level reached across all benchmark runs.pubdefbestLevel(runs: List[Outcome]): Int32 =List.foldLeft((best, r) -> Int32.max(best, r#level), 0, runs)/// Returns the total ticks elapsed across all benchmark runs.pubdeftotalTicks(runs: List[Outcome]): Int32 =List.foldLeft((total, r) -> total+r#ticks, 0, runs)////// A count per ten thousand ticks of play, in tenths.////// Always compare rates. Two configurations that end their games at different times cannot/// be compared on totals, and the difference in when they end is usually the very thing/// being measured.////// Per ten thousand rather than per thousand, and in tenths, because of the rarest event/// that matters. Deaths run at about four across seventy-eight thousand ticks; per thousand/// in tenths that prints as 0.0, which is what a bot dying twenty-four times also printed/// before it was fixed. A scale that cannot show the improvement it was built to detect is/// no better than no scale.///////// `count` per 10 000 ticks, in tenths.////// Widened to `Int64` for the multiplication, which is not defensive: `count * 100000`/// leaves `Int32` above 21 474, and a sixty-seed run of the shipped bot reports 24 871/// kills. It printed as `-277.-8` per 10 000 ticks -- visibly broken, which was luck. An/// overflow a little smaller would have printed a plausible number instead.///pubdefrateTenths(count: Int32, ticks: Int32): Int32 =if (ticks<=0)0else {letwide = Int32.toInt64(count) *100000i64/Int32.toInt64(ticks);matchInt64.tryToInt32(wide) {case Some(rate) => ratecase None => Int32.maxValue() } }/// A tenths value as `X.Y`.pubdefshowTenths(tenths: Int32): String = "${tenths / 10}.${Int32.remainder(tenths, 10)}"/// Returns total player deaths across all benchmark runs.pubdefdeaths(runs: List[Outcome]): Int32 =List.foldLeft((total, r) -> total+r#deaths, 0, runs)/// Returns total invader kills across all benchmark runs.pubdefkills(runs: List[Outcome]): Int32 =List.foldLeft((total, r) -> total+r#kills, 0, runs)/// Returns total row drops across all benchmark runs.pubdefdrops(runs: List[Outcome]): Int32 =List.foldLeft((total, r) -> total+r#drops, 0, runs)/// Aggregates endgame statistics across all benchmark runs.pubdefendgame(runs: List[Outcome]): Endgame =List.foldLeft( (total, r) -> { pixels = total#pixels +r#endgame#pixels, ticks = total#ticks +r#endgame#ticks, kills = total#kills +r#endgame#kills },emptyEndgame(),runs )////// How far the cannon walked, and how long it took, per invader killed in the endgame.////// The pair is the point. A change that makes the bot walk less is only an improvement if/// it does not take longer to kill: down-weighting hard-to-reach targets once cut pixels/// per kill from 139 to 130 while raising ticks per kill from 72 to 76, and was rejected/// on exactly that reading. Both are rates, so neither can be flattered by a shorter game.////// Nought when nothing was killed, which is the honest answer to a ratio with no/// denominator -- an infinity here would sort as the best run ever measured.///pubdefpixelsPerKill(endgame: Endgame): Float32 =if (endgame#kills <=0) 0.0f32elseendgame#pixels /Int32.toFloat32(endgame#kills)/// The other half of the pair above.pubdefticksPerKill(endgame: Endgame): Float32 =if (endgame#kills <=0)0.0f32elseInt32.toFloat32(endgame#ticks) /Int32.toFloat32(endgame#kills)/// How many games ended with the formation landing rather than the lives running out.pubdefinvasions(runs: List[Outcome]): Int32 = List.count(r -> r#invaded, runs)/// How many games hit the budget instead of finishing, which invalidates the run.pubdefunfinished(runs: List[Outcome]): Int32 = List.count(r -> r#ticks >=budget(), runs)// -- judging one tuning ------------------------------------------------------------------////// A single number for a tuning, so candidates can be ranked.////// Mean level dominates, because clearing formations is what the game is. The worst seed/// breaks ties, and it earns its place: more than one tuning has lifted the mean while/// dropping a seed two levels, and a demo that collapses one game in six looks broken/// rather than fallible. Deaths break the remaining ties -- of two tunings that reach the/// same levels, prefer the one that is not being hit.///pubdefmerit(runs: List[Outcome]): Int32 = {letticks = totalTicks(runs);meanLevelTenths(runs) *1000+worstLevel(runs) *100-rateTenths(deaths(runs), ticks) }////// The merit of a tuning over the standard seeds, which is what the search maximises.////// Always the same seeds, so two tunings are compared on the same games rather than on/// their luck. `bin/bench --wide` then plays a set that shares no seed with this one, and/// that is what a claim has to survive: a win here alone may only mean the tuning has been/// fitted to these ten games.///pubdefscore(tuning: Tuning): Int32 = merit(all(tuning))deftryKnob(current: (Tuning, Int32), adjust: List[Tuning -> Tuning]): (Tuning, Int32) = {let (curT, curS) = current;letcandidates = List.map(f -> Tuning.sane(f(curT)), adjust);List.foldLeft( (inner, candidate) -> {let (held, heldScore) = inner;lettrial = score(candidate);if (trial>heldScore) (candidate, trial) else (held, heldScore) }, (curT, curS),candidates ) }////// Improves one parameter at a time, keeping any change that scores better.////// Coordinate descent rather than anything cleverer, because the expensive part is playing/// the games and the surface is not smooth enough for gradients to mean much. Each/// parameter is offered a few multiples of its current value; the best wins and the search/// moves on carrying that improvement.////// Bounded and deterministic: the same build searches the same way every time, so a/// `--recalc` can be repeated and checked.///pubdefrecalc(rounds: Int32, start: Tuning): (Tuning, Int32) \ IO = {defsweep(remaining, best, bestScore) =if (remaining<=0) (best, bestScore)else {let (improved, improvedScore) = List.foldLeft(tryKnob, (best, bestScore), knobs());println(" round ${rounds-remaining+1}: merit ${improvedScore}"+ (if (improvedScore>bestScore) ""else" (no improvement)") );if (improvedScore<=bestScore) (best, bestScore)elsesweep(remaining-1, improved, improvedScore) };sweep(rounds, start, score(start)) }/// Scales a float field up and down, and leaves it alone.defspread(): List[Float32] = 0.6f32 :: 0.8f32 :: 1.25f32 :: 1.6f32 :: Nildefbumps(): List[Int32] = -2 :: -1 :: 1 :: 2 :: Nildefscaled(value: Float32, by: Float32): Float32 = value*by////// The neighbours of a tuning, one parameter at a time.////// Grouped per parameter so the search stays coordinate-wise: each inner list is the set of/// alternatives for a single field, and the best of them is adopted before the next field/// is considered.///defknobs(): List[List[Tuning -> Tuning]] =List.map(by -> ((t: Tuning) ->letdw = scaled(t#dangerWidth, by); {dangerWidth = dw | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letsp = scaled(t#selfPreservation, by); {selfPreservation = sp | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letu = scaled(t#urgency, by); {urgency = u | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letbc = scaled(t#blockedCost, by); {blockedCost = bc | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letsr = scaled(t#shelterRelief, by); {shelterRelief = sr | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letc = scaled(t#calm, by); {calm = c | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letff = scaled(t#finishFlank, by); {finishFlank = ff | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letsa = scaled(t#startAt, by); {startAt = sa | t}),spread() ) :: List.map(by -> ((t: Tuning) ->letra = scaled(t#reverseAt, by); {reverseAt = ra | t}),spread() ) :: List.map(n -> ((t: Tuning) -> {aimJitter = t#aimJitter +n | t}), bumps()) :: List.map(n -> ((t: Tuning) -> {judgeFor = t#judgeFor +n*4 | t}), bumps()) :: List.map(n -> ((t: Tuning) -> {lapseFor = t#lapseFor +n | t}), bumps()) :: Nil// -- reporting --------------------------------------------------------------------------defpad(text: String, width: Int32): String = {letmissing = width-String.length(text);if (missing<=0)textelse {letaddSpace = (acc, _) -> acc+" ";letspaces = List.foldLeft(addSpace, "", List.range(0, missing));spaces+text } }defrow(r: Outcome): String = {letstatus = if (r#invaded) "invaded"else"out of lives";letc1 = pad("${r#seed}", 6);letc2 = pad("${r#level}", 7);letc3 = pad("${r#score}", 8);letc4 = pad("${r#lives}", 7);letc5 = pad("${r#deaths}", 8);letc6 = pad("${r#kills}", 7);letc7 = pad("${r#ticks}", 8);c1+c2+c3+c4+c5+c6+c7+" "+status }defreport(runs: List[Outcome]): Unit \ IO = {letticks = totalTicks(runs);leth1 = pad("seed", 6) +pad("level", 7) +pad("score", 8);leth2 = pad("lives", 7) +pad("deaths", 8) +pad("kills", 7);leth3 = pad("ticks", 8) +" ended by";letheader = h1+h2+h3;println(header);List.forEach(r -> println(row(r)), runs);println("");letmeanMsg =" mean level ${showTenths(meanLevelTenths(runs))}"+" (worst ${worstLevel(runs)}, best ${bestLevel(runs)})";println(meanMsg);letdRate = showTenths(rateTenths(deaths(runs), ticks));println(" deaths ${deaths(runs)} = ${dRate} per 10000 ticks");letkRate = showTenths(rateTenths(kills(runs), ticks));println(" kills ${kills(runs)} = ${kRate} per 10000 ticks");letrRate = showTenths(rateTenths(drops(runs), ticks));println(" row drops ${drops(runs)} = ${rRate} per 10000 ticks");letendg = endgame(runs);letegMsg =" <=8 invaders ${pixelsPerKill(endg)} px/kill, "+"${ticksPerKill(endg)} ticks/kill"+" (${endg#pixels} px, ${endg#ticks} ticks, ${endg#kills} kills)";println(egMsg);letendedMsg =" ended by ${invasions(runs)} invaded, "+"${List.length(runs) - invasions(runs)} out of lives";println(endedMsg);letcut = unfinished(runs);if (cut>0) {letwarnMsg =" WARNING ${cut} game(s) hit the budget and were cut short; "+"raise budget() before trusting these numbers";println(warnMsg) } else() }// -- the command line --------------------------------------------------------------------////// What the user asked for.///pubenumFlagwithEq, ToString {case Helpcase Recalc(Int32)case Config(String)case Defaultscase Wide }defdefaultRounds(): Int32 = 3////// The options, in the shape `Util.GetOpt` wants.////// `--recalc` takes its round count optionally, so `--recalc` and `--recalc 5` both work/// and neither swallows a following flag.///defswitches(): List[OptionDescr[Flag]] = {lethelpOpt = { optionIds = 'h' :: Nil, optionNames = "help" :: Nil, argDescriptor = ArgDescr.NoArg(Flag.Help), explanation = "print this message" };letparseRounds = givenOpt -> {letn =givenOpt |> Option.flatMap(Int32.fromString) |> Option.getWithDefault(defaultRounds()); Some(Flag.Recalc(n)) };letrecalcOpt = { optionIds = 'r' :: Nil, optionNames = "recalc" :: Nil, argDescriptor = ArgDescr.OptArg(parseRounds, "ROUNDS"), explanation = "search for a better tuning "+"(default ${defaultRounds()} rounds) and save it if it wins" };letconfigOpt = { optionIds = 'c' :: Nil, optionNames = "config" :: Nil, argDescriptor = ArgDescr.ReqArg(given -> Some(Flag.Config(given)), "PATH"), explanation = "use PATH instead of the file beside the high scores" };letdefaultsOpt = { optionIds = 'd' :: Nil, optionNames = "defaults" :: Nil, argDescriptor = ArgDescr.NoArg(Flag.Defaults), explanation = "ignore any config and use the tuning compiled in" };letwideOpt = { optionIds = 'w' :: Nil, optionNames = "wide" :: Nil, argDescriptor = ArgDescr.NoArg(Flag.Wide), explanation = "play ${List.length(wideSeeds())} seeds "+"instead of ${List.length(seeds())}; "+"slower, and the only sample that can settle a close call" };helpOpt :: recalcOpt :: configOpt :: defaultsOpt :: wideOpt :: Nil }defusage(): String = usageInfo("usage: bin/bench [options]", switches())/// The rounds asked for, if `--recalc` was given at all.defroundsIn(flags: List[Flag]): Option[Int32] =List.findMap(flag -> matchflag {case Flag.Recalc(n) => Some(n)case_ => None },flags )defconfigIn(flags: List[Flag]): Option[String] =List.findMap(flag -> matchflag {case Flag.Config(path) => Some(path)case_ => None },flags )/// The directory a path lives in, for creating it before a write.defparentOf(file: String): String \ Sys.Env = {letseparator = Sys.Env.getFileSeparator();matchList.reverse(String.splitOn(substr = separator, file)) {case_ :: rest => String.intercalate(separator, List.reverse(rest))case Nil => "." } }defrunSearch(configFile: Option[String], stored: Tuning, rounds: Int32): Unit \ {Fs.FileWrite,Sys.Env,IO } = {letbefore = score(stored);letseedsCount = List.length(seeds());println("Searching from merit ${before} over at most ${rounds} round(s).");println("Each round plays ${seedsCount} games per candidate; this takes a while.");let (found, foundScore) = recalc(rounds, stored);println("");report(all(found));println("");if (foundScore<=before)println("No improvement found; the config is unchanged.")elsewriteTuning(configFile, found) }defrunBenchOptions(flags: List[Flag], configFile: Option[String]): Unit \ {Fs.FileRead,Fs.FileWrite,Sys.Env,IO } = {letstored = startingTuning(flags, configFile);println(provenance(flags, configFile));matchroundsIn(flags) {case None =>letplaying = if (List.memberOf(Flag.Wide, flags)) wideSeeds() elseseeds();println("Bot benchmark -- ${List.length(playing)} seeds, budget ${budget()} ticks");println("");report(allOn(playing, stored))case Some(rounds) => runSearch(configFile, stored, rounds) } }////// Measures the demo player, and optionally searches for better numbers.///pubdefmain(): Unit \ { Fs.FileRead, Fs.FileWrite, Sys.Env, IO } = {letparsed = getOpt1(ArgOrder.Permute, switches(), Sys.Env.getArgs());lethasErrors = notList.isEmpty(parsed#errors) ornotList.isEmpty(parsed#unknowns);if (hasErrors) {letcomplaints = List.append(parsed#errors, parsed#unknowns);List.forEach(e -> println("bench: ${e}"), complaints);println(usage()) } elseif (List.memberOf(Flag.Help, parsed#options))println(usage())else {letflags = parsed#options;letconfigFile = matchconfigIn(flags) {case Some(given) => Some(given)case None => Tuning.path() };runBenchOptions(flags, configFile) } }////// Where the numbers being measured came from.////// Said out loud on every run, because the alternative was silence. `bin/bench` picks up/// `~/.config/flix-invaders/tuning.json` if it exists, so a config left behind by an/// earlier `--recalc` quietly becomes the thing every later run measures -- and a/// comparison against a `--defaults` run then differs in every field rather than the one/// under test. That happened, and the numbers it produced ranked a change backwards.///defprovenance(flags: List[Flag], configFile: Option[String]): String =if (List.memberOf(Flag.Defaults, flags))"Tuning: the compiled-in defaults (--defaults)."elsematchconfigFile {case None => "Tuning: the compiled-in defaults; no config file was found."case Some(file) =>"Tuning: ${file} if it exists, otherwise the compiled-in defaults." }////// The tuning to start from: the config, unless `--defaults` says otherwise.////// A config that cannot be read is reported and then ignored. Refusing to run because a/// tuning file is malformed would be a strange way to treat a tool whose whole job is to/// tell you whether a set of numbers is any good.///defstartingTuning(flags: List[Flag], configFile: Option[String]): Tuning \ {Fs.FileRead,IO } =if (List.memberOf(Flag.Defaults, flags))Demo.defaults()elsematchconfigFile {case None => Demo.defaults()case Some(file) => matchTuning.load(file) {case Ok(t) => tcase Err(why) =>println("could not read ${file}: ${why}; using the compiled-in defaults");Demo.defaults() } }defwriteTuning(configFile: Option[String], t: Tuning): Unit \ { Fs.FileWrite, Sys.Env, IO } =matchconfigFile {case None => println("nowhere to write a config; the tuning above was not saved")case Some(file) => matchTuning.save(file, parentOf(file), t) {case Ok(_) => println("Wrote ${file}.")case Err(why) => println("could not write ${file}: ${why}") } }}