@pkmn/engine 0.1.0-dev.729b1e87 → 0.1.0-dev.7cd30bd9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -7
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +111 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data.d.ts +1 -2
- package/build/pkg/data.js +3 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +1 -1
- package/build/pkg/protocol.js +1 -1
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +383 -0
- package/build/test/display.js.map +1 -0
- package/build/tools/debug.js +133 -0
- package/build/tools/debug.js.map +1 -0
- package/build.zig +17 -27
- package/package.json +39 -29
- package/src/bin/install-pkmn-engine +58 -31
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +4 -4
- package/src/lib/binding/wasm.zig +2 -2
- package/src/lib/gen1/README.md +37 -24
- package/src/lib/gen1/data.zig +6 -6
- package/src/lib/gen1/helpers.zig +0 -4
- package/src/lib/gen1/mechanics.zig +317 -256
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +3 -3
- package/src/test/display/pkmn.html.tmpl +368 -0
package/src/lib/gen1/README.md
CHANGED
|
@@ -332,7 +332,9 @@ must be gleaned through the `Battle` state). Useful size and offset information
|
|
|
332
332
|
the [`layout.json`](../../data/layout.json) which exists to simplify writing driver code.
|
|
333
333
|
|
|
334
334
|
Documentation of the wire protocol used for logging traces when `-Dtrace` is enabled can be found in
|
|
335
|
-
[PROTOCOL.md](../../../docs/PROTOCOL.md).
|
|
335
|
+
[PROTOCOL.md](../../../docs/PROTOCOL.md). Note that the
|
|
336
|
+
[`pkmn-debug`](../../../README.md#pkmn-debug) tool exists to display the binary protocol and battle
|
|
337
|
+
data in the browser for ease of debugging.
|
|
336
338
|
|
|
337
339
|
### `Battle`
|
|
338
340
|
|
|
@@ -467,7 +469,7 @@ Documentation of the wire protocol used for logging traces when `-Dtrace` is ena
|
|
|
467
469
|
|
|
468
470
|
In addition to its alternative [RNG semantics](#rng), Pokémon Showdown's implementation of the first
|
|
469
471
|
generation of Pokémon contains a number bugs, [many of which are known and have been documented on
|
|
470
|
-
Smogon](https://www.smogon.com/forums/
|
|
472
|
+
Smogon](https://www.smogon.com/forums/posts/5933177/show):
|
|
471
473
|
|
|
472
474
|
- moves on Pokémon Showdown can do 0 damage instead of failing or causing a [division-by-zero
|
|
473
475
|
freeze](https://pkmn.cc/bulba-glitch-1#Division_by_0).
|
|
@@ -476,23 +478,36 @@ Smogon](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3
|
|
|
476
478
|
- Confusion self-hits use the wrong damage formula resulting in off-by-one errors (and also fail to
|
|
477
479
|
account for an opponent's Reflect). Furthermore, the confusion self-hit damage will erroneously be
|
|
478
480
|
inflicted to the confused user's substitute if the confused user had been attempting to use a
|
|
479
|
-
self-targeting move.
|
|
481
|
+
self-targeting move. Finally, Pokémon Showdown erroneously considers the *uncapped* self-hit
|
|
482
|
+
damage for the purposes of tracking the battle's last damage.
|
|
480
483
|
|
|
481
484
|
Beyond the general bugs listed above, several move effects are implemented incorrectly by Pokémon
|
|
482
485
|
Showdown. Some of these moves are [too fundamentally broken to be implemented](#unimplementable) by
|
|
483
486
|
the pkmn engine, but the following moves have their broken behavior preserved in `-Dshowdown` mode:
|
|
484
487
|
|
|
488
|
+
- **Bide**: If the opponent faints after Bide inflicts damage on Pokémon Showdown residual damage
|
|
489
|
+
incorrectly still gets applied to Bide's user.
|
|
485
490
|
- **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
|
|
486
|
-
recoil/crash damage on Pokémon Showdown.
|
|
491
|
+
recoil/crash damage on Pokémon Showdown. Pokémon Showdown also updates the battle's last damage
|
|
492
|
+
field with the uncapped Leech Seed damage if the residual damage is applied which has consequences
|
|
493
|
+
for Bide and Counter.
|
|
487
494
|
- **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
|
|
488
495
|
Substitute but doesn't on Pokémon Showdown.
|
|
489
496
|
- **Flinch**: Flinching does not get cleared during move selection on Pokémon Showdown and is
|
|
490
497
|
instead cleared in Pokémon Showdown's "residual" phase, meaning the flinch status gets erroneously
|
|
491
498
|
preserved across fainting (as fainting triggers Pokémon Showdown's "instaswitch" behavior which
|
|
492
499
|
skips end-of-turn residuals).
|
|
500
|
+
- **Rage**: Rage boosts should still result in burn/paralysis [stat modification
|
|
501
|
+
errors](https://pkmn.cc/bulba-glitch-1#Stat_modification_errors) but don't on Pokémon Showdown.
|
|
502
|
+
Furthermore, Pokémon Showdown only builds Rage for Disable/Explosion (hit/miss) when attacking
|
|
503
|
+
into a Substitute instead of all moves. Pokémon Showdown also implements the [Rage and Thrash /
|
|
504
|
+
Petal Dance accuracy bug]( https://www.youtube.com/watch?v=NC5gbJeExbs) incorrectly, as the
|
|
505
|
+
accuracy only gets written when the volatile is present which can lead to incorrect accuracy
|
|
506
|
+
values on turns where Rage is used on the same turn as a move which modifies accuracy or evasion.
|
|
493
507
|
- **Thrash** / **Petal Dance**: once a Pokémon is locked into a thrashing move they will lose all
|
|
494
508
|
speed ties on Pokémon Showdown (due to the fact that if they win the speed tie their action will
|
|
495
|
-
then get "changed" and inserted back into the queue after their opponent's action).
|
|
509
|
+
then get "changed" and inserted back into the queue after their opponent's action). Pokémon
|
|
510
|
+
Showdown also implements accuracy incorrectly, as covered above.
|
|
496
511
|
- **Freeze** / **Sleep**: Pokémon Showdown requires a move to be selected when a Pokémon is frozen
|
|
497
512
|
or sleeping and uses that in the event that the status is removed while on the cartridge no
|
|
498
513
|
selection is possible and no turn exists for the thawed/woken Pokémon to act except in the case of
|
|
@@ -508,7 +523,8 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
508
523
|
implement by Pokémon Showdown.
|
|
509
524
|
- **Roar** / **Whirlwind**: these moves can miss on Pokémon Showdown (and advance the RNG when
|
|
510
525
|
checking) which is incorrect (these moves should always fail, but do not check accuracy or advance
|
|
511
|
-
the RNG).
|
|
526
|
+
the RNG). More importantly, these moves should *not* cause the tracked last battle damage to be
|
|
527
|
+
zeroed, but on Pokémon Showdown they do.
|
|
512
528
|
- **Substitute**: in addition to the [Substitute + Confusion
|
|
513
529
|
glitch](https://pkmn.cc/bulba-glitch-1#Substitute_.2B_Confusion_glitch) not being implemented
|
|
514
530
|
correctly (covered above), the [Substitute 1/4
|
|
@@ -516,7 +532,8 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
516
532
|
Pokémon Showdown implementing the health check based on floating point division instead of integer
|
|
517
533
|
divison like on the cartridge (meaning the Substitute 1/4 glitch will only occur if the Pokémon's
|
|
518
534
|
maximum HP is evenly divisible by 4). Finally, Substitute also incorrectly blocks Dream Eater on
|
|
519
|
-
Pokémon Showdown
|
|
535
|
+
Pokémon Showdown and will incorrectly still heal 1 HP for any draining moves if the attack does 0
|
|
536
|
+
damage.
|
|
520
537
|
|
|
521
538
|
In addition to numerous cases where Pokémon Showdown uses the wrong type of message (e.g. `|-fail`
|
|
522
539
|
vs. `|-miss|` vs. `|-immune|`, e.g. in the case of Leech Seed) which are not documented here, Pokémon
|
|
@@ -550,7 +567,7 @@ called out in the `|rule|` section at the beginning of a battle's log):
|
|
|
550
567
|
`|rule|` section** in Generation I (or II) as the actual order of switches here does not have
|
|
551
568
|
competitive implications like it does in Generation III, but it is still contrary to how the games
|
|
552
569
|
work where the [host (Player 1)'s Pokemon would switch
|
|
553
|
-
first](https://www.smogon.com/forums/
|
|
570
|
+
first](https://www.smogon.com/forums/posts/5989318/show).
|
|
554
571
|
|
|
555
572
|
Pokémon Showdown enforces several clauses *before* the battle: **Cleric Clause** (all Pokémon must
|
|
556
573
|
have full HP and PP, and not have any status conditions prior to the battle), **Stat Tradeback
|
|
@@ -571,13 +588,12 @@ left up to a client to support.
|
|
|
571
588
|
|
|
572
589
|
Numerous moves on Pokémon Showdown are broken not simply due to local issues in the implementation
|
|
573
590
|
of their effects but instead due to **global issues** related to fundamental mechanics such as
|
|
574
|
-
[broken move
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
changes or dramatically deviating from the correct control flow):
|
|
591
|
+
[broken move selection](https://www.smogon.com/forums/posts/8655897/show), using move name instead
|
|
592
|
+
of slot to determine move identity, implementing volatile statuses incorrectly or not understanding
|
|
593
|
+
how moves which call other moves work means that it isn't possible to completely implement Pokémon
|
|
594
|
+
Showdown's behavior for the following moves (the pkmn engine attempts to reproduce as much of the
|
|
595
|
+
behavior that can be reproduced without making data structure changes or dramatically deviating from
|
|
596
|
+
the correct control flow):
|
|
581
597
|
|
|
582
598
|
- **Wrap**: Binding moves like Wrap are implemented on Pokémon Showdown with an artificial
|
|
583
599
|
`partialtrappinglock` volatile as opposed to how it works on the cartridge which simply relies on
|
|
@@ -666,10 +682,10 @@ compatibility mode, the implications of these differences are outlined below:
|
|
|
666
682
|
Finally, the **initial 10-byte seed for link battles on Pokémon Red cannot include bytes larger than
|
|
667
683
|
the `SERIAL_PREAMBLE_BYTE`**, so must be in the range $\left[0, 252\right]$. This has implications
|
|
668
684
|
on the first 10 random numbers generated during the battle and has [**non-trivial competitive
|
|
669
|
-
implications**](https://www.smogon.com/forums/
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
685
|
+
implications**](https://www.smogon.com/forums/posts/9068411/show) (at the start of the battle move
|
|
686
|
+
effects become more likely, the ["1/256-miss" glitch](https://glitchcity.wiki/1/256_miss_glitch)
|
|
687
|
+
cannot happen, Player 1 is more likely to win speed ties, etc) that Pokémon Showdown cannot
|
|
688
|
+
replicate due to everything described above.
|
|
673
689
|
|
|
674
690
|
All of places in the link battle code where randomness is required are outlined below:
|
|
675
691
|
|
|
@@ -768,11 +784,8 @@ The pkmn engine attempts to adhere to certain naming conventions:
|
|
|
768
784
|
## Resources
|
|
769
785
|
|
|
770
786
|
- [pret/pokered](https://github.com/pret/pokered/) disassembly
|
|
771
|
-
- [Gen I Main Battle
|
|
772
|
-
Function](https://www.smogon.com/forums/threads/past-gens-research-thread.3506992/#post-5878612) -
|
|
773
|
-
Crystal_
|
|
787
|
+
- [Gen I Main Battle Function](https://www.smogon.com/forums/posts/5878612/show) - Crystal_
|
|
774
788
|
- [Pokemon Showdown!](https://github.com/smogon/pokemon-showdown)
|
|
775
789
|
- [List of glitches (Generation
|
|
776
790
|
I)](https://bulbapedia.bulbagarden.net/wiki/List_of_glitches_(Generation_I))
|
|
777
|
-
- [Pokémon Showdown RBY
|
|
778
|
-
Bugs](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/#post-5933177)
|
|
791
|
+
- [Pokémon Showdown RBY Bugs](https://www.smogon.com/forums/posts/5933177/show)
|
package/src/lib/gen1/data.zig
CHANGED
|
@@ -17,16 +17,16 @@ const expectEqual = std.testing.expectEqual;
|
|
|
17
17
|
const expect = std.testing.expect;
|
|
18
18
|
|
|
19
19
|
/// The minimum size in bytes required to hold all Generation I choice options.
|
|
20
|
-
pub const
|
|
20
|
+
pub const MAX_CHOICES: usize = 9; // move 1..4, switch 2..6
|
|
21
21
|
/// The optimal size in bytes required to hold all Generation I choice options.
|
|
22
|
-
/// At least as large as
|
|
22
|
+
/// At least as large as MAX_CHOICES.
|
|
23
23
|
pub const MAX_LOGS: usize = 180;
|
|
24
24
|
|
|
25
25
|
/// The maximum number of bytes possibly logged by a single Generation I update.
|
|
26
|
-
pub const
|
|
27
|
-
|
|
26
|
+
pub const CHOICES_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
27
|
+
MAX_CHOICES
|
|
28
28
|
else
|
|
29
|
-
std.math.ceilPowerOfTwo(usize,
|
|
29
|
+
std.math.ceilPowerOfTwo(usize, MAX_CHOICES) catch unreachable;
|
|
30
30
|
/// The optimal size in bytes required to hold the largest amount of log data possible from a
|
|
31
31
|
/// single Generation I update. At least as large as MAX_LOGS.
|
|
32
32
|
pub const LOGS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
@@ -272,7 +272,7 @@ pub const Status = enum(u8) {
|
|
|
272
272
|
return num > 0;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
///
|
|
275
|
+
/// Returns a human-readable representation of the status `num`.
|
|
276
276
|
pub fn name(num: u8) []const u8 {
|
|
277
277
|
if (Status.is(num, .EXT)) return if (num == Status.TOX) "TOX" else "SLF";
|
|
278
278
|
if (Status.is(num, .SLP)) return "SLP";
|
package/src/lib/gen1/helpers.zig
CHANGED
|
@@ -216,11 +216,7 @@ fn blocked(m: Move) bool {
|
|
|
216
216
|
if (Move.get(m).effect == .Binding) return true;
|
|
217
217
|
return switch (m) {
|
|
218
218
|
.Counter,
|
|
219
|
-
// FIXME: test and see if this can be removed or document
|
|
220
|
-
.Rage,
|
|
221
219
|
.Mimic,
|
|
222
|
-
// FIXME: test and see if this can be removed or document
|
|
223
|
-
.Bide,
|
|
224
220
|
.Metronome,
|
|
225
221
|
.MirrorMove,
|
|
226
222
|
.Transform,
|