Adds some doc comments

This commit is contained in:
2026-07-05 14:04:01 +02:00
parent a649e58826
commit 1ab15110f5
5 changed files with 89 additions and 4 deletions

View File

@@ -6,8 +6,14 @@ using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.AI;
/// <summary>
/// Helper functions for AI
/// </summary>
public static class AIHelpers
{
/// <summary>
/// Estimates the amount of damage that will be done by a move against a target.
/// </summary>
public static uint CalculateDamageEstimation(IMoveData move, IPokemon user, IPokemon target,
IDynamicLibrary library)
{

View File

@@ -1,8 +1,18 @@
namespace PkmnLib.Dynamic.AI;
/// <summary>
/// Logging implementation for AI
/// </summary>
public static class AILogging
{
/// <summary>
/// The actual function called by the logging.
/// </summary>
public static Action<string> LogHandler { get; set; } = _ => { };
/// <summary>
/// Forwarding function.
/// </summary>
/// <param name="message"></param>
public static void LogInformation(string message) => LogHandler(message);
}

View File

@@ -3,14 +3,25 @@ using PkmnLib.Static.Moves;
namespace PkmnLib.Dynamic.AI.Explicit;
/// <summary>
/// Container wrapper for a move and its user.
/// </summary>
public class AIMoveState
{
/// <inheritdoc cref="AIMoveState" />
public AIMoveState(IPokemon user, IMoveData move)
{
User = user;
Move = move;
}
/// <summary>
/// The user that's being wrapper
/// </summary>
public IPokemon User { get; }
/// <summary>
/// The move that's being wrapper
/// </summary>
public IMoveData Move { get; }
}

View File

@@ -45,8 +45,7 @@ public partial class ExplicitAI
return false;
}
var battleSide = pokemon.BattleData!.BattleSide;
var bestReplacement =
ChooseBestReplacementPokemon(pokemon.BattleData!.Position, terribleMoves, usablePokemon, battleSide);
var bestReplacement = ChooseBestReplacementPokemon(terribleMoves, usablePokemon, battleSide);
if (bestReplacement is null)
{
AILogging.LogInformation(
@@ -57,8 +56,8 @@ public partial class ExplicitAI
return true;
}
private IPokemon? ChooseBestReplacementPokemon(byte position, bool terribleMoves,
IReadOnlyList<IPokemon> usablePokemon, IBattleSide battleSide)
private IPokemon? ChooseBestReplacementPokemon(bool terribleMoves, IReadOnlyList<IPokemon> usablePokemon,
IBattleSide battleSide)
{
var options = usablePokemon.Where((_, index) =>
{

View File

@@ -3,17 +3,35 @@ using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.AI.Explicit;
/// <summary>
/// An option where a move is used against a target
/// </summary>
public record struct MoveOption(AIMoveState Move, IBattle Battle, IPokemon? Target, uint EstimatedDamage = 0);
/// <summary>
/// A function that takes an explicit AI and a move option and returns a boolean value.
/// </summary>
public delegate bool AIBoolHandler(IExplicitAI ai, MoveOption option);
/// <summary>
/// A function for returning whether a Pokemon should switch.
/// </summary>
public delegate bool AISwitchBoolHandler(IExplicitAI ai, IPokemon pokemon, IBattle battle,
IReadOnlyList<IPokemon> reserves);
/// <summary>
/// A function for returning the base power of a move.
/// </summary>
public delegate void AIMoveBasePowerHandler(IExplicitAI ai, MoveOption option, ref int score);
/// <summary>
/// A function for returning a score
/// </summary>
public delegate void AIScoreMoveHandler(IExplicitAI ai, MoveOption option, ref int score);
/// <summary>
/// Explicit AI Handlers are a library that allow plugins to explicitly indicate AI preferences.
/// </summary>
public interface IReadOnlyExplicitAIHandlers
{
/// <summary>
@@ -86,28 +104,50 @@ public interface IReadOnlyExplicitAIHandlers
/// </summary>
void ApplyGenerateMoveAgainstTargetScoreModifiers(IExplicitAI ai, MoveOption option, ref int score);
/// <summary>
/// Functions that indicate whether a Pokemon should switch
/// </summary>
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> ShouldSwitchFunctions { get; }
/// <summary>
/// Indicates whether a Pokemon should switch into another Pokemon
/// </summary>
bool ShouldSwitch(IExplicitAI ai, IPokemon pokemon, IBattle battle, IReadOnlyList<IPokemon> reserves);
/// <summary>
/// Functions that indicate whether a Pokemon should NOT switch
/// </summary>
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> ShouldNotSwitchFunctions { get; }
/// <summary>
/// Indicates whether a Pokemon should NOT switch into another Pokemon
/// </summary>
bool ShouldNotSwitch(IExplicitAI ai, IPokemon pokemon, IBattle battle, IReadOnlyList<IPokemon> reserves);
/// <summary>
/// Scores abilities
/// </summary>
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> AbilityRanking { get; }
}
/// <inheritdoc />
public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
{
/// <inheritdoc />
IReadOnlyDictionary<StringKey, AIBoolHandler> IReadOnlyExplicitAIHandlers.MoveFailureCheck => MoveFailureCheck;
/// <summary>
/// Checks whether a move will fail
/// </summary>
public FunctionHandlerDictionary<AIBoolHandler> MoveFailureCheck { get; } = new();
/// <inheritdoc />
public bool MoveWillFail(IExplicitAI ai, StringKey functionCode, MoveOption option) =>
MoveFailureCheck.TryGetValue(functionCode, out var handler) && handler(ai, option);
/// <summary>
/// Checks whether a move will fail against a target
/// </summary>
public FunctionHandlerDictionary<AIBoolHandler> MoveFailureAgainstTargetCheck { get; } = new();
/// <inheritdoc />
@@ -118,12 +158,18 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
public bool MoveWillFailAgainstTarget(IExplicitAI ai, StringKey functionCode, MoveOption option) =>
MoveFailureAgainstTargetCheck.TryGetValue(functionCode, out var handler) && handler(ai, option);
/// <summary>
/// Functions to score a move
/// </summary>
public FunctionHandlerDictionary<AIScoreMoveHandler> MoveEffectScore { get; } = [];
/// <inheritdoc />
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.MoveEffectScore =>
MoveEffectScore;
/// <summary>
/// Functions to score a move against a target
/// </summary>
public FunctionHandlerDictionary<AIScoreMoveHandler> MoveEffectAgainstTargetScore = [];
/// <inheritdoc />
@@ -137,6 +183,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.MoveEffectAgainstTargetScore =>
MoveEffectAgainstTargetScore;
/// <summary>
/// Functions that indicate a moves base power
/// </summary>
public FunctionHandlerDictionary<AIMoveBasePowerHandler> MoveBasePower = [];
/// <inheritdoc />
@@ -150,6 +199,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
IReadOnlyDictionary<StringKey, AIMoveBasePowerHandler> IReadOnlyExplicitAIHandlers.MoveBasePower =>
MoveBasePower;
/// <summary>
/// Functions that indicate a moves score
/// </summary>
public FunctionHandlerDictionary<AIScoreMoveHandler> GeneralMoveScore = [];
/// <inheritdoc />
@@ -193,6 +245,7 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> IReadOnlyExplicitAIHandlers.ShouldSwitchFunctions =>
ShouldSwitchFunctions;
/// <inheritdoc />
public bool ShouldSwitch(IExplicitAI ai, IPokemon pokemon, IBattle battle, IReadOnlyList<IPokemon> reserves)
{
var shouldSwitch = false;
@@ -203,6 +256,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
return shouldSwitch;
}
/// <summary>
/// Functions that indicate whether we should not switch
/// </summary>
public FunctionHandlerDictionary<AISwitchBoolHandler> ShouldNotSwitchFunctions = [];
/// <inheritdoc />
@@ -210,6 +266,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> IReadOnlyExplicitAIHandlers.ShouldNotSwitchFunctions =>
ShouldNotSwitchFunctions;
/// <summary>
/// Functions to rank an ability
/// </summary>
public FunctionHandlerDictionary<AIScoreMoveHandler> AbilityRanking = [];
/// <inheritdoc />