using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Luneraria.Core;
///
/// Measures the C# rules: one combat step at representative maximum occupation (round 13,
/// six armies at the supply cap, the same fixture as the Godot benchmark probe) and complete
/// bot matches. Usage: dotnet run -c Release --project tools/dotnet/Luneraria.Core.Bench [out.json]
///
public static class Program
{
public static int Main(string[] args)
{
var probe = new LuneMatch();
probe.Setup(new MatchOptions { Seed = 5, HumanSlot = -1 });
probe.RoundNumber = 13;
for (int slot = 0; slot < 6; slot++)
{
probe.Players[slot].Draft.Gold = 100000;
LuneBot.Plan(probe, slot, "ausgewogen");
}
probe.BeginCombat();
int units = probe.Combat.MobileCount();
for (int i = 0; i < 50; i++)
probe.StepCombat();
var samples = new List();
for (int block = 0; block < 5; block++)
{
var fresh = new LuneMatch();
fresh.Setup(new MatchOptions { Seed = 5, HumanSlot = -1 });
fresh.RoundNumber = 13;
for (int slot = 0; slot < 6; slot++)
{
fresh.Players[slot].Draft.Gold = 100000;
LuneBot.Plan(fresh, slot, "ausgewogen");
}
fresh.BeginCombat();
var clock = Stopwatch.StartNew();
for (int i = 0; i < 200; i++)
fresh.StepCombat();
clock.Stop();
samples.Add(clock.Elapsed.TotalMilliseconds / 200.0);
}
samples.Sort();
double stepMs = samples[samples.Count / 2];
var matchClock = Stopwatch.StartNew();
int rounds = 0;
foreach (int seed in new[] { 1, 2, 3 })
{
var match = new LuneMatch();
match.Setup(new MatchOptions { Seed = seed, HumanSlot = -1 });
while (match.Phase != Phase.Over && match.RoundNumber <= 60)
{
for (int slot = 0; slot < 6; slot++)
LuneBot.Plan(match, slot);
match.BeginCombat();
match.FinishCombat();
rounds++;
}
}
matchClock.Stop();
string json = string.Format(System.Globalization.CultureInfo.InvariantCulture,
"{{\n \"runtime\": \"{0}\",\n \"cpu\": \"{1}\",\n \"mobile_units_at_start\": {2},\n \"sim_step_ms_median\": {3:0.0000},\n \"step_blocks_ms\": [{4}],\n \"bot_matches_seeds_1_2_3_ms\": {5:0.0},\n \"bot_match_rounds\": {6},\n \"ms_per_round\": {7:0.00}\n}}\n",
System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription, System.Runtime.InteropServices.RuntimeInformation.OSArchitecture,
units, stepMs, string.Join(", ", samples.ConvertAll(s => s.ToString("0.0000", System.Globalization.CultureInfo.InvariantCulture))),
matchClock.Elapsed.TotalMilliseconds, rounds, matchClock.Elapsed.TotalMilliseconds / rounds);
Console.Write(json);
if (args.Length > 0)
File.WriteAllText(args[0], json);
return 0;
}
}