Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -18,9 +18,9 @@ public class PrescientAI : PokemonAI
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ITurnChoice GetChoice(IBattle battle, IPokemon pokemon)
|
||||
public override ITurnChoice GetChoice(IBattle battle, IBattlePokemon pokemon)
|
||||
{
|
||||
var opponentSide = pokemon.BattleData!.SideIndex == 0 ? (byte)1 : (byte)0;
|
||||
var opponentSide = pokemon.SideIndex == 0 ? (byte)1 : (byte)0;
|
||||
var moves = pokemon.Moves.WhereNotNull().Where(x => battle.CanUse(new MoveChoice(pokemon, x, opponentSide, 0)))
|
||||
.ToList();
|
||||
|
||||
@@ -34,13 +34,13 @@ public class PrescientAI : PokemonAI
|
||||
}
|
||||
|
||||
private static IEnumerable<(ITurnChoice Choice, float Score)> ScoreChoices(IBattle battle,
|
||||
IReadOnlyList<ILearnedMove> moves, IPokemon pokemon)
|
||||
IReadOnlyList<ILearnedMove> moves, IBattlePokemon pokemon)
|
||||
{
|
||||
var opponentSide = pokemon.BattleData!.SideIndex == 0 ? (byte)1 : (byte)0;
|
||||
var opponentSide = pokemon.SideIndex == 0 ? (byte)1 : (byte)0;
|
||||
foreach (var learnedMoveOriginal in moves.WhereNotNull())
|
||||
{
|
||||
var battleClone = battle.DeepClone();
|
||||
var pokemonClone = battleClone.Sides[pokemon.BattleData!.SideIndex].Pokemon[pokemon.BattleData.Position]!;
|
||||
var pokemonClone = battleClone.Sides[pokemon.SideIndex].Pokemon[pokemon.Position]!;
|
||||
var learnedMove = pokemonClone.Moves.WhereNotNull()
|
||||
.First(m => m.MoveData.Name == learnedMoveOriginal.MoveData.Name);
|
||||
var choice = new MoveChoice(pokemonClone, learnedMove, opponentSide, 0);
|
||||
@@ -57,17 +57,16 @@ public class PrescientAI : PokemonAI
|
||||
}
|
||||
if (battleClone.TrySetChoice(choice))
|
||||
{
|
||||
var score = CalculateScore(battleClone.Parties[pokemon.BattleData.SideIndex],
|
||||
battleClone.Parties[opponentSide]);
|
||||
var score = CalculateScore(battleClone.Parties[pokemon.SideIndex], battleClone.Parties[opponentSide]);
|
||||
var realChoice = new MoveChoice(pokemon, learnedMoveOriginal, opponentSide, 0);
|
||||
yield return (realChoice, score);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ITurnChoice GetOpponentChoice(IBattle battle, IPokemon pokemon)
|
||||
private static ITurnChoice GetOpponentChoice(IBattle battle, IBattlePokemon pokemon)
|
||||
{
|
||||
var opponentSide = pokemon.BattleData!.SideIndex == 0 ? (byte)1 : (byte)0;
|
||||
var opponentSide = pokemon.SideIndex == 0 ? (byte)1 : (byte)0;
|
||||
var opponent = battle.Sides[opponentSide].Pokemon[0];
|
||||
if (opponent is null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user