Getting started with implementing an explicit AI, based on the Essentials one.
All checks were successful
Build / Build (push) Successful in 1m2s
All checks were successful
Build / Build (push) Successful in 1m2s
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user