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();
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<float>::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));
}

View File

@ -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);
}

View File

@ -17,8 +17,11 @@ namespace PkmnLibAI {
auto moves = user->GetMoves();
ArbUt::List<PkmnLib::Battling::LearnedMove*> 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);