From 91247909f83ed0141bad75ffda6ddf4f83c9c612 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 30 Apr 2021 13:50:28 +0200 Subject: [PATCH] Fixes bug in DepthSearchAI where we ran threaded simulations with captured by reference variables. Should be captured by value, as they changed. --- src/DepthSearchAI.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/DepthSearchAI.hpp b/src/DepthSearchAI.hpp index f051383..b1e5d60 100644 --- a/src/DepthSearchAI.hpp +++ b/src/DepthSearchAI.hpp @@ -74,7 +74,7 @@ namespace PkmnLibAI { if (move.GetValue()->GetRemainingUses() == 0) { 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)); asThreadCleanup(); return v; @@ -89,7 +89,7 @@ namespace PkmnLibAI { if (mon.GetValue()->IsFainted()) { 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)); asThreadCleanup(); return v; @@ -141,6 +141,9 @@ namespace PkmnLibAI { auto target = GetOppositeIndex(user); if (index < 4) { auto move = user->GetMoves()[index]; + if (!move.HasValue()) { + return std::numeric_limits::min(); + } auto choice = new CreatureLib::Battling::AttackTurnChoice(user, move.GetValue(), target); if (!battle->TrySetChoice(choice)) { delete choice;