mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2026-02-01 19:11:02 +00:00
AI now chooses a move at random if all moves end up with a score of 0
This commit is contained in:
@@ -81,11 +81,19 @@ class PokeBattle_AI
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Randomly choose a move to use
|
# If there are no calculated choices, pick one at random
|
||||||
if choices.length==0
|
if choices.length==0
|
||||||
# If there are no calculated choices, use Struggle (or an Encored move)
|
PBDebug.log("[AI] #{user.pbThis} (#{user.index}) doesn't want to use any moves; picking one at random")
|
||||||
@battle.pbAutoChooseMove(idxBattler)
|
user.eachMoveWithIndex do |_m,i|
|
||||||
else
|
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
|
# Randomly choose a move from the choices and register it
|
||||||
randNum = pbAIRandom(totalScore)
|
randNum = pbAIRandom(totalScore)
|
||||||
choices.each do |c|
|
choices.each do |c|
|
||||||
@@ -95,7 +103,6 @@ class PokeBattle_AI
|
|||||||
@battle.pbRegisterTarget(idxBattler,c[2]) if c[2]>=0
|
@battle.pbRegisterTarget(idxBattler,c[2]) if c[2]>=0
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
|
||||||
# Log the result
|
# Log the result
|
||||||
if @battle.choices[idxBattler][2]
|
if @battle.choices[idxBattler][2]
|
||||||
PBDebug.log("[AI] #{user.pbThis} (#{user.index}) will use #{@battle.choices[user.index][2].name}")
|
PBDebug.log("[AI] #{user.pbThis} (#{user.index}) will use #{@battle.choices[user.index][2].name}")
|
||||||
|
|||||||
Reference in New Issue
Block a user