41 lines
1.8 KiB
C++
41 lines
1.8 KiB
C++
#ifndef PKMNLIB_AI_RANDOMAI_HPP
|
|
#define PKMNLIB_AI_RANDOMAI_HPP
|
|
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
|
|
#include <PkmnLib/Battling/Pokemon/LearnedMove.hpp>
|
|
|
|
namespace PkmnLibAI {
|
|
// AI that returns a random valid move.
|
|
class RandomAI : public PokemonAI {
|
|
private:
|
|
ArbUt::Random rand;
|
|
|
|
public:
|
|
std::string GetName() const noexcept override { return "random"; }
|
|
|
|
CreatureLib::Battling::BaseTurnChoice* GetChoice([[maybe_unused]] PkmnLib::Battling::Battle* battle,
|
|
[[maybe_unused]] PkmnLib::Battling::Pokemon* user) override {
|
|
auto moves = user->GetMoves();
|
|
ArbUt::List<std::tuple<PkmnLib::Battling::LearnedMove*, CreatureLib::Battling::CreatureIndex>> validMoves;
|
|
for (auto move : moves) {
|
|
if (!move.HasValue()) {
|
|
continue;
|
|
}
|
|
auto target = GetTargetIndex(battle, user, move.GetValue());
|
|
if (move.GetValue()->GetRemainingUses() > 0 && target.has_value()) {
|
|
validMoves.Append(std::tuple<PkmnLib::Battling::LearnedMove*, CreatureLib::Battling::CreatureIndex>(
|
|
move.GetValue(), target.value()));
|
|
}
|
|
}
|
|
|
|
if (validMoves.Count() == 0) {
|
|
return battle->GetLibrary()->GetMiscLibrary()->ReplacementAttack(user, GetOppositeIndex(user));
|
|
}
|
|
auto moveIndex = rand.Get(validMoves.Count());
|
|
return new CreatureLib::Battling::AttackTurnChoice(user, std::get<0>(validMoves[moveIndex]),
|
|
std::get<1>(validMoves[moveIndex]));
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // PKMNLIB_AI_RANDOMAI_HPP
|