From 4584185a42f9846d2119e070070897506f0d3674 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 10 Jan 2025 10:09:35 +0100 Subject: [PATCH] Prevent RandomAI from targeting own side with attacking moves --- PkmnLib.Dynamic/AI/RandomAI.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PkmnLib.Dynamic/AI/RandomAI.cs b/PkmnLib.Dynamic/AI/RandomAI.cs index e60a8ce..ff4623e 100644 --- a/PkmnLib.Dynamic/AI/RandomAI.cs +++ b/PkmnLib.Dynamic/AI/RandomAI.cs @@ -1,5 +1,6 @@ using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.Models.Choices; +using PkmnLib.Static.Moves; using PkmnLib.Static.Utils; namespace PkmnLib.Dynamic.AI; @@ -20,11 +21,15 @@ public class RandomAI : PokemonAI /// public override ITurnChoice GetChoice(IBattle battle, IPokemon pokemon) { - var moves = pokemon.Moves.Where(x => x?.CurrentPp > 0).ToList(); + var moves = pokemon.Moves.WhereNotNull().Where(x => x.CurrentPp > 0).ToList(); while (moves.Count > 0) { var move = moves[_random.GetInt(moves.Count)]; - var targets = GetValidTargetsForMove(pokemon, move!).ToArray(); + var targets = GetValidTargetsForMove(pokemon, move).ToArray(); + if (move.MoveData.Category is MoveCategory.Physical or MoveCategory.Special) + { + targets = targets.Where(x => x.side != pokemon.BattleData!.SideIndex).ToArray(); + } if (targets.Length == 0) { moves.Remove(move);