More error fixes in AI

This commit is contained in:
Maruno17
2022-10-16 14:53:49 +01:00
parent 43290c39a2
commit e8703e8b05
8 changed files with 29 additions and 29 deletions

View File

@@ -140,7 +140,7 @@ class Battle::AI
return score return score
=begin
mini_score = 1.0 mini_score = 1.0
# Determine whether the move boosts Attack, Special Attack or Speed (Bulk Up # Determine whether the move boosts Attack, Special Attack or Speed (Bulk Up
# is sometimes not considered a sweeping move) # is sometimes not considered a sweeping move)
@@ -230,6 +230,7 @@ class Battle::AI
end end
return mini_score return mini_score
=end
end end
#============================================================================= #=============================================================================
@@ -361,7 +362,7 @@ class Battle::AI
return score return score
=begin
mini_score = 1.0 mini_score = 1.0
case stat case stat
when :ATTACK when :ATTACK
@@ -565,6 +566,7 @@ class Battle::AI
end end
return mini_score return mini_score
=end
end end
#============================================================================= #=============================================================================

View File

@@ -7,6 +7,8 @@ class Battle::AI
#============================================================================= #=============================================================================
def pbGetDamagingMoveBaseScore def pbGetDamagingMoveBaseScore
return 100 return 100
=begin
# Don't prefer moves that are ineffective because of abilities or effects # Don't prefer moves that are ineffective because of abilities or effects
return 0 if @target.immune_to_move? return 0 if @target.immune_to_move?
user_battler = @user.battler user_battler = @user.battler
@@ -45,6 +47,7 @@ class Battle::AI
damage_percentage += 40 if damage_percentage > 100 # Prefer moves likely to be lethal damage_percentage += 40 if damage_percentage > 100 # Prefer moves likely to be lethal
return damage_percentage.to_i return damage_percentage.to_i
=end
end end
#============================================================================= #=============================================================================
@@ -53,6 +56,8 @@ class Battle::AI
#============================================================================= #=============================================================================
def pbGetStatusMoveBaseScore def pbGetStatusMoveBaseScore
return 100 return 100
=begin
# TODO: Call @target.immune_to_move? here too, not just for damaging moves # TODO: Call @target.immune_to_move? here too, not just for damaging moves
# (only if this status move will be affected). # (only if this status move will be affected).
@@ -295,5 +300,6 @@ class Battle::AI
# "TargetActsLast", # "TargetActsLast",
# "ProtectUserSideFromStatusMoves" # "ProtectUserSideFromStatusMoves"
return 100 return 100
=end
end end
end end

View File

@@ -59,7 +59,7 @@ Battle::AI::Handlers::MoveEffectScore.add("MaxUserAttackLoseHalfOfTotalHP",
proc { |score, move, user, target, ai, battle| proc { |score, move, user, target, ai, battle|
score = ai.get_score_for_user_stat_raise(score) score = ai.get_score_for_user_stat_raise(score)
# Don't prefer the lower the user's HP is # Don't prefer the lower the user's HP is
score -= 80 * (1 - (@user.hp.to_f / @user.totalhp)) # 0 to -40 score -= 80 * (1 - (user.hp.to_f / user.totalhp)) # 0 to -40
next score next score
} }
) )

View File

@@ -413,7 +413,7 @@ Battle::AI::Handlers::MoveEffectScore.copy("FreezeTarget",
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("FreezeTarget", Battle::AI::Handlers::MoveEffectScore.add("FreezeFlinchTarget",
proc { |score, move, user, target, ai, battle| proc { |score, move, user, target, ai, battle|
score = Battle::AI::Handlers.apply_move_effect_score("FreezeTarget", score = Battle::AI::Handlers.apply_move_effect_score("FreezeTarget",
score, move, user, target, ai, battle) score, move, user, target, ai, battle)

View File

@@ -37,24 +37,18 @@ Battle::AI::Handlers::MoveEffectScore.add("HitTwoTimesPoisonTarget",
) )
#=============================================================================== #===============================================================================
# TODO: Review score modifiers. #
#=============================================================================== #===============================================================================
Battle::AI::Handlers::MoveBasePower.copy("HitTwoTimes", Battle::AI::Handlers::MoveBasePower.copy("HitTwoTimes",
"HitTwoTimesFlinchTarget") "HitTwoTimesFlinchTarget")
Battle::AI::Handlers::MoveEffectScore.add("HitTwoTimesFlinchTarget", Battle::AI::Handlers::MoveEffectScore.add("HitTwoTimesFlinchTarget",
proc { |score, move, user, target, ai, battle| proc { |score, move, user, target, ai, battle|
dmg = move.rough_damage # Score for hitting multiple times
num_hits = move.move.pbNumHits(user.battler, [target.battler]) score = Battle::AI::Handlers.apply_move_effect_score("HitTwoTimes",
# Prefer if the target has a Substitute and the first hit can break it score, move, user, target, ai, battle)
if target.effects[PBEffects::Substitute] > 0 && !move.move.ignoresSubstitute?(user.battler) # Score for flinching
score += 10 if target.effects[PBEffects::Substitute] < dmg / num_hits score = Battle::AI::Handlers.apply_move_effect_score("FlinchTarget",
end score, move, user, target, ai, battle)
# Flinching
if user.faster_than?(target) && target.effects[PBEffects::Substitute] < dmg / num_hits &&
(battle.moldBreaker || !target.has_active_ability?(:INNERFOCUS))
score += 10
end
# TODO: Consider effects that trigger per hit.
next score next score
} }
) )
@@ -244,7 +238,7 @@ Battle::AI::Handlers::MoveEffectScore.add("TwoTurnAttack",
has_protect_move = true has_protect_move = true
end end
end end
if move.rough_priority > 0 if move.rough_priority(user) > 0
if target.check_for_move { |m| m.function == "ProtectUserSideFromPriorityMoves" } if target.check_for_move { |m| m.function == "ProtectUserSideFromPriorityMoves" }
has_protect_move = true has_protect_move = true
end end
@@ -305,18 +299,16 @@ Battle::AI::Handlers::MoveEffectScore.add("TwoTurnAttackBurnTarget",
) )
#=============================================================================== #===============================================================================
# TODO: Review score modifiers. #
#=============================================================================== #===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("TwoTurnAttackFlinchTarget", Battle::AI::Handlers::MoveEffectScore.add("TwoTurnAttackFlinchTarget",
proc { |score, move, user, target, ai, battle| proc { |score, move, user, target, ai, battle|
# Score for being a two turn attack # Score for being a two turn attack
score = Battle::AI::Handlers.apply_move_effect_score("TwoTurnAttack", score = Battle::AI::Handlers.apply_move_effect_score("TwoTurnAttack",
score, move, user, target, ai, battle) score, move, user, target, ai, battle)
# Flinching # Score for flinching
if user.faster_than?(target) && target.effects[PBEffects::Substitute] == 0 && score = Battle::AI::Handlers.apply_move_effect_score("FlinchTarget",
(battle.moldBreaker || !target.has_active_ability?(:INNERFOCUS)) score, move, user, target, ai, battle)
score += 10
end
next score next score
} }
) )

View File

@@ -316,8 +316,8 @@ Battle::AI::Handlers::MoveEffectScore.add("TargetUsesItsLastUsedMoveAgain",
#=============================================================================== #===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("HigherPriorityInGrassyTerrain", Battle::AI::Handlers::MoveEffectScore.add("HigherPriorityInGrassyTerrain",
proc { |score, move, user, target, ai, battle| proc { |score, move, user, target, ai, battle|
if ai.trainer.medium_skill? && @battle.field.terrain == :Grassy if ai.trainer.medium_skill? && battle.field.terrain == :Grassy
score += 40 if target.faster_than?(user) score += 15 if target.faster_than?(user)
end end
next score next score
} }

View File

@@ -283,7 +283,7 @@ Battle::AI::Handlers::GeneralMoveScore.add(:add_predicted_damage,
dmg = move.rough_damage dmg = move.rough_damage
score += [15.0 * dmg / target.hp, 20].min score += [15.0 * dmg / target.hp, 20].min
score += 10 if dmg > target.hp * 1.1 # Predicted to KO the target score += 10 if dmg > target.hp * 1.1 # Predicted to KO the target
next score next score.to_i
end end
} }
) )

View File

@@ -116,7 +116,7 @@ class Battle::AI::AIMove
end end
##### Calculate target's defense stat ##### ##### Calculate target's defense stat #####
defense, def_stage = pbGetDefenseStats(user, target) defense, def_stage = @move.pbGetDefenseStats(user.battler, target.battler)
if !user.has_active_ability?(:UNAWARE) || @ai.battle.moldBreaker if !user.has_active_ability?(:UNAWARE) || @ai.battle.moldBreaker
def_stage = 6 if is_critical && def_stage > 6 def_stage = 6 if is_critical && def_stage > 6
defense = (defense.to_f * stage_mul[def_stage] / stage_div[def_stage]).floor defense = (defense.to_f * stage_mul[def_stage] / stage_div[def_stage]).floor
@@ -552,7 +552,7 @@ class Battle::AI::AIMove
# 3 = additional effect has an increased chance to work # 3 = additional effect has an increased chance to work
def additional_effect_usability(user, target) def additional_effect_usability(user, target)
return 0 if @move.addlEffect == 0 # Doesn't have an additional effect return 0 if @move.addlEffect == 0 # Doesn't have an additional effect
return 1 if target.has_active_ability?(:SHIELDDUST) && !battle.moldBreaker return 1 if target.has_active_ability?(:SHIELDDUST) && !@ai.battle.moldBreaker
return 3 if (Settings::MECHANICS_GENERATION >= 6 || self.function != "EffectDependsOnEnvironment") && return 3 if (Settings::MECHANICS_GENERATION >= 6 || self.function != "EffectDependsOnEnvironment") &&
(user.has_active_ability?(:SERENEGRACE) || user.pbOwnSide.effects[PBEffects::Rainbow] > 0) (user.has_active_ability?(:SERENEGRACE) || user.pbOwnSide.effects[PBEffects::Rainbow] > 0)
return 2 return 2