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

@@ -40,7 +40,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
public uint CalculateBoostedStat(IPokemon pokemon, Statistic stat)
{
var flatStat = CalculateFlatStat(pokemon, stat);
var boostModifier = GetStatBoostModifier(pokemon, stat);
var boostModifier = GetStatBoostModifier(pokemon.StatBoost.GetStatistic(stat));
var boostedStat = flatStat * boostModifier;
if (boostedStat > uint.MaxValue)
boostedStat = uint.MaxValue;
@@ -71,13 +71,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
if (ignoreEvasion)
targetEvasion = 0;
var userAccuracy = executingMove.User.StatBoost.Accuracy;
var difference = targetEvasion - userAccuracy;
var statModifier = difference switch
{
> 0 => 3.0f / (3.0f + Math.Min(difference, 6)),
< 0 => 3.0f + -Math.Max(difference, -6) / 3.0f,
_ => 1.0f,
};
var statModifier = GetAccuracyEvasionStatModifier(targetEvasion, userAccuracy);
modifiedAccuracy = (int)(modifiedAccuracy * statModifier);
modifiedAccuracy = modifiedAccuracy switch
{
@@ -116,10 +110,9 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
return (uint)modified;
}
private static float GetStatBoostModifier(IPokemon pokemon, Statistic statistic)
public static float GetStatBoostModifier(sbyte amount)
{
var boost = pokemon.StatBoost.GetStatistic(statistic);
return boost switch
return amount switch
{
-6 => 2.0f / 8.0f,
-5 => 2.0f / 7.0f,
@@ -134,7 +127,18 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
4 => 6.0f / 2.0f,
5 => 7.0f / 2.0f,
6 => 8.0f / 2.0f,
_ => throw new ArgumentException($"Stat boost was out of expected range of -6 to 6: {boost}"),
_ => throw new ArgumentException($"Stat boost was out of expected range of -6 to 6: {amount}"),
};
}
public static float GetAccuracyEvasionStatModifier(sbyte evasion, sbyte accuracy)
{
var difference = evasion - accuracy;
return difference switch
{
> 0 => 3.0f / (3.0f + Math.Min(difference, 6)),
< 0 => 3.0f + -Math.Max(difference, -6) / 3.0f,
_ => 1.0f,
};
}
}