mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-08 13:44:59 +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,20 +81,27 @@ 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)
|
||||||
# Randomly choose a move from the choices and register it
|
choices.push([i,100,-1]) # Move index, score, target
|
||||||
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
|
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
|
end
|
||||||
# Log the result
|
# Log the result
|
||||||
if @battle.choices[idxBattler][2]
|
if @battle.choices[idxBattler][2]
|
||||||
|
|||||||
Reference in New Issue
Block a user