Implements AI Switching
All checks were successful
Build / Build (push) Successful in 58s

This commit is contained in:
2025-07-12 13:03:00 +02:00
parent 364d4b9080
commit bf83b25238
34 changed files with 903 additions and 226 deletions

View File

@@ -5,6 +5,8 @@ using PkmnLib.Dynamic.AI;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Plugin.Gen7;
using Serilog;
using Serilog.Core;
using Serilog.Events;
namespace AIRunner;
@@ -12,9 +14,12 @@ internal static class Program
{
private static List<PokemonAI>? _availableAIs;
internal static LoggingLevelSwitch LogLevelSwitch { get; } = new(LogEventLevel.Information);
private static Task<int> Main(string[] args)
{
Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console().CreateLogger();
Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(LogLevelSwitch).WriteTo.Console()
.CreateLogger();
Log.Information("Starting AI Runner...");
AILogging.LogHandler = Log.Debug;
var library = DynamicLibraryImpl.Create([
@@ -24,6 +29,10 @@ internal static class Program
var testCommand = new Command("test", "Run two AIs against each other")
{
new Option<bool>("--debug")
{
Description = "Enable debug logging.",
},
new Option<string>("--ai1")
{
Description = "The name of the first AI script to run against the second AI.",
@@ -55,6 +64,9 @@ internal static class Program
};
testCommand.SetAction(result =>
{
var debug = result.GetValue<bool>("--debug");
LogLevelSwitch.MinimumLevel = debug ? LogEventLevel.Debug : LogEventLevel.Information;
var ai1Name = result.GetRequiredValue<string>("--ai1");
var ai2Name = result.GetRequiredValue<string>("--ai2");
var ai1 = _availableAIs!.First(a =>

View File

@@ -32,6 +32,7 @@ public static class TestCommandRunner
randoms[i] = new RandomImpl(rootRandom.GetInt());
battleTasks[i] = Task.CompletedTask; // Initialize tasks to avoid null references
}
const int pokemonPerParty = 6;
// Show a progress bar if debug logging is not enabled.
// We disable this if debug logging is on, to prevent annoying console output where the progress bar is drawn in
@@ -55,7 +56,7 @@ public static class TestCommandRunner
{
Log.Debug("Battle {BattleNumber}: {AI1} vs {AI2}", index + 1, ai1.Name, ai2.Name);
var random = randoms[taskIndex];
var battle = GenerateBattle(library, 3, random);
var battle = GenerateBattle(library, pokemonPerParty, random);
var timePerTurn = new List<double>(20);
while (!battle.HasEnded)
{