Class EvaluationBattleRandomness

java.lang.Object
com.pixelmonmod.pixelmon.battles.controller.random.policy.EvaluationBattleRandomness
All Implemented Interfaces:
BattleRandomness

public class EvaluationBattleRandomness extends Object implements BattleRandomness
BattleRandomness implementation used for deterministic battle evaluation.

This policy intentionally removes most non-guaranteed random outcomes from AI evaluation so that simulated battle states are stable and repeatable. Guaranteed effects still succeed, while chance-based positive outcomes such as critical hits, secondary effects, move power boosts, and random recovery generally fail unless their chance is 100%.

Where a random value must still be selected, this implementation chooses a stable representative value, such as the minimum multi-hit count, the first available target or attack, or the midpoint of a fixed damage range.

  • Constructor Details

    • EvaluationBattleRandomness

      public EvaluationBattleRandomness(BattleRandomSource randomSource)
  • Method Details

    • raw

      public BattleRandomSource raw()
      Description copied from interface: BattleRandomness
      Gets the raw battle randomness source.

      This should almost never be used directly by internal battle mechanics. Prefer adding or using a semantic method on this interface instead.

      Direct raw access is appropriate for:

      • Implementing methods inside a BattleRandomness implementation.
      • External/non-battle-mechanic randomness where AI evaluation is irrelevant.
      • Old AI implementations (such as Advanced/Tactical AIs)
      • Temporary migration code where no semantic method exists yet.

      If a random result can affect battle state, turn order, damage, status, targeting, move success, or any decision an AI may need to evaluate, add a semantic method instead of using this directly.

      Specified by:
      raw in interface BattleRandomness
      Returns:
      The raw battle random source.
    • rollAccuracy

      public boolean rollAccuracy(double accuracy)
      Description copied from interface: BattleRandomness
      Rolls whether a move passes its accuracy check.
      Specified by:
      rollAccuracy in interface BattleRandomness
      Parameters:
      accuracy - The move accuracy as a probability from 0.0 to 1.0.
      Returns:
      Whether the move hits.
    • rollOHKOAccuracy

      public boolean rollOHKOAccuracy(double accuracy)
      Description copied from interface: BattleRandomness
      Rolls whether an OHKO move passes its special accuracy check.

      OHKO moves are separated from normal accuracy because they have unusually high impact and may need to be treated more conservatively by AI evaluation.

      Specified by:
      rollOHKOAccuracy in interface BattleRandomness
      Parameters:
      accuracy - The OHKO accuracy as a probability from 0.0 to 1.0.
      Returns:
      Whether the OHKO move hits.
    • rollSecondaryEffect

      public boolean rollSecondaryEffect(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a move's secondary effect occurs.

      This should be used for additional effects caused by a move, such as secondary status, stat drops, or similar effects that are not the primary purpose of the move.

      Specified by:
      rollSecondaryEffect in interface BattleRandomness
      Parameters:
      chance - The secondary effect chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the secondary effect occurs.
    • rollAbilityEffect

      public boolean rollAbilityEffect(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether an ability-based random effect occurs.
      Specified by:
      rollAbilityEffect in interface BattleRandomness
      Parameters:
      chance - The ability effect chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the ability effect occurs.
    • rollCrit

      public boolean rollCrit(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether an attack is a critical hit.
      Specified by:
      rollCrit in interface BattleRandomness
      Parameters:
      chance - The critical hit chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the attack crits.
    • rollStatusEffect

      public boolean rollStatusEffect(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a status-inflicting effect occurs.

      This is intended for random status application when the status effect itself is the thing being rolled.

      Specified by:
      rollStatusEffect in interface BattleRandomness
      Parameters:
      chance - The status effect chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the status effect occurs.
    • rollConsecutiveMoveSuccess

      public boolean rollConsecutiveMoveSuccess(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a consecutively-used move succeeds.

      This is intended for Protect-like effects, Ally Switch repeat failure, and similar mechanics where repeated use lowers the success chance.

      Specified by:
      rollConsecutiveMoveSuccess in interface BattleRandomness
      Parameters:
      chance - The success chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the consecutive-use move succeeds.
    • rollStatusPrevention

      public boolean rollStatusPrevention(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a status prevents the affected Pokémon from acting.

      Examples include full paralysis, immobilization from infatuation, drowsy action failure, and similar status-based turn denial.

      Specified by:
      rollStatusPrevention in interface BattleRandomness
      Parameters:
      chance - The prevention chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the status prevents action this turn.
    • rollHeldItemEffect

      public boolean rollHeldItemEffect(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a held item random effect occurs.
      Specified by:
      rollHeldItemEffect in interface BattleRandomness
      Parameters:
      chance - The held item effect chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the held item effect occurs.
    • chooseMultiHitCount

      public int chooseMultiHitCount(int minHits, int maxHits)
      Description copied from interface: BattleRandomness
      Chooses the number of hits for a multi-hit move.

      Implementations should preserve any special distributions for common multi-hit moves, such as the standard weighted 2-5 hit distribution, rather than assuming uniform selection.

      Specified by:
      chooseMultiHitCount in interface BattleRandomness
      Parameters:
      minHits - The minimum possible number of hits.
      maxHits - The maximum possible number of hits.
      Returns:
      The selected number of hits.
    • rollUserWinsSpeedTie

      public boolean rollUserWinsSpeedTie(PixelmonWrapper user, PixelmonWrapper target)
      Description copied from interface: BattleRandomness
      Rolls whether the user wins a speed tie against the target.
      Specified by:
      rollUserWinsSpeedTie in interface BattleRandomness
      Parameters:
      user - The Pokémon whose move order is being checked.
      target - The opposing Pokémon in the speed tie.
      Returns:
      Whether user wins the speed tie.
    • rollStatusRecovery

      public boolean rollStatusRecovery(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a status randomly recovers or ends.

      Examples include random thawing from freeze or similar status recovery mechanics.

      Specified by:
      rollStatusRecovery in interface BattleRandomness
      Parameters:
      chance - The recovery chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the status recovers.
    • rollMovePowerBoost

      public boolean rollMovePowerBoost(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a move receives a random power boost.

      This is intended for moves where the primary damage profile changes due to a random effect, rather than for secondary effects.

      Specified by:
      rollMovePowerBoost in interface BattleRandomness
      Parameters:
      chance - The power boost chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the move receives the power boost.
    • chooseBefuddleStatus

      public StatusType chooseBefuddleStatus(PixelmonWrapper user, PixelmonWrapper target)
      Description copied from interface: BattleRandomness
      Chooses the status applied by Befuddle.
      Specified by:
      chooseBefuddleStatus in interface BattleRandomness
      Parameters:
      user - The Pokémon using Befuddle.
      target - The Pokémon receiving the status.
      Returns:
      The selected status type.
    • chooseDireClawStatus

      public StatusType chooseDireClawStatus(PixelmonWrapper user, PixelmonWrapper target)
      Description copied from interface: BattleRandomness
      Chooses the status applied by Dire Claw.
      Specified by:
      chooseDireClawStatus in interface BattleRandomness
      Parameters:
      user - The Pokémon using Dire Claw.
      target - The Pokémon receiving the status.
      Returns:
      The selected status type.
    • chooseTriAttackStatus

      public StatusType chooseTriAttackStatus(PixelmonWrapper user, PixelmonWrapper target)
      Description copied from interface: BattleRandomness
      Chooses the status applied by Tri Attack.
      Specified by:
      chooseTriAttackStatus in interface BattleRandomness
      Parameters:
      user - The Pokémon using Tri Attack.
      target - The Pokémon receiving the status.
      Returns:
      The selected status type.
    • chooseStunShockStatus

      public StatusType chooseStunShockStatus(PixelmonWrapper user, PixelmonWrapper target)
      Description copied from interface: BattleRandomness
      Chooses the status applied by Stun Shock.
      Specified by:
      chooseStunShockStatus in interface BattleRandomness
      Parameters:
      user - The Pokémon using Stun Shock.
      target - The Pokémon receiving the status.
      Returns:
      The selected status type.
    • rollStatusTurns

      public int rollStatusTurns(int min, int max)
      Description copied from interface: BattleRandomness
      Rolls the number of turns a status will last.
      Specified by:
      rollStatusTurns in interface BattleRandomness
      Parameters:
      min - The minimum number of turns.
      max - The maximum number of turns.
      Returns:
      The selected duration.
    • chooseFixedDamageMultiplier

      public float chooseFixedDamageMultiplier(float min, float max)
      Description copied from interface: BattleRandomness
      Chooses a fixed-damage multiplier.

      This is intended for fixed-damage moves with random damage ranges, such as Psywave-style effects. Normal attack damage variance should generally be handled by the attack damage calculator instead.

      Specified by:
      chooseFixedDamageMultiplier in interface BattleRandomness
      Parameters:
      min - The minimum multiplier.
      max - The maximum multiplier.
      Returns:
      The selected multiplier.
    • chooseRaidCheerEffect

      public int chooseRaidCheerEffect(int effectCount)
      Description copied from interface: BattleRandomness
      Chooses which raid cheer effect occurs.
      Specified by:
      chooseRaidCheerEffect in interface BattleRandomness
      Parameters:
      effectCount - The number of possible cheer effects.
      Returns:
      The selected cheer effect index.
    • chooseRaidCheerBoost

      public RaidCheerBoost chooseRaidCheerBoost()
      Description copied from interface: BattleRandomness
      Chooses the stat boost or special boost applied by a raid cheer effect.
      Specified by:
      chooseRaidCheerBoost in interface BattleRandomness
      Returns:
      The selected raid cheer boost.
    • rollCheerChance

      public boolean rollCheerChance(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a raid cheer attempt succeeds.
      Specified by:
      rollCheerChance in interface BattleRandomness
      Parameters:
      chance - The cheer success chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the cheer succeeds.
    • rollShockwaveChance

      public boolean rollShockwaveChance(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a shockwave-style random raid effect occurs.
      Specified by:
      rollShockwaveChance in interface BattleRandomness
      Parameters:
      chance - The shockwave chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the shockwave effect occurs.
    • getRandomStatIncrease

      public BattleStatsType getRandomStatIncrease(it.unimi.dsi.fastutil.ints.IntList possibleStats)
      Description copied from interface: BattleRandomness
      Chooses a random stat from the possible stat list to increase.
      Specified by:
      getRandomStatIncrease in interface BattleRandomness
      Parameters:
      possibleStats - The possible stat indexes.
      Returns:
      The selected battle stat type.
    • rollMoveEffect

      public boolean rollMoveEffect(double chance)
      Description copied from interface: BattleRandomness
      Rolls whether a move's main random effect occurs.

      This is intended for moves whose primary effect has a random activation chance, rather than for secondary effects, ability effects, or held item effects.

      Specified by:
      rollMoveEffect in interface BattleRandomness
      Parameters:
      chance - The move effect chance as a probability from 0.0 to 1.0.
      Returns:
      Whether the move effect occurs.
    • rollMagnitude

      public MagnitudeRoll rollMagnitude()
      Description copied from interface: BattleRandomness
      Rolls Magnitude's magnitude and power.
      Specified by:
      rollMagnitude in interface BattleRandomness
      Returns:
      The selected Magnitude roll.
    • getRandomTarget

      public PixelmonWrapper getRandomTarget(PixelmonWrapper user, PixelmonWrapper[] possibleTargets)
      Description copied from interface: BattleRandomness
      Chooses a random target from the possible targets.
      Specified by:
      getRandomTarget in interface BattleRandomness
      Parameters:
      user - The Pokémon choosing the target.
      possibleTargets - The possible targets.
      Returns:
      The selected target.
    • getRandomAttack

      public Attack getRandomAttack(List<Attack> possibleAttacks)
      Description copied from interface: BattleRandomness
      Chooses a random attack from the possible attacks.
      Specified by:
      getRandomAttack in interface BattleRandomness
      Parameters:
      possibleAttacks - The possible attacks.
      Returns:
      The selected attack.
    • getRandomType

      public net.minecraft.core.Holder<Type> getRandomType(List<net.minecraft.core.Holder<Type>> possibleTypes)
      Description copied from interface: BattleRandomness
      Chooses a random type from the possible types.
      Specified by:
      getRandomType in interface BattleRandomness
      Parameters:
      possibleTypes - The possible types.
      Returns:
      The selected type.
    • rollPresentPower

      public int rollPresentPower(int maxPower)
      Description copied from interface: BattleRandomness
      Rolls Present's random base power.
      Specified by:
      rollPresentPower in interface BattleRandomness
      Parameters:
      maxPower - The maximum power value available to the roll.
      Returns:
      The selected Present power.
    • copy

      public BattleRandomness copy(BattleRandomContext newController, BattleRandomSource newSource)
      Description copied from interface: BattleRandomness
      Creates a copy of this randomness context for another battle controller and random source.

      This is primarily intended for battle state copying, simulation, and AI lookahead.

      Specified by:
      copy in interface BattleRandomness
      Parameters:
      newController - The battle controller the copied randomness should belong to.
      newSource - The random source the copied randomness should use.
      Returns:
      The copied randomness context.