Commit Graph

210 Commits

Author SHA1 Message Date
Guangcong Luo
eb6fe5ce41 Improve tests 2017-07-25 03:25:25 -04:00
Guangcong Luo
3b4d8b3ff0 Split random-teams.js out of scripts.js
Random team generation scripts are no longer in scripts.js, but instead
in a new file random-teams.js.

The scripts are now also no longer run from inside battles, but in a
new team generator object. This makes it easier for external scripts
to generate random teams by running Dex.generateTeam(format).
2017-07-25 02:59:59 -04:00
HoeenHero
54f957875e [Gen 3] Random Battles (#3760) 2017-07-10 23:35:26 +04:00
Ben Davies
0e736074a9 Tests: refactor test/main.js, remove test/simulator/index.js (#3565)
- The before hook in test/main.js has no reason to be handled
asynchronously when nothing it handles is async
- test/simulator/index.js has no reason to exist when mocha.opts
already handles finding files to test
2017-06-02 01:21:47 -05:00
Guangcong Luo
cd3ac06987 Fix Hail/Sandstorm damage regression
(Also add a test for it since this isn't even the first time this
exact regression has happened.)
2017-05-18 06:29:25 -05:00
HoeenHero
36b56f5c44 Finish renaming tools to dex (#3526) 2017-05-12 17:11:30 -05:00
Guangcong Luo
6dd58b40d3 Refactor simulator into new sim/ directory
This is a surprisingly minor refactor considering how many files it
touches, but most of this is only renames.

In terms of file renames:
- `tools.js` is now `sim/dex.js`
- `battle-engine.js` is now `sim/index.js` and its three classes are
  in `sim/battle.js`, `sim/side.js`, and `sim/pokemon.js`
- `prng.js` is now `sim/prng.js`

In terms of variable renames:
- `Tools` is now `Dex`
- `BattleEngine` is now `Sim`
- `BattleEngine.Battle` is now `Sim.Battle`
- `BattleEngine.BattleSide` is now `Sim.Side`
- `BattleEngine.BattlePokemon` is now `Sim.Pokemon`
2017-05-05 16:48:38 -05:00
Guangcong Luo
fcccc2cff0 Rename Battle#on to Battle#onEvent
Battle will soon be a Node.js Stream, which has an .on() function,
which Battle#on would conflict with.

PS events aren't Node events, so naming a PS event function .on()
was kind of misleading anyway.
2017-05-05 16:48:38 -05:00
Marty-D
ab89834912 Fix lack of Inverse format 2017-05-01 23:36:47 -04:00
Guangcong Luo
698fb2ad9a Refactor choices
PS's choice system has now been majorly rewritten!

Battle#parseChoice has been eliminated, and Battle#choose is now a
very lightweight wrapper around the BattleSide#choose* functions, which
now handle validation.

Partial decisions have been mostly removed. You can manually construct
decisions partially with the side.choose* functions, but there's no
other support for them. Partial undo has been removed completely.

Choice tracking has been renamed from side.choiceData to side.choice.
side.choices has been removed and is now autogenerated from side.choice
when needed.

side.choiceData.decisions has been renamed side.choice.actions. In the
future, "decision" is a deprecated term and should be called "action"
wherever it shows up.

side.choiceData.waiting and side.getDecisionsFinished() have been
merged into side.isChoiceDone().

Other values in side.choiceData have either been rendered unnecessary
or renamed to something clearer.

The "skip" and "pass" choices have been merged together. Passes can
still be filled in automatically (so you can just use `/move 1` in
doubles when you have only one Pokémon left).
2017-03-17 23:14:52 -05:00
Guangcong Luo
df5d8b283e Fix mistakes in tests
So I've been working on a massive refactor to the choice system for,
like, over a week. It's still not done, but it's found some mistakes
in the tests that should be fixed.
2017-03-17 02:22:52 -05:00
Kevin Lau
50795768e8 Add various Z-Status Move tests (#3279) 2017-02-23 04:54:04 -06:00
Dan Pantry
9c65c5b84a add mock for battle tests that can reset the RNG
This enables battles in tests to reset their RNG to what it originally
was when they were created. A number of tests do this already by
breaking encapsulating and modifying the prng variable directly. This
should fix that.

We also remove createBattleWithPRNG and min/maxSeed properties.

Firstly, the tests that were still using the maxSeed property were
setting it to Battle.seed which has no effect since the PRNG class does
not look at this property any more - so these were no-ops.

After removing this property from tests, maxRollSeed was never used, so
I removed it and renamed minRollSeed to DEFAULT_ROLL_SEED (since it's
constant).

The places that were still using minRollSeed also were no-ops or were
using createBattleWithPRNG. Since every single instance was actually
just using the same code, I removed createBattleWithPRNG and made
createBattle default to giving you a seed with DEFAULT_ROLL_SEED and
removed the minRollSeed property too.

This makes tests much simpler and reduces the usage surface of
TestTools; now, you must define your *own* seed if you're making a PRNG
for a test, or you use one that TestTools gives you; you may not use a
public property that TestTools gives you.

We also remove the code that removes a listener in the Battle Engine.
This was rendered obsolete by f6a7c4b (see more info [in the discussion
on github][disc]

[disc]:
https://github.com/Zarel/Pokemon-Showdown/pull/3272#discussion_r102414795
2017-02-22 20:44:20 -05:00
Dan Pantry
89d4265be8 don't rely on global BattleEngine in tests
This is necessary for us to introduce a mock object.
2017-02-22 20:44:20 -05:00
Dan Pantry
56ba782966 refactor PRNG to its own class
This removes the 'deterministic test' tools by preventing action at a
distance (namely, preventing the modification of the `init` method in
`Battle` during tests). This action at a distance is incredibly
confusing.

All this action at a distance did was discard any parameters that were
passed to `Battle` that weren't the first three (which was probably a
mistake by the original author) and also hard code `this.seed` and
`this.startingSeed` in `Battle`.

This functionality has now been moved to the `PRNG` class, so instead
users should pass a `PRNG` to `Battle` as the 5th constructor argument.
Users can also pass one as the third argument to `common.createBattle`
or use `common.createBattleWithPRNG` with the PRNG as the first
argument.

The PRNG is just an encapsulation of the pseudo-random algorithm in a
class. It is stateful, so make sure to take a `clone()` of the PRNG if
you want to re-use it.
2017-02-22 20:44:20 -05:00
Guangcong Luo
5d68b0441e Disable mod loader test
It's incredibly slow, and regressions are unlikely.
2017-02-14 22:20:10 -06:00
Guangcong Luo
6611c9c9ed Fix Seed activation on double-Surge
Terrain seeds weren't activating correctly on the first Surge of two
Surge ability activations turn 1. This fixes it by allowing Update to
run on inactive Pokémon, allowing a Pokémon's item to activate onUpdate
before their own ability activation.
2017-02-14 22:14:15 -06:00
Guangcong Luo
4fc03700fb Fix Mega Pursuit
Previously, if a pokemon mega evolved and used Pursuit, and the foe
switched on the next turn, it would use Pursuit again on the next turn,
in addition to its usual decision.

This is a hack to fix it; a full fix is pending a rewrite of the
decision structure.
2016-12-21 19:37:48 -08:00
Guangcong Luo
c773b7dd83 Add test for e1c43d4bb 2016-12-15 15:25:02 -08:00
Guangcong Luo
cfd1d0ab92 Fix Emergency Exit + Sitrus Berry interaction
If Sitrus Berry activates before switch-out, Emergency Exit shouldn't
activate.
2016-12-15 03:03:11 -08:00
Kevin Lau
d7e96b8390 Add unit tests for Comatose ability (#3013) 2016-12-11 10:44:01 -05:00
Ivo Julca
78972c41f0 Revert "Confusion still has a 50% self-hit chance"
This reverts commit 7d1ee5fecd.

There is even stronger evidence, from a trusted source, that the chance is now 1/3.
https://twitter.com/pokemon_PhD/status/788827888028151808
2016-12-06 23:50:07 -05:00
Ivo Julca
7d1ee5fecd Confusion still has a 50% self-hit chance
Hypothesis of chance=1/3 can be rejected at a 0.0005 significance level.
2016-11-27 19:11:58 -05:00
Ivo Julca
2604dd1939 Trim megaOrZ argument of BattleSide#chooseMove() 2016-11-27 00:23:19 -05:00
Ivo Julca
318ca6ae9f Fix Destiny Bond 2016-11-25 15:38:25 -05:00
Ivo Julca
a14d1cc1f2 Add test for turn order for Mega Evos with Trace 2016-11-24 22:42:03 -05:00
Kevin Lau
7963c97894 Fix priority issues with Z-Moves (#2930) 2016-11-21 14:32:31 -05:00
Ivo Julca
cf35c0a8d7 Test: Fix Destiny Bond specification
It should fail deterministically every second time it's used.
2016-11-20 03:00:05 -05:00
Ivo Julca
632c04e6f1 Add failing tests for randbats generators 2016-11-20 00:24:28 -05:00
Ivo Julca
2bceebaac8 Test: Add coverage for random team generators 2016-11-19 16:11:50 -05:00
Slayer95
a3e3249a8f Spectral Thief should zero boosts despite of target abilities (#2906) 2016-11-19 14:38:54 -05:00
Ivo Julca
a09c0110b8 Destiny Bond: Add tests for exclusive counter and a minimal implementation 2016-11-19 14:17:08 -05:00
Ivo Julca
792548c01d Add test for Mega-evolution vs Pursuit order 2016-11-19 02:54:52 -05:00
Ivo Julca
78ab0bdf31 Implement Spectral Thief 2016-11-18 18:26:16 -05:00
Ivo Julca
34beddac3d Add test for bounced status moves affected by Prankster
So that UltiMario can be validated when it happens in CC:
http://www.smogon.com/forums/threads/3586701/page-33#post-7087589
2016-11-18 16:59:22 -05:00
Ivo Julca
1700067a77 Fix Judgment test 2016-11-18 15:14:27 -05:00
Ivo Julca
fbc88c8428 Fix Emergency Exit: It should block Volt Switch effect 2016-11-18 15:10:51 -05:00
Ivo Julca
c2f8c72b38 Judgment should not change type from Z Crystals 2016-11-18 15:09:21 -05:00
Ivo Julca
e97ccb3d48 Emergency Exit activation quirks are similar to Eject Button and Red Card
In particular, it only activates after all hits in a multi-hit move are performed, and
it won't activate if the move is boosted by Sheer Force.

This commit also implements the interactions of Emergency Exit
with Eject Button and Red Card, and adds tests.
2016-11-18 13:55:57 -05:00
Ivo Julca
5d04c4f2e0 King's Shield Atk drop now triggers even if immune 2016-11-18 12:48:50 -05:00
Ivo Julca
c8308ccd89 Sheer Cold no longer affects Ice-type Pokémon 2016-11-18 01:53:24 -05:00
Ivo Julca
511a45eb95 Implement immunity of Dark-types to Prankster
The immunity also applies to any moves, even non-Status, called by
other Prankster-boosted moves.
2016-11-18 00:35:52 -05:00
Ivo Julca
e741700553 Test: Update the PRNG seed to make confusion self-hits more consistent 2016-11-17 23:09:04 -05:00
Ivo Julca
92c31e9d7c Test: Move old gen suites for statuses to the bottom 2016-11-17 23:09:04 -05:00
Ivo Julca
005287443c Add tests for new mega evolution & turn order mechanics 2016-11-17 20:57:29 -05:00
Ivo Julca
4fa6c5499b Build: Fix issues reported by the latest Eslint version 2016-11-17 14:27:39 -05:00
Guangcong Luo
b734d2f1c3 Make gen 7 the default mod
This makes gen 7 the default mod, updates the tests to match, and fixes
the corresponding build error.

Note that this only changes the default Tools mod, the default Formats
mod is now gen6. gen7 must be specified by name in a format, for that
format to be a gen 7 format.
2016-11-17 12:27:46 -06:00
Guangcong Luo
02055d3d17 Fix mod loading order
Sometimes mods would mess up if they were loaded in the wrong order.
Specifically, some autogenerated properties of e.g. moves need to be
recalculated for mods.

Anyway, the entire cache system is replaced with a newer, faster,
slightly-more-memory-intensive-but-only-slightly cache system, which
no longer has these kinds of loading order issues.
2016-10-23 14:17:13 -05:00
Ben Davies
54d0ff203a Performance: replace direct references to arguments with rest parametres (#2818)
Replacing direct references to the arguments object of functions with rest
parametres prevents the function from being deoptimized while still allowing
use of arbitrary arguments. This may also fix some minor memory leaks related
to mishandling the arguments object.
2016-10-04 16:29:14 -07:00
Guangcong Luo
da1b318707 Move text processing from Tools to CommandParser
The following functions have been renamed:

- Tools.html to CommandParser.html
- Tools.plural to CommandParser.plural
- Tools.escapeHTML to CommandParser.escapeHTML
- Tools.toDurationString to CommandParser.toDurationString
- Tools.toTimeStamp to CommandParser.toTimestamp
  (notice the lowercase 's')

This is in preparation for a rename of Tools to Dex (by removing the
non-dex-related functions) and a rename of CommandParser to either
Messages or Chat.
2016-09-30 18:04:13 -07:00