36 lines
1.3 KiB
C++
36 lines
1.3 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<PkmnLib::Battling::LearnedMove*> validMoves;
|
|
for (auto move : moves) {
|
|
if (move->GetRemainingUses() > 0) {
|
|
validMoves.Append(move);
|
|
}
|
|
}
|
|
auto target = GetOppositeIndex(user);
|
|
|
|
if (validMoves.Count() == 0) {
|
|
return battle->GetLibrary()->GetMiscLibrary()->ReplacementAttack(user, target);
|
|
}
|
|
auto moveIndex = rand.Get(validMoves.Count());
|
|
return new CreatureLib::Battling::AttackTurnChoice(user, validMoves[moveIndex], target);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // PKMNLIB_AI_RANDOMAI_HPP
|