Updates PkmnLib

This commit is contained in:
Deukhoofd 2021-04-23 12:02:56 +02:00
parent a5d49d7aa4
commit f5b438f38a
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 25 additions and 12 deletions

View File

@ -68,7 +68,10 @@ namespace PkmnLibAI {
auto side = user->GetBattleSide().GetValue(); auto side = user->GetBattleSide().GetValue();
for (u8 moveIndex = 0; moveIndex < (u8)user->GetMoves().Count(); ++moveIndex) { for (u8 moveIndex = 0; moveIndex < (u8)user->GetMoves().Count(); ++moveIndex) {
auto move = user->GetMoves()[moveIndex]; auto move = user->GetMoves()[moveIndex];
if (move->GetRemainingUses() == 0) { if (!move.HasValue()) {
continue;
}
if (move.GetValue()->GetRemainingUses() == 0) {
continue; continue;
} }
threadPool.push_back(std::async([=] { threadPool.push_back(std::async([=] {
@ -105,7 +108,11 @@ namespace PkmnLibAI {
auto side = user->GetBattleSide().GetValue(); auto side = user->GetBattleSide().GetValue();
for (u8 moveIndex = 0; moveIndex < (u8)user->GetMoves().Count(); ++moveIndex) { for (u8 moveIndex = 0; moveIndex < (u8)user->GetMoves().Count(); ++moveIndex) {
auto move = user->GetMoves()[moveIndex]; auto move = user->GetMoves()[moveIndex];
if (move->GetRemainingUses() == 0) { if (!move.HasValue()) {
continue;
}
if (move.GetValue()->GetRemainingUses() == 0) {
continue; continue;
} }
auto scored = SimulateTurn(battle, side->GetSideIndex(), 0, moveIndex, depth); auto scored = SimulateTurn(battle, side->GetSideIndex(), 0, moveIndex, depth);
@ -134,7 +141,7 @@ namespace PkmnLibAI {
auto target = GetOppositeIndex(user); auto target = GetOppositeIndex(user);
if (index < 4) { if (index < 4) {
auto move = user->GetMoves()[index]; 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)) { if (!battle->TrySetChoice(choice)) {
delete choice; delete choice;
return std::numeric_limits<float>::min(); return std::numeric_limits<float>::min();
@ -197,7 +204,7 @@ namespace PkmnLibAI {
} }
if (highest < 4) { 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 { } else {
return new CreatureLib::Battling::SwitchTurnChoice(user, party.At(highest - 4)); return new CreatureLib::Battling::SwitchTurnChoice(user, party.At(highest - 4));
} }

View File

@ -15,11 +15,14 @@ namespace PkmnLibAI {
auto highestScore = -1; auto highestScore = -1;
PkmnLib::Battling::LearnedMove* bestMove; PkmnLib::Battling::LearnedMove* bestMove;
for (auto move : user->GetMoves()) { for (auto move : user->GetMoves()) {
if (move->GetRemainingUses() <= 0) if (!move.HasValue()) {
continue; continue;
auto naiveDamage = }
move->GetMoveData()->GetBasePower() * battle->GetLibrary()->GetTypeLibrary()->GetEffectiveness( if (move.GetValue()->GetRemainingUses() <= 0)
move->GetMoveData()->GetType(), c->GetTypes()); continue;
auto naiveDamage = move.GetValue()->GetMoveData()->GetBasePower() *
battle->GetLibrary()->GetTypeLibrary()->GetEffectiveness(
move.GetValue()->GetMoveData()->GetType(), c->GetTypes());
if (naiveDamage > highestScore) { if (naiveDamage > highestScore) {
highestScore = naiveDamage; highestScore = naiveDamage;
bestMove = move; bestMove = move;

View File

@ -17,8 +17,11 @@ namespace PkmnLibAI {
auto moves = user->GetMoves(); auto moves = user->GetMoves();
ArbUt::List<PkmnLib::Battling::LearnedMove*> validMoves; ArbUt::List<PkmnLib::Battling::LearnedMove*> validMoves;
for (auto move : moves) { for (auto move : moves) {
if (move->GetRemainingUses() > 0) { if (!move.HasValue()) {
validMoves.Append(move); continue;
}
if (move.GetValue()->GetRemainingUses() > 0) {
validMoves.Append(move.GetValue());
} }
} }
auto target = GetOppositeIndex(user); auto target = GetOppositeIndex(user);