Commit Graph

301 Commits

Author SHA1 Message Date
MacChaeger
05cdd33542 Fix Dancer activation order (#4009) 2017-09-23 20:17:00 -04:00
Guangcong Luo
0646743a6d Sim: Check Protect/etc before type immunities in gen 7
TryHit effects, like Protect, Lightningrod, Magic Bounce, etc now
activate before type immunities, rather than after.
2017-09-05 09:36:18 -04:00
Guangcong Luo
8d12d1e0d2 Refactor matchmaker
This removes the outdated user.searching object, instead tracking all
searching state from inside the matchmaker.
2017-09-05 05:34:27 -04:00
Guangcong Luo
7a9310ac66 Fix Matchmaker hotpatching
Matchmaker is now globally accessible under Ladders, rather than
needing to be manually required.

This fixes a crash when hotpatching certain things.
2017-09-01 06:29:21 -04:00
Guangcong Luo
cb459a37bc Rename matchmaker.startBattle -> Rooms.createBattle 2017-09-01 04:46:37 -04:00
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
Guangcong Luo
95e8bebeaf Revert "ProcessManager: refactor, fix memory leak, use Typescript (#3706)"
This reverts commit c9b93d3529.
2017-07-02 08:11:18 -04:00
Ben Davies
c9b93d3529 ProcessManager: refactor, fix memory leak, use Typescript (#3706)
- spawning and setting up child processes is now handled by
ProcessManager#constructor rather than needing to be done manually for
each module that uses ProcessManager
- direct references to ProcessManager in ProcessWrapper were removed to
prevent dead ProcessWrapper instances from being leaked when hotpatching
- process-manager.js and verifier.js now use Typescript
2017-06-30 09:09:13 +09:00
Guangcong Luo
0143ae28dd Replace fs module (#3686)
The new FS module is an abstraction layer over the built-in fs module.

The main reason it exists is because I need an abstraction layer I can
disable writing from. But that'll be in another commit.

Currently, mine is better because:
 - paths are always relative to PS's base directory
 - Promises (seriously wtf Node Core what are you thinking)
 - PS-style API: FS("foo.txt").write("bar") for easier argument order
 - mkdirp

This also increases the minimum supported Node version from v6.0 to
v7.7, because we now use async/await. Sorry for the inconvenience!

This also drops the mock-fs-require-fix dependency

mock-fs-require-fix was always kind of a huge hack. It's no longer
necessary, with an FS API that does everything it used to.

This removes a lot of other hacks from test/main.js, which is nice.
2017-06-24 13:42:54 -07:00
Konrad Borowski
56a05a82b6 Rename Gen6 formats to have [Gen 6] in name (#3683)
* Rename Gen6 formats to have [Gen 6] in name

* Add Gen 6 format aliases for bots

Those will be removed later when bots will be updated to know
about new format names.
2017-06-24 01:51:06 -07: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
Ben Davies
92c6c3e3ac Trivia: fix crash in Trivia#destroy, pause when too many players absent (#3531) 2017-05-13 19:35:57 -05:00
HoeenHero
36b56f5c44 Finish renaming tools to dex (#3526) 2017-05-12 17:11:30 -05:00
Guangcong Luo
9e180e4fc1 Remove MockBattle
No MockBattle feature needs to be kept out of sim/...
2017-05-05 16:57:18 -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
Ben Davies
8de4bdfecb Sockets: refactor to use maps (#3474) 2017-04-23 16:39:38 -07:00
Ben Davies
7002810044 Tests: import the Trivia module in a sane way, clean up users/rooms (#3455)
Using internal module API to require the Trivia module is insane when it's
very simple to do without it. The trivia room is deleted after the tests
finish, and users are now destroyed properly.
2017-04-17 22:45:12 -04:00
Ben Davies
7d27efb817 Matchmaking: move battle logging back to Rooms.global (#3454)
* Matchmaking: move battle logging back to Rooms.global

For now, logging should be dealt by the global room until logging can be
abstracted away from it. This makes it simpler to refactor the logic in
Matchmaker#startBattle to be handled by Rooms.createBattle where it belongs.

* Matchmaking: use Matchmaker#cancelSearch format parametre

Optimizes cancelling searches if the format is known
2017-04-15 17:51:34 -04:00
Ben Davies
5adac2bc56 Matchmaking: fix crash on user disconnect/merge
Challenges and searches weren't being cleared properly after moving
them out of GlobalRoom#onLeave.
2017-03-20 17:01:42 -05: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
Ben Davies
fa3136f6f4 Prevent JSON writers from being able to block I/O (#3368)
These are the last place process.nextTick should be used. Also fixes
BattleRoom's unit tests.
2017-03-17 17:42:10 -05:00
Ben Davies
213b697d7c Rooms: move matchmaking logic to ladders-matchmaker.js (#3364)
This abstracts matchmaking logic from the global room away to its own
module, allowing the two to be decoupled from each other entirely with
some refactoring.

Related to #3361
2017-03-17 02:42:30 -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
Guangcong Luo
5223e4b9ad Remove roomid from Battle
Battles never actually use the roomid for anything. This commit removes
it in preparation for a refactor to the sim API.
2017-03-09 13:51:13 -06:00
Ben Davies
5031794f97 Sockets: fix unit tests (#3281)
* Sockets: fix Sockets.killWorker not disconnecting connections

* Sockets: fix unit tests

- Fix crash when constructing mock sockets in certain cases
- Properly prevent workers from writing to stdout
- Fix race conditions in workers-related tests that were causing false
  positives

* Tests: mock workers now more closely imitate sockets' workers

This helps catch cases where messages are being sent in the wrong order
to the workers, e.g. messages sent to sockets that no longer exist.
2017-02-24 05:38:37 -06: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
Ben Davies
8a9ce4a12a Sockets: temporarily skip unit tests (#3235)
Until the crashes and workers' flooding of stdout are resolved.
2017-02-14 22:00:06 -06:00
Ben Davies
2d0e7dba25 Implement sockets.js unit tests (#3098)
These tests are just sanity checks for sockets.js' exported methods.
Tests for bugs will come later when those for related users.js methods
have been written.
2017-01-16 16:38:16 -06:00
Ben Davies
1a433e9972 Tests: clear all users created during rooms.js tests (#3097)
This left behind 7 users in Users.users before.
2017-01-15 13:29:28 -06:00
Ben Davies
b0c117ce7a Trivia: mitigate game end/question timeout callback race condition (#3080)
This isn't very easy to reproduce, so I can't properly test any fixes.
Trivia#broadcast writes to debug monitor rather than throwing if called after
the game instance destroys itself.
2017-01-07 04:13:19 -08: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
asgdf
1a922d9ea4 Don't allow locked users to roompromote (#2986) 2016-12-04 10:10:56 -06: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