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

This commit is contained in:
Deukhoofd committed 2025-07-11 17:03:08 +02:00
1 parent 084ae84130
commit a3a4993407
56 files changed
+2687 -1274

No files matched your search

+17
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();
}
}