Prevent RandomAI from targeting own side with attacking moves
This commit is contained in:
parent
1f5a320090
commit
4584185a42
|
@ -1,5 +1,6 @@
|
||||||
using PkmnLib.Dynamic.Models;
|
using PkmnLib.Dynamic.Models;
|
||||||
using PkmnLib.Dynamic.Models.Choices;
|
using PkmnLib.Dynamic.Models.Choices;
|
||||||
|
using PkmnLib.Static.Moves;
|
||||||
using PkmnLib.Static.Utils;
|
using PkmnLib.Static.Utils;
|
||||||
|
|
||||||
namespace PkmnLib.Dynamic.AI;
|
namespace PkmnLib.Dynamic.AI;
|
||||||
|
@ -20,11 +21,15 @@ public class RandomAI : PokemonAI
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override ITurnChoice GetChoice(IBattle battle, IPokemon pokemon)
|
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)
|
while (moves.Count > 0)
|
||||||
{
|
{
|
||||||
var move = moves[_random.GetInt(moves.Count)];
|
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)
|
if (targets.Length == 0)
|
||||||
{
|
{
|
||||||
moves.Remove(move);
|
moves.Remove(move);
|
||||||
|
|
Loading…
Reference in New Issue