PkmnLibAI/src/NaiveAI.hpp

46 lines
1.8 KiB
C++
Raw Normal View History

2021-04-18 11:37:14 +00:00
#ifndef PKMNLIB_DOWNLOAD_NAIVEAI_HPP
#define PKMNLIB_DOWNLOAD_NAIVEAI_HPP
#include "PokemonAI.hpp"
namespace PkmnLibAI {
class NaiveAI : public PokemonAI {
public:
std::string GetName() const noexcept override { return "naive"; }
CreatureLib::Battling::BaseTurnChoice* GetChoice(PkmnLib::Battling::Battle* battle,
PkmnLib::Battling::Pokemon* user) override {
auto target = GetOppositeIndex(user);
auto c = battle->GetCreature(target).GetValue();
auto highestScore = -1;
2021-11-27 09:58:48 +00:00
PkmnLib::Battling::LearnedMove* bestMove = nullptr;
2021-04-18 11:37:14 +00:00
for (auto move : user->GetMoves()) {
2021-04-23 10:02:56 +00:00
if (!move.HasValue()) {
2021-04-18 11:37:14 +00:00
continue;
2021-04-23 10:02:56 +00:00
}
2021-05-24 10:21:07 +00:00
auto t = GetTargetIndex(battle, user, move);
if (!t.has_value() || t.value() != target) {
continue;
}
2021-04-23 10:02:56 +00:00
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) {
2021-04-18 11:37:14 +00:00
highestScore = naiveDamage;
bestMove = move;
}
}
2021-04-23 10:02:56 +00:00
if (highestScore == -1) {
2021-04-18 11:37:14 +00:00
return battle->GetLibrary()->GetMiscLibrary()->ReplacementAttack(user, target);
}
return new CreatureLib::Battling::AttackTurnChoice(user, bestMove, target);
}
};
}
#endif // PKMNLIB_DOWNLOAD_NAIVEAI_HPP