Getting started with implementing an explicit AI, based on the Essentials one.
All checks were successful
Build / Build (push) Successful in 1m2s

This commit is contained in:
2025-07-11 17:03:08 +02:00
parent 084ae84130
commit a3a4993407
56 changed files with 2687 additions and 1274 deletions

View File

@@ -1,3 +1,4 @@
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Static.Moves;
@@ -96,4 +97,20 @@ public abstract class PokemonAI
yield break;
byte GetOppositeSide(byte side) => side == 0 ? (byte)1 : (byte)0;
}
public static List<PokemonAI> InstantiateAis(IDynamicLibrary library)
{
return AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(PokemonAI)) && !type.IsAbstract).Select(x =>
{
var ctorWithLibrary = x.GetConstructor([typeof(IDynamicLibrary)]);
if (ctorWithLibrary != null)
return Activator.CreateInstance(x, library);
var defaultCtor = x.GetConstructor(Type.EmptyTypes);
if (defaultCtor != null)
return Activator.CreateInstance(x);
throw new InvalidOperationException($"No suitable constructor found for {x.Name}. " +
"Ensure it has a constructor with IDynamicLibrary parameter or a default constructor.");
}).Cast<PokemonAI>().ToList();
}
}