From 3eda79ccb20e77f9e1d8fcf30c4e5724cde02e48 Mon Sep 17 00:00:00 2001 From: Annika <56906084+AnnikaCodes@users.noreply.github.com> Date: Fri, 4 Nov 2022 17:03:16 -0700 Subject: [PATCH] Remove unnecessary RNG roll for targeting This should make singles battles faster and more accurate --- sim/battle.ts | 10 ++++++---- test/sim/abilities/cursedbody.js | 2 +- test/sim/abilities/emergencyexit.js | 2 +- test/sim/items/quickclaw.js | 2 +- test/sim/misc/statuses.js | 2 +- test/sim/moves/counter.js | 4 ++-- test/sim/moves/substitute.js | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sim/battle.ts b/sim/battle.ts index 23f52a7280..98ecd88cc3 100644 --- a/sim/battle.ts +++ b/sim/battle.ts @@ -2229,13 +2229,15 @@ export class Battle { // when used without an explicit target. move = this.dex.moves.get(move); - if (move.target === 'adjacentAlly') { + if (['self', 'all', 'allySide', 'allyTeam', 'adjacentAllyOrSelf'].includes(move.target)) { + return pokemon; + } else if (move.target === 'adjacentAlly') { + if (this.gameType === 'singles') return null; const adjacentAllies = pokemon.adjacentAllies(); return adjacentAllies.length ? this.sample(adjacentAllies) : null; } - if (['self', 'all', 'allySide', 'allyTeam', 'adjacentAllyOrSelf'].includes(move.target)) { - return pokemon; - } + if (this.gameType === 'singles') return pokemon.side.foe.active[0]; + if (this.activePerHalf > 2) { if (move.target === 'adjacentFoe' || move.target === 'normal' || move.target === 'randomNormal') { // even if a move can target an ally, auto-resolution will never make it target an ally diff --git a/test/sim/abilities/cursedbody.js b/test/sim/abilities/cursedbody.js index 92940db228..2dee3262c1 100644 --- a/test/sim/abilities/cursedbody.js +++ b/test/sim/abilities/cursedbody.js @@ -11,7 +11,7 @@ describe(`Cursed Body`, function () { }); it(`should be able to disable Z-moves (not the base of Z-moves)`, function () { - battle = common.createBattle({seed: [1, 2, 3, 98]}, [[ // hardcoded seed to force Cursed Body + battle = common.createBattle({seed: [1, 2, 3, 5]}, [[ // hardcoded seed to force Cursed Body {species: 'gengar', ability: 'cursedbody', item: 'focussash', moves: ['sleeptalk']}, ], [ {species: 'kommoo', item: 'kommoniumz', moves: ['clangingscales', 'sleeptalk']}, diff --git a/test/sim/abilities/emergencyexit.js b/test/sim/abilities/emergencyexit.js index b94958ec76..62cffc3b56 100644 --- a/test/sim/abilities/emergencyexit.js +++ b/test/sim/abilities/emergencyexit.js @@ -239,7 +239,7 @@ describe(`Emergency Exit`, function () { }); it(`should be suppressed by Sheer Force`, function () { - battle = common.createBattle([ + battle = common.createBattle({seed: [1, 2, 3, 4]}, [ [{species: "Golisopod", ability: 'emergencyexit', moves: ['sleeptalk'], ivs: EMPTY_IVS}, {species: "Clefable", ability: 'Unaware', moves: ['metronome']}], [{species: "Nidoking", ability: 'sheerforce', moves: ['thunder']}], ]); diff --git a/test/sim/items/quickclaw.js b/test/sim/items/quickclaw.js index c073c1998d..0bb744ce50 100644 --- a/test/sim/items/quickclaw.js +++ b/test/sim/items/quickclaw.js @@ -28,7 +28,7 @@ describe('Quick Claw', function () { }); it(`[Gen 3] causes Speed ties with every holder when activated`, function () { - battle = common.gen(3).createBattle([[ + battle = common.gen(3).createBattle({seed: [163, 106, 112, 542]}, [[ {species: 'snorlax', item: 'quickclaw', moves: ['spore']}, ], [ {species: 'deoxys', item: 'quickclaw', moves: ['seismictoss']}, diff --git a/test/sim/misc/statuses.js b/test/sim/misc/statuses.js index 0b51973394..fe51477b18 100644 --- a/test/sim/misc/statuses.js +++ b/test/sim/misc/statuses.js @@ -27,7 +27,7 @@ describe('Burn', function () { const target = battle.p2.active[0]; battle.makeChoices('move boneclub', 'move splash'); // hardcoded to RNG - assert.hurtsBy(target, 64, () => battle.makeChoices('move boneclub', 'move willowisp')); + assert.hurtsBy(target, 42, () => battle.makeChoices('move boneclub', 'move willowisp')); }); it('should reduce atk to 50% of its original value in Stadium', function () { diff --git a/test/sim/moves/counter.js b/test/sim/moves/counter.js index e375e464af..adc54cbf75 100644 --- a/test/sim/moves/counter.js +++ b/test/sim/moves/counter.js @@ -74,7 +74,7 @@ describe('Counter', function () { it(`[Gen 1] Counter Desync Clause`, function () { // seed chosen so Water Gun succeeds and Pound full paras - battle = common.gen(1).createBattle({seed: [1, 2, 3, 6]}, [[ + battle = common.gen(1).createBattle({seed: [1, 2, 3, 3]}, [[ {species: 'Mew', moves: ['pound', 'watergun', 'counter', 'thunderwave']}, ], [ {species: 'Persian', moves: ['pound', 'watergun', 'counter', 'thunderwave']}, @@ -84,7 +84,7 @@ describe('Counter', function () { assert(battle.log.some(line => line.includes('Desync Clause Mod activated'))); // seed chosen so Pound succeeds and Water Gun full paras - battle = common.gen(1).createBattle({seed: [1, 2, 3, 6]}, [[ + battle = common.gen(1).createBattle({seed: [1, 2, 3, 3]}, [[ {species: 'Mew', moves: ['pound', 'watergun', 'counter', 'thunderwave']}, ], [ {species: 'Persian', moves: ['pound', 'watergun', 'counter', 'thunderwave']}, diff --git a/test/sim/moves/substitute.js b/test/sim/moves/substitute.js index bcb8475734..44af178b0a 100644 --- a/test/sim/moves/substitute.js +++ b/test/sim/moves/substitute.js @@ -49,7 +49,7 @@ describe('Substitute', function () { }); it('should take specific recoil damage in Gen 1', function () { - battle = common.gen(1).createBattle({seed: [0, 1, 0, 1]}); + battle = common.gen(1).createBattle({seed: [1, 10, 1, 10]}); battle.setPlayer('p1', {team: [{species: 'Hitmonlee', moves: ['substitute', 'highjumpkick']}]}); battle.setPlayer('p2', {team: [{species: 'Hitmonchan', moves: ['substitute', 'agility']}]}); battle.makeChoices('move substitute', 'move substitute'); @@ -57,7 +57,7 @@ describe('Substitute', function () { const subhp = battle.p1.active[0].volatiles['substitute'].hp; assert.equal(subhp, battle.p2.active[0].volatiles['substitute'].hp); - battle.resetRNG(); // Make Hi Jump Kick miss and cause recoil. + // High Jump Kick will miss and cause recoil battle.makeChoices('move highjumpkick', 'move agility'); // Both Pokemon had a substitute, so the *target* Substitute takes recoil damage.