diff options
| author | godosa <godosa@godosa.eu> | 2026-10-06 23:39:36 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-06 23:39:36 +0200 |
| commit | 39066900773e7857faf2d02e7ed51b71d219d97d (patch) | |
| tree | ffab8e4ddd971626776c3b1f4ce1da2c186c2187 /src/Godosa.Core/Runs/RunFlags.cs | |
| download | godosa-engine-39066900773e7857faf2d02e7ed51b71d219d97d.tar.gz godosa-engine-39066900773e7857faf2d02e7ed51b71d219d97d.zip | |
godosa-engine: initial public history
Diffstat (limited to 'src/Godosa.Core/Runs/RunFlags.cs')
| -rw-r--r-- | src/Godosa.Core/Runs/RunFlags.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Godosa.Core/Runs/RunFlags.cs b/src/Godosa.Core/Runs/RunFlags.cs new file mode 100644 index 0000000..1eca433 --- /dev/null +++ b/src/Godosa.Core/Runs/RunFlags.cs @@ -0,0 +1,39 @@ +using System.Globalization; + +namespace Godosa.Core.Runs; + +/// <summary>Shared run flags: <c>--deterministic [seed]</c> (fixed step, seeded streams), <c>--digest [every=N]</c> +/// (state hash lines), <c>--headless</c> (no window; implies deterministic). <see cref="Seed"/> null = the game's default.</summary> +public sealed record RunFlags(bool Deterministic = false, ulong? Seed = null, bool Digest = false, int DigestEvery = 0, bool Headless = false) +{ + public ulong SeedOr(ulong fallback) => Seed ?? fallback; + + /// <summary>Consumes the run flag at <paramref name="i"/> (and its optional value, advancing <paramref name="i"/>); + /// false when <c>args[i]</c> is no run flag.</summary> + public static bool TryTake(IReadOnlyList<string> args, ref int i, ref RunFlags flags) + { + string? next = i + 1 < args.Count ? args[i + 1] : null; + switch (args[i]) + { + case "--deterministic": + flags = flags with { Deterministic = true }; + if (next != null && ulong.TryParse(next, NumberStyles.None, CultureInfo.InvariantCulture, out var seed)) + (flags, i) = (flags with { Seed = seed }, i + 1); + return true; + case "--digest": + flags = flags with { Digest = true }; + if (next != null && next.StartsWith("every=", StringComparison.Ordinal)) + { + if (!int.TryParse(next.AsSpan(6), NumberStyles.None, CultureInfo.InvariantCulture, out var every) || every < 1) + throw new ArgumentException($"--digest {next}: every=N needs N ≥ 1"); + (flags, i) = (flags with { DigestEvery = every }, i + 1); + } + return true; + case "--headless": + flags = flags with { Headless = true, Deterministic = true }; + return true; + default: + return false; + } + } +} |
