Commit Graph

83 Commits

Author SHA1 Message Date
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
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
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
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
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
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
fbc88c8428 Fix Emergency Exit: It should block Volt Switch effect 2016-11-18 15:10:51 -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
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
The Immortal
a61e19b46a Tests: Remove unused const 2016-06-26 05:37:17 +04:00
Kevin Lau
5e3f1dcabc Tests: Update Weather tests for clarity and readability (#2596)
Updated remaining Primal Weathers to the new APIs.

Updated misleading test cases relating to base power of moves in
Desolate Land / Primordial Sea.

Increased coverage on weather tests.
2016-06-24 20:11:03 -07:00
Ivo Julca
67da1a1221 Test: Use the new common#createBattle method
- This cuts down tons of code that define player names, avatars,
and deal with Team Preview.
2016-06-17 05:45:22 -05:00
Ivo Julca
f2aff1b6ae Refactor tests to use the new assert/battle APIs 2016-06-15 08:56:29 -05:00
Ivo Julca
2ab2937b3c Implement assert extensions to enhance the test suite 2016-06-15 08:54:18 -05:00
Kevin Lau
715de49408 Refactor Anger Point to the Hit event handler
This fixes its interaction with Clear Smog because Hit handlers for
moves always activate before all other global event handlers.

Removed the Hit event from the list of events stopped by Mold Breaker
variants as there are no abilities that would be negated by it that
use that handler.
2016-03-23 20:23:42 -07:00
Kevin Lau
bfac338ddb Normalize doesn't affect moves that change type
The ModifyMove singleEvent for moves always runs before the
larger event that triggers an ability's event handler and
take precedence over Normalize, so we code exceptions in
Normalize to not change the type in those situations.

Conveniently, all the moves that change type right now are
defaulted to Normal-type, and since Normalize technically
won't change the type of any Normal-type move, we're using
that as the guideline for our exception.
2016-03-16 10:54:47 -07:00
Guangcong Luo
8446e5fbc3 Fix Thousand Arrows Wonder Guard interaction
Thousand Arrows shouldn't add Smack Down if Wonder Guard avoids it.
2016-02-19 17:23:21 -06:00
Guangcong Luo
a8e8272bac Refactor types and remove ModifyPokemon
The unwieldy system that is typesData is now removed, and is replaced by
the array `types` and the string `addedType`, which track the same amount
of information in a much more efficient way. (Roost is now hardcoded, but
let's not talk about that.)

Incidentally, this now roughly matches client, which tracks typechange
and typeadd as volatiles.

This allows us to remove ModifyPokemon, which overall provides a 10%
performance increase. I was hoping it'd be more substantial, but oh well.
2016-02-16 23:42:37 -06:00
Guangcong Luo
b665660608 Refactor for more ES6 features
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.

This refactor:

- uses arrow functions where appropriate

  Note that arrow functions still aren't used in Mocha, where `this`
  is sometimes meaningful.

  This also removes the need for .bind() nearly everywhere, as well
  as the `self = this` trick.

- refactors Validator and Connection into ES6 classes

- no longer uses Array#forEach for iterating arrays

  We strongly prefer for (let i = 0; i < arr.length; i++) because of
  performance reasons. Most forEaches have been replaced with for..of,
  though, which is 5x slower than the long-form loop but 2x faster
  than forEach, which is good enough outside of most inner loops.

  The only exception is tournaments, which is due for a more invasive
  refactor soon anyway.
2016-02-10 17:40:21 -06:00
Guangcong Luo
f094e4cf01 Fix Lightning Rod redirection priority
In speed ties, the pokemon that's had the ability the longest is
redirected to.

Fixes #2083

Closes #2154
2016-01-13 00:13:55 -08:00
Guangcong Luo
4898190cb6 Fix old pullreq for modern code style 2016-01-04 23:13:43 -06:00
Guangcong Luo
69934732ef Merge pull request #2130 from ascriptmaster/move-fixes
Refactor move redirection
2016-01-05 04:06:58 +00:00
Konrad Borowski
81f602b8d8 Always use trailing comma for multiline objects 2016-01-01 00:20:07 +01:00
Marty-D
235e470553 Merge pull request #2339 from ascriptmaster/trapping
Trapping refactor
2015-12-28 12:10:52 -05:00
Kevin Lau
7c491ad06b Add test suites for trapping moves and abilities 2015-12-21 14:56:21 -08:00
Ivo Julca
c8df8c4e27 Test: increase timeout for Lightningrod Triples test 2015-12-21 05:41:56 -05:00
Ivo Julca
344e021700 Increase timeout for Pressure tests in Triples 2015-12-14 17:53:03 -05:00
Ivo Julca
90973d5c0c Style fixes
- Cut down excessive spacing
- Add braces to missing conditionals
2015-11-07 17:08:09 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Carl Sobolewski
f1146dcac6 Weather modifies baseDamage instead of basePower
http://git.io/vZKFp
2015-09-13 02:43:39 -06:00
Kevin Lau
449f0aaa16 Add test suite for Shield Dust 2015-09-03 03:10:13 -07:00
Kevin Lau
cc1f581c90 Refactor move redirection
Implemented a new priorityEvent function that is set to abort when any
event handler returns a non-undefined result, unlike runEvent which waits
until all event handlers have run. Set RedirectTarget to use this event.

Changed ability/move priorities for RedirectTarget handlers to fit under
this new paradigm.

Added new Lightning Rod and Storm Drain tests to ensure proper behavior.
2015-08-26 20:22:28 -07:00
Kevin Lau
1c70494e2b Fix Snatch and Imprison's interaction with Pressure
They target the user, but for the purposes of Pressure are treated as if
they target the opposing side.
2015-08-21 18:50:21 -07:00
Kevin Lau
e846fbb129 Fix Battle Armor and Shell Armor tests to no longer use the battle log
Instead, they can use Battle#on to check for the move dealing a critical
hit within the ModifyDamage event instead.
2015-08-12 16:02:12 -07:00
Ivo Julca
cd36fbfde2 Gulpfile: add more JSCS rules
- Disallow spaces between function names and round brackets.
- Disallow spaces inside array/object literal brackets.
- Disallow spaces before semicolons.
- Disallow yoda conditions for equality.
2015-07-28 19:38:53 -05:00
Marty-D
d00ed0c5c5 Fix trailing whitespace from cf295251a1 2015-07-24 21:26:28 -04:00
Pikachuun
cf295251a1 Fix Flower Gift 2015-07-24 20:03:25 -04:00
Kevin Lau
b310eb00b9 Add Intimidate test for double-KOs 2015-07-19 16:54:55 -07:00
Guangcong Luo
0eb6f4b244 Merge pull request #2006 from ascriptmaster/move-fixes-2
Fix PP deduction interactions with Pressure
2015-07-17 13:40:19 -05:00
Kevin Lau
913704c3ac Release and update Pressure tests
Added a check for Harsh Sun/Water moves failing and deducting PP.

Spikes has 32 max PP. Correct relevant values in the code.
2015-07-17 01:47:58 -07:00
Guangcong Luo
3bde6c758b Merge pull request #2050 from ascriptmaster/tests
Fix Mold Breaker interaction with Damp
2015-07-16 16:36:43 -05:00
Konrad Borowski
c0b71f03b7 Show that weather began even under Air Lock effect 2015-07-16 16:12:47 +02:00
Kevin Lau
55f08be727 Add many Ability tests related to Mold Breaker 2015-07-15 14:48:57 -07:00
Kevin Lau
72b61b25d6 Update Intimidate test to ensure ability activation order
Re-do the activation test with the Pokemon switched to ensure that ability
activation was based on speed instead of player order.
2015-07-13 20:39:25 -07:00
Kevin Lau
604194e7d4 Normalize wording on tests related to Mold Breaker
The two most common wordings were "suppressed" and "bypassed". Out of the
two, "suppressed" was chosen to be used across all tests.
2015-07-12 03:27:11 -07:00
Kevin Lau
e991c70f4c Update Intimidate test to check activation order 2015-07-07 13:20:32 -07:00
Kevin Lau
3c33a363fa Add Intimidate test to check simultaneous switches 2015-07-07 00:15:10 -07:00