aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/src/Godosa.Core/Runs/RunFlags.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Godosa.Core/Runs/RunFlags.cs')
-rw-r--r--src/Godosa.Core/Runs/RunFlags.cs39
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;
+ }
+ }
+}