Commit Graph

23714 Commits

Author SHA1 Message Date
asgdf
8dc80d0e8d Add missing space to battleban staff room notification (#4486) 2018-03-12 13:40:40 +09:00
KrisXV
8758cb6fbe Show help for /smogdex if no target is provided (#4484) 2018-03-11 23:11:30 -04:00
Matthew Glazar
81208685d1 Refactor some code to use sample
Mechanically refactor code which uses PRNG#random to calculate a random
array index to use PRNG#sample instead.
2018-03-12 05:53:33 +09:00
Matthew Glazar
6c2350f5b6 Refactor random indexes into sample function
Often, you just need a random item in an array. Throughout Pokemon
Showdown's code, there are many instances of the following pattern:

    let randomThing = things[this.random(things.length)];

Make this code easier to read by factoring the indexing into the
PRNG#sample function:

    let randomThing = this.sample(things);

Run the following sed script to refactor lots of code to use sample:

    s/\([a-zA-Z0-9.]\{1,\}\)\[this\.random(\1\.length)\]/this.sample(\1)/

This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
2018-03-12 05:53:33 +09:00
KrisXV
48c48282ec UU suspect test should be playable via challenge (#4482) 2018-03-11 16:09:36 +08:00
Bär Halberkamp
68bf432966 OTD: dirty hack to make the "no repeats for a month" work in tvbf 2018-03-11 02:53:53 +01:00
asgdf
459f7c919a Fix movesearch for trapping moves (#4480) 2018-03-11 08:09:54 +09:00
Jeremy Piemonte
ad6f3a0d6f Markshared: Require a reason (#4475) 2018-03-11 08:09:17 +09:00
KrisXV
fab3c855bc Battle Factory: Require Hail with Slush Rush (#4481) 2018-03-11 04:15:39 +08:00
urkerab
46f3683a3a Fix Z-Power behaviour while Transformed into Ultra (#4479) 2018-03-11 00:01:50 +08:00
The Immortal
94d7a42555 Random Battle updates 2018-03-10 22:58:56 +08:00
The Immortal
95b5a3410a
BF: Fix Sneasel EVs 2018-03-10 17:10:08 +08:00
strager
5a5b4182a3 Delete dead code (#4477)
According to `git grep getResidualStatuses`, the
Battle#getResidualStatuses function isn't referenced anywhere. Delete
the definition of that unused function.
2018-03-10 14:44:30 +09:00
Autistik2000
42abe5bb6b Fix broken link to beginner guide (#4476) 2018-03-10 14:23:50 +09:00
HoeenHero
2ca0fe7793 Unban Slowbro-Mega from UU suspect test 2018-03-09 16:48:27 +00:00
The Immortal
5181ea4650
Add UU suspect test 2018-03-09 23:26:10 +08:00
The Immortal
f1afc8ed8c
2v2: Ban Mega Salamence 2018-03-09 14:42:17 +08:00
Kris Johnson
0d1151ce5b Update format links 2018-03-09 08:56:29 +09:00
KrisXV
7c5e400855 STABmons: Ban Porygon-Z and restrict Spore (#4471)
https://www.smogon.com/forums/threads/stabmons.3587949/page-24#post-7711998
2018-03-09 05:38:06 +08:00
Marty-D
6f0d08722a
Remove Help Ticket link from locked message
Has been an unmitigated disaster without proper explanations in the Help Ticket form.
2018-03-08 15:02:48 -05:00
The Immortal
097152b5af
Correct BSS9 rules 2018-03-09 00:00:28 +08:00
Marty-D
c678014580
Update Choice locking for USUM
They fixed it so that ignoring the item allows other moves to be used. However, using another move, even one that isn't part of the moveset, before you've locked yourself into a move, locks you into that move until move selection happens again. For example, a Choice Specs Oricorio choosing to use Hurricane turn 1 but getting outsped by a Quiver Dance has it use Quiver Dance, then Hurricane fails (even if it doesn't know Quiver Dance). If it does know Quiver Dance it becomes locked into it, otherwise it can choose any move for use since the Choice lock breaks at move selection if you don't have that move anymore.
2018-03-08 10:44:14 -05:00
Marty-D
ca61471e50 Add new event Pokemon 2018-03-08 08:55:19 -05:00
The Immortal
85004a5f9a
Release Alolan starters' hidden abilities 2018-03-08 20:09:24 +08:00
Matthew Glazar
ddc85bf1f8 Random Battle: Refactor inverted randomChance calls
`!randomChance(_, _)` is hard to read. Clean up code which uses that
pattern by taking advantage of the following fact: `!randomChance(n, d)`
is truthy with the same probability as `randomChance(d - n, d)`.

Note: This transformation changes behaviour. Randomized teams with the
same PRNG seed might differ. The probability of each team is still the
same as before, however.
2018-03-08 20:11:33 +09:00
Matthew Glazar
674a995b0e Random Battle: Refactor some variable names
randomNum isn't a number anymore. Rename it to randomBool.

This commit should not change behaviour.
2018-03-08 20:11:33 +09:00
Matthew Glazar
df5988bacf Refactor some code to use randomChance
Mechanically refactor code which uses PRNG#random for booleans to use
PRNG#randomChance instead.

Take advantage of the following properties:

    random(x) < y        is equivalent to   randomChance(y, x)
    random(x) <= y       is equivalent to   random(x) < (y + 1), i.e. randomChance(y + 1, x)
    random(x) >= y       is equivalent to   !(random(x) < y), i.e. !randomChance(y, x)
    random(x) > y        is equivalent to   random(x) >= (y + 1), i.e. !randomChance(y + 1, x)
    random(x) === 0      is equivalent to   random(x) < 1, i.e. randomChance(1, x)
    !random(x)           is equivalent to   random(x) === 0, i.e. randomChance(1, x)
    Boolean(random(x))   is equivalent to   random(x) > 0, i.e. !randomChance(1, x)

This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
2018-03-08 20:11:33 +09:00
Matthew Glazar
45a876917d Refactor random booleans into randomChance function
Often, you just need a random boolean. Throughout Pokemon Showdown's
code, there are many creative ways of requesting random booleans. For
example:

    if (this.random(10) < 3) {
    if (this.isWeather(['sunnyday', 'desolateland']) || this.random(2) === 0) {
    let shiny = !this.random(1024);
    if (uberCount > 1 && this.random(5) >= 1) continue;
    if (!this.random(3)) ability = ability1.name;
    } else if ((ability === 'Iron Barbs' || ability === 'Rough Skin') && this.random(2)) {
    if (typeof secondary.chance === 'undefined' || this.random(256) <= effectChance) {
    if (accuracy !== true && this.random(256) > accuracy) {

Enable these methods to converge by introducing the PRNG#randomChance
function. It accepts a probability and returns true with that
probability.

Run the following sed script to refactor many common patterns to use
randomChance:

    s/this\.random(\([0-9]\{1,\}\)) >= \([0-9]\{1,\}\)/!this.randomChance(\2, \1)/g
    s/this\.random(\([0-9]\{1,\}\)) < \([0-9]\{1,\}\)/this.randomChance(\2, \1)/g
    s/this\.random(\([0-9]\{1,\}\)) === 0/this.randomChance(1, \1)/g
    s/!this\.random(\([0-9]\{1,\}\))/this.randomChance(1, \1)/g

The sed script takes advantage of the following properties:

    random(x) < y     is equivalent to   randomChance(y, x)
    random(x) >= y    is equivalent to   !(random(x) < y), i.e. !randomChance(y, x)
    random(x) === 0   is equivalent to   random(x) < 1, i.e. randomChance(1, x)
    !random(x)        is equivalent to   random(x) === 0, i.e. randomChance(1, x)

This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
2018-03-08 20:11:33 +09:00
Marty-D
e726c2fe72 Battleban: Show expiry and upload replays 2018-03-07 23:33:46 -05:00
Marty-D
42b3846c6c
Fix Jaboca/Rowap Berry activation 2018-03-08 01:45:47 +00:00
Marty-D
e5138993eb
Tiers: Add March quick changes 2018-03-07 14:47:39 -05:00
asgdf
d9c3b46b83 Extend Protective Pads unit tests (#4467) 2018-03-08 04:11:37 +09:00
Marty-D
6b1ce58f08
Remove BH suspect test 2018-03-07 14:00:24 -05:00
Jeremy Piemonte
9233024106 Battle ban: Handle users already in tournaments (#4468) 2018-03-08 03:43:27 +09:00
Insist
f3d7e6e912 Mafia: Fix typo (#4466) 2018-03-06 21:45:43 +08:00
whales
dda7e592ef Mafia: add commands to modify hammer (#4461) 2018-03-06 08:05:24 -05:00
ZestOfLife
4e3dd5dda2 Mafia: Add selflynch command (#4453) 2018-03-06 07:59:46 -05:00
The Immortal
888d077032 Add Battle Spot Special 9 2018-03-06 18:47:18 +08:00
asgdf
9448f51db7 Add unit test for Protective Pads/Mummy interaction (#4462) 2018-03-06 13:38:20 +09:00
KrisXV
d257e0a243 Move Snorlax to DUber (#4465)
https://www.smogon.com/forums/threads/usum-dou-stage-2-suspect-voting.3629784/page-2#post-7708807
2018-03-05 22:39:09 -05:00
Marty-D
d94ae94074
Remove Ultra Sinnoh Classic 2018-03-06 00:32:39 +00:00
KrisXV
5889519828 Nature Swap: Correctly calculate nature.minus (#4464) 2018-03-05 17:52:27 -06:00
Bär Halberkamp
68433ec474 Wifi: leave - in for pokemon ids 2018-03-05 15:10:12 +01:00
Guangcong Luo
de3e0e11c7 Change Chat.count argument order
This is purely a readability change; behind the scenes there's now more
magic going on, but magic is good for text processing functions, which
are otherwise way too verbose.
2018-03-05 21:19:37 +09:00
Guangcong Luo
cad1165ad4 Implement Chat.count
Adds some more magic to make Chat.plural more readable when used to
count things.

Overall, it's not _nearly_ as concise as I'd like, but it might be the
best we can get for now.
2018-03-05 20:57:25 +09:00
Guangcong Luo
115cf9a420 Add Help Ticket link to Locked message 2018-03-05 20:57:25 +09:00
Guangcong Luo
416f7b45d0 Improve indentation for canTalk 2018-03-05 20:57:25 +09:00
strager
5d08426faa Optimize no-op effects (#4460)
Various functions call ModdedDex#getEffect with null, undefined, or an
empty string. For example, in the common case, Battle#getWeather calls
getEffect with an empty string. In these cases, getEffect basically
returns the same object each time: a PureEffect indicating that no
effect with the given name exists.

Creating the dummy PureEffect is expensive and puts pressure on the
JavaScript garbage collector. Memoize the creation in getEffect to
improve performance.

(As a bonus, special-casing null, undefined, and empty strings also lets
us drop some noisy truthiness checks in getEffect.)

On my machine, this commit speeds up Pokemon Showdown's tests by 11%.

Methodology: With and without this commit, I ran mocha four times with
zsh' 'time' builtin, dropped the first result, and averaged the wall
times:

    mocha times before this commit:
    18.20s user 0.33s system 118% cpu 15.704 total
    17.91s user 0.34s system 118% cpu 15.454 total
    18.11s user 0.33s system 118% cpu 15.558 total

    mocha times after this commit:
    16.53s user 0.35s system 120% cpu 13.994 total
    16.43s user 0.34s system 120% cpu 13.918 total
    16.54s user 0.32s system 120% cpu 14.009 total

    Hardware:
    Mid 2012 MacBook Pro
    2.6 GHz Intel Core i7

    Software:
    Node v9.0.0
    macOS 10.10.5
2018-03-05 17:27:55 +09:00
strager
423509bceb Cache species-specific effects (e.g. Arceus); 20% overall perf win (#4459)
Battle#getRelevantEffectsInner performs a lookup for the base species of
every Pokemon with ModdedDex#getEffect, then invokes callbacks. The
lookup is expensive, and callbacks very rare. In fact, there are only
ever two callbacks: one for Arceus (SwitchIn) and one for Silvally
(SwitchIn).

Instead of an expensive ModdedDex#getEffect lookup for the callbacks,
put the callbacks directly on the Pokemon's Template object.

On my machine, this commit speeds up Pokemon Showdown's tests by 20%.

Methodology: With and without this commit, I ran mocha four times with
zsh' 'time' builtin, dropped the first result, and averaged the wall
times:

    mocha times before this commit:
    18.20s user 0.33s system 118% cpu 15.704 total
    17.91s user 0.34s system 118% cpu 15.454 total
    18.11s user 0.33s system 118% cpu 15.558 total

    mocha times after this commit:
    15.58s user 0.33s system 122% cpu 13.028 total
    15.32s user 0.33s system 121% cpu 12.890 total
    15.56s user 0.32s system 121% cpu 13.068 total

    Hardware:
    Mid 2012 MacBook Pro
    2.6 GHz Intel Core i7

    Software:
    Node v9.0.0
    macOS 10.10.5
2018-03-05 17:24:14 +09:00
Marty-D
d84441ccfd
Remove Doubles OU suspect test 2018-03-05 04:29:32 +00:00