Tweaks and fixes

This commit is contained in:
2025-07-05 18:27:42 +02:00
parent d57076374f
commit 83f6a183e3
4 changed files with 33 additions and 4 deletions

View File

@@ -19,14 +19,15 @@ public static class TestCommandRunner
var library = DynamicLibraryImpl.Create([
new Gen7Plugin(),
]);
const int maxTasks = 10;
Log.Information("Running {Battles} battles between {AI1} and {AI2}", battles, ai1.Name, ai2.Name);
var averageTimePerTurnPerBattle = new List<double>(battles);
var turnsPerBattle = new ConcurrentBag<uint>();
var results = new ConcurrentBag<BattleResult>();
var timePerBatch = new List<double>(battles / maxTasks);
var rootRandom = new RandomImpl();
const int maxTasks = 10;
var battleTasks = new Task[maxTasks];
var randoms = new IRandom[maxTasks];
for (var i = 0; i < maxTasks; i++)
@@ -36,7 +37,8 @@ public static class TestCommandRunner
}
// Show a progress bar if debug logging is not enabled.
// This is to avoid weird console output where the progress bar is drawn in the middle of debug logs.
// We disable this if debug logging is on, to prevent annoying console output where the progress bar is drawn in
// the middle of debug logs.
ProgressBar? pb = null;
if (!Log.IsEnabled(LogEventLevel.Debug))
{
@@ -47,6 +49,7 @@ public static class TestCommandRunner
});
pb.EstimatedDuration = TimeSpan.FromMilliseconds(battles);
}
var batchStartTime = DateTime.UtcNow;
for (var i = 0; i < battles; i++)
{
var taskIndex = i % maxTasks;
@@ -87,6 +90,14 @@ public static class TestCommandRunner
await Task.WhenAll(battleTasks);
Log.Debug("Batch of {TaskCount} tasks completed", maxTasks);
Array.Fill(battleTasks, Task.CompletedTask); // Reset tasks for the next batch
var batchTime = (DateTime.UtcNow - batchStartTime).TotalMilliseconds;
if (pb != null)
{
timePerBatch.Add(batchTime);
pb.EstimatedDuration = TimeSpan.FromMilliseconds(timePerBatch.Average() * battles / maxTasks);
}
batchStartTime = DateTime.UtcNow; // Reset batch start time after each batch
}
}
pb?.Dispose();