From 3cf88f6f72358bd94e68a7af9b5740ee67a95c0b Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Fri, 18 Sep 2020 20:45:20 +0100 Subject: [PATCH] AI now chooses a move at random if all moves end up with a score of 0 --- Data/Scripts/012_Battle/004_AI/004_AI_Move.rb | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Data/Scripts/012_Battle/004_AI/004_AI_Move.rb b/Data/Scripts/012_Battle/004_AI/004_AI_Move.rb index c1a2de5d7..c42cc49c6 100644 --- a/Data/Scripts/012_Battle/004_AI/004_AI_Move.rb +++ b/Data/Scripts/012_Battle/004_AI/004_AI_Move.rb @@ -81,20 +81,27 @@ class PokeBattle_AI return end end - # Randomly choose a move to use + # If there are no calculated choices, pick one at random if choices.length==0 - # If there are no calculated choices, use Struggle (or an Encored move) - @battle.pbAutoChooseMove(idxBattler) - else - # Randomly choose a move from the choices and register it - randNum = pbAIRandom(totalScore) - choices.each do |c| - randNum -= c[1] - next if randNum>=0 - @battle.pbRegisterMove(idxBattler,c[0],false) - @battle.pbRegisterTarget(idxBattler,c[2]) if c[2]>=0 - break + PBDebug.log("[AI] #{user.pbThis} (#{user.index}) doesn't want to use any moves; picking one at random") + user.eachMoveWithIndex do |_m,i| + next if !@battle.pbCanChooseMove?(idxBattler,i,false) + choices.push([i,100,-1]) # Move index, score, target end + if choices.length==0 # No moves are physically possible to use + user.eachMoveWithIndex do |_m,i| + choices.push([i,100,-1]) # Move index, score, target + end + end + end + # Randomly choose a move from the choices and register it + randNum = pbAIRandom(totalScore) + choices.each do |c| + randNum -= c[1] + next if randNum>=0 + @battle.pbRegisterMove(idxBattler,c[0],false) + @battle.pbRegisterTarget(idxBattler,c[2]) if c[2]>=0 + break end # Log the result if @battle.choices[idxBattler][2]