Prevent RandomAI from targeting own side with attacking moves

This commit is contained in:
Deukhoofd 2025-01-10 10:09:35 +01:00
parent 1f5a320090
commit 4584185a42
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 7 additions and 2 deletions

View File

@ -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
/// <inheritdoc />
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);