Fixes bug in DepthSearchAI where we ran threaded simulations with captured by reference variables. Should be captured by value, as they changed.

This commit is contained in:
Deukhoofd 2021-04-30 13:50:28 +02:00
parent f5b438f38a
commit 91247909f8
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 5 additions and 2 deletions

View File

@ -74,7 +74,7 @@ namespace PkmnLibAI {
if (move.GetValue()->GetRemainingUses() == 0) { if (move.GetValue()->GetRemainingUses() == 0) {
continue; continue;
} }
threadPool.push_back(std::async([=] { threadPool.push_back(std::async([this, battle, side, moveIndex, depth] {
auto v = std::tuple(moveIndex, SimulateTurn(battle, side->GetSideIndex(), 0, moveIndex, depth)); auto v = std::tuple(moveIndex, SimulateTurn(battle, side->GetSideIndex(), 0, moveIndex, depth));
asThreadCleanup(); asThreadCleanup();
return v; return v;
@ -89,7 +89,7 @@ namespace PkmnLibAI {
if (mon.GetValue()->IsFainted()) { if (mon.GetValue()->IsFainted()) {
continue; continue;
} }
threadPool.push_back(std::async([=] { threadPool.push_back(std::async([this, battle, side, i, depth] {
auto v = std::tuple((u8)(i + 4), SimulateTurn(battle, side->GetSideIndex(), 0, i + 4, depth)); auto v = std::tuple((u8)(i + 4), SimulateTurn(battle, side->GetSideIndex(), 0, i + 4, depth));
asThreadCleanup(); asThreadCleanup();
return v; return v;
@ -141,6 +141,9 @@ 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];
if (!move.HasValue()) {
return std::numeric_limits<float>::min();
}
auto choice = new CreatureLib::Battling::AttackTurnChoice(user, move.GetValue(), target); auto choice = new CreatureLib::Battling::AttackTurnChoice(user, move.GetValue(), target);
if (!battle->TrySetChoice(choice)) { if (!battle->TrySetChoice(choice)) {
delete choice; delete choice;