diff --git a/src/DepthSearchAI.hpp b/src/DepthSearchAI.hpp index 4198569..f051383 100644 --- a/src/DepthSearchAI.hpp +++ b/src/DepthSearchAI.hpp @@ -68,7 +68,10 @@ namespace PkmnLibAI { auto side = user->GetBattleSide().GetValue(); for (u8 moveIndex = 0; moveIndex < (u8)user->GetMoves().Count(); ++moveIndex) { auto move = user->GetMoves()[moveIndex]; - if (move->GetRemainingUses() == 0) { + if (!move.HasValue()) { + continue; + } + if (move.GetValue()->GetRemainingUses() == 0) { continue; } threadPool.push_back(std::async([=] { @@ -105,7 +108,11 @@ namespace PkmnLibAI { auto side = user->GetBattleSide().GetValue(); for (u8 moveIndex = 0; moveIndex < (u8)user->GetMoves().Count(); ++moveIndex) { auto move = user->GetMoves()[moveIndex]; - if (move->GetRemainingUses() == 0) { + if (!move.HasValue()) { + continue; + } + + if (move.GetValue()->GetRemainingUses() == 0) { continue; } auto scored = SimulateTurn(battle, side->GetSideIndex(), 0, moveIndex, depth); @@ -134,7 +141,7 @@ namespace PkmnLibAI { auto target = GetOppositeIndex(user); if (index < 4) { auto move = user->GetMoves()[index]; - auto choice = new CreatureLib::Battling::AttackTurnChoice(user, move, target); + auto choice = new CreatureLib::Battling::AttackTurnChoice(user, move.GetValue(), target); if (!battle->TrySetChoice(choice)) { delete choice; return std::numeric_limits::min(); @@ -197,7 +204,7 @@ namespace PkmnLibAI { } if (highest < 4) { - return new CreatureLib::Battling::AttackTurnChoice(user, user->GetMoves()[highest], target); + return new CreatureLib::Battling::AttackTurnChoice(user, user->GetMoves()[highest].GetValue(), target); } else { return new CreatureLib::Battling::SwitchTurnChoice(user, party.At(highest - 4)); } diff --git a/src/NaiveAI.hpp b/src/NaiveAI.hpp index 798fe89..a327400 100644 --- a/src/NaiveAI.hpp +++ b/src/NaiveAI.hpp @@ -15,18 +15,21 @@ namespace PkmnLibAI { auto highestScore = -1; PkmnLib::Battling::LearnedMove* bestMove; for (auto move : user->GetMoves()) { - if (move->GetRemainingUses() <= 0) + if (!move.HasValue()) { continue; - auto naiveDamage = - move->GetMoveData()->GetBasePower() * battle->GetLibrary()->GetTypeLibrary()->GetEffectiveness( - move->GetMoveData()->GetType(), c->GetTypes()); - if (naiveDamage > highestScore){ + } + if (move.GetValue()->GetRemainingUses() <= 0) + continue; + auto naiveDamage = move.GetValue()->GetMoveData()->GetBasePower() * + battle->GetLibrary()->GetTypeLibrary()->GetEffectiveness( + move.GetValue()->GetMoveData()->GetType(), c->GetTypes()); + if (naiveDamage > highestScore) { highestScore = naiveDamage; bestMove = move; } } - if (highestScore == -1){ + if (highestScore == -1) { return battle->GetLibrary()->GetMiscLibrary()->ReplacementAttack(user, target); } diff --git a/src/RandomAI.hpp b/src/RandomAI.hpp index f099443..3bedb24 100644 --- a/src/RandomAI.hpp +++ b/src/RandomAI.hpp @@ -17,8 +17,11 @@ namespace PkmnLibAI { auto moves = user->GetMoves(); ArbUt::List validMoves; for (auto move : moves) { - if (move->GetRemainingUses() > 0) { - validMoves.Append(move); + if (!move.HasValue()) { + continue; + } + if (move.GetValue()->GetRemainingUses() > 0) { + validMoves.Append(move.GetValue()); } } auto target = GetOppositeIndex(user);