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).
- 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
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.
* 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.
- 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
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`
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.
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.
* 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
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).
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
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.
* 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.
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
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.
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.
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.
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.
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.