@pkmn/engine 0.1.0-dev.af1565df → 0.1.0-dev.c4dec0f7
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 +22 -50
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/data.d.ts +2 -1
- package/build/pkg/data.js +5 -3
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +4 -5
- package/build/pkg/gen1.js +24 -43
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +12 -15
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +2 -4
- package/build/pkg/protocol.js +2 -4
- package/build/pkg/protocol.js.map +1 -1
- package/build.zig +34 -24
- package/package.json +29 -40
- package/src/bin/install-pkmn-engine +33 -60
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +0 -1
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +85 -119
- package/src/lib/gen1/data.zig +17 -19
- package/src/lib/gen1/helpers.zig +15 -4
- package/src/lib/gen1/mechanics.zig +313 -431
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
- package/build/pkg/addon.d.ts +0 -7
- package/build/pkg/addon.js +0 -111
- package/build/pkg/addon.js.map +0 -1
- package/build/test/display.js +0 -400
- package/build/test/display.js.map +0 -1
- package/build/tools/debug.js +0 -133
- package/build/tools/debug.js.map +0 -1
- package/src/bin/pkmn-debug +0 -62
- package/src/test/display/pkmn.html.tmpl +0 -368
package/src/lib/gen1/README.md
CHANGED
|
@@ -28,36 +28,35 @@ list of additional reference [**resources**](#resources).
|
|
|
28
28
|
|
|
29
29
|
The following information is required to simulate a Generation I Pokémon battle:
|
|
30
30
|
|
|
31
|
-
| pkmn
|
|
32
|
-
|
|
|
33
|
-
| `battle.seed`
|
|
34
|
-
| `battle.turn`
|
|
35
|
-
| `battle.last_damage`
|
|
36
|
-
| `side.{active,pokemon}`
|
|
37
|
-
| `side.team`
|
|
38
|
-
| `side.last_used_move`
|
|
39
|
-
| `side.last_selected_move`
|
|
40
|
-
| `battle.
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `pokemon.
|
|
45
|
-
| `{pokemon,active}.
|
|
46
|
-
| `
|
|
47
|
-
| `pokemon.
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `active.
|
|
52
|
-
| `
|
|
53
|
-
| `active.
|
|
54
|
-
| `
|
|
55
|
-
| `volatiles.
|
|
56
|
-
| `volatiles.
|
|
57
|
-
| `volatiles.
|
|
58
|
-
| `volatiles.
|
|
59
|
-
| `volatiles.
|
|
60
|
-
| `volatiles.disabled_{move,duration}` | `PlayerDisabledMove{,Number}` | `volatiles.disable.{move,time}` |
|
|
31
|
+
| pkmn | Pokémon Red (pret) | Pokémon Showdown |
|
|
32
|
+
| ------------------------------------ | ---------------------------------- | -------------------------------------- |
|
|
33
|
+
| `battle.seed` | `Random{Add,Sub}` | `battle.seed` |
|
|
34
|
+
| `battle.turn` | - | `battle.turn` |
|
|
35
|
+
| `battle.last_damage` | `Damage` | `battle.lastDamage` |
|
|
36
|
+
| `side.{active,pokemon}` | `PlayerMonNumber`/`BattleMon` | `side.active` |
|
|
37
|
+
| `side.team` | `PartyMons` | `side.pokemon` |
|
|
38
|
+
| `side.last_used_move` | `PlayerUsedMove` | `pokemon.lastMove` |
|
|
39
|
+
| `side.last_selected_move` | `PlayerSelectedMove` | `side.lastSelectedMove` |
|
|
40
|
+
| `battle.last_selected_indexes` | `PlayerMoveListIndex` | `side.lastMove` |
|
|
41
|
+
| `side.order` | - | `pokemon.position` |
|
|
42
|
+
| `{pokemon,active}.moves` | `{party,battle}_struct.{Moves,PP}` | `pokemon.{baseMoveSlots,moveSlots}` |
|
|
43
|
+
| `pokemon.hp` | `{party,battle}_struct.HP` | `pokemon.hp` |
|
|
44
|
+
| `{pokemon,active}.status` | `{party,battle}_struct.Status` | `pokemon.status` |
|
|
45
|
+
| `{pokemon,active}.level` | `PlayerMonUnmodifiedLevel` | `pokemon.level` |
|
|
46
|
+
| `pokemon.species` | `party_struct.Species` | `pokemon.baseSpecies` |
|
|
47
|
+
| `pokemon.stats` | `box_struct.Stats` | `pokemon.baseStoredStats` |
|
|
48
|
+
| `active.stats` | `battle_struct.Stats` | `pokemon.modifiedStats` |
|
|
49
|
+
| `volatiles.transform` | `PlayerMonUnmodified*` | `pokemon.storedStats` |
|
|
50
|
+
| `active.species` | `battle_struct.Species` | `pokemon.species` |
|
|
51
|
+
| `{pokemon,active}.types` | `{party,battle}_struct.Type` | `pokemon.types` |
|
|
52
|
+
| `active.boosts` | `PlayerMon*Mod` | `pokemon.boosts` |
|
|
53
|
+
| `active.volatiles` | `PlayerBattleStatus{1,2,3}` | `pokemon.volatiles` |
|
|
54
|
+
| `volatiles.state` | `PlayerBideAccumulatedDamage` | `volatiles.bide.totalDamage` |
|
|
55
|
+
| `volatiles.attacks` | `PlayerNumAttacksLeft` | `volatiles.{bide,lockedmove}.duration` |
|
|
56
|
+
| `volatiles.confusion` | `PlayerConfusedCounter` | `volatiles.confusion.duration` |
|
|
57
|
+
| `volatiles.toxic` | `PlayerToxicCounter` | `volatiles.residualdmg.counter` |
|
|
58
|
+
| `volatiles.substitute` | `PlayerSubstituteHP` | `volatiles.substitute.hp` |
|
|
59
|
+
| `volatiles.disabled_{move,duration}` | `PlayerDisabledMove{,Number}` | `volatiles.disable.{move,time}` |
|
|
61
60
|
|
|
62
61
|
- Pokémon Showdown [does not implement the correct Generation I RNG](#rng) and as such its `seed` is
|
|
63
62
|
different
|
|
@@ -69,9 +68,6 @@ The following information is required to simulate a Generation I Pokémon battle
|
|
|
69
68
|
Counter and is not set and cleared in the correct locations. `Pokemon.lastMove` matches
|
|
70
69
|
`PlayerUsedMove` more often so is what the engine attempts to model, despite the implications for
|
|
71
70
|
Counter)
|
|
72
|
-
- `battle.last_moves` doesn't map precisely to cartridge concepts because it is used to track desyncs
|
|
73
|
-
which instead are represented on the cartridge as discrepancies between the two separate battle states
|
|
74
|
-
that exist in the link battle.
|
|
75
71
|
- Pokémon Showdown does not implement the [partial-trapping move Mirror Move
|
|
76
72
|
glitch](https://glitchcity.wiki/Partial_trapping_move_Mirror_Move_link_battle_glitch) and as such
|
|
77
73
|
does not need to keep track of a player's last selected move index (`PlayerMoveListIndex`)
|
|
@@ -102,8 +98,8 @@ The following information is required to simulate a Generation I Pokémon battle
|
|
|
102
98
|
store general information about the battle. Unlike in Pokémon Showdown there is a distinction
|
|
103
99
|
between the data structure for the "active" Pokémon and its party members (see below).
|
|
104
100
|
|
|
105
|
-
Due to layout constraints,
|
|
106
|
-
otherwise be the padding bytes of`Battle` (the `
|
|
101
|
+
Due to layout constraints, the index of the last selected move for a side is stored in what would
|
|
102
|
+
otherwise be the padding bytes of`Battle` (the `last_selected_indexes` field) instead of in `Side`.
|
|
107
103
|
|
|
108
104
|
### `Pokemon` / `ActivePokemon`
|
|
109
105
|
|
|
@@ -202,7 +198,7 @@ above, PP information isn't strictly necessary in Generation I so is dropped. `M
|
|
|
202
198
|
a special sentinel value to indicate `null`. Move PP data is only included for testing and is not
|
|
203
199
|
necessary for the actual engine implementation.
|
|
204
200
|
|
|
205
|
-
In order to workaround various [Pokémon Showdown bugs](#bugs) and to support its protocol in
|
|
201
|
+
In order to workaround various [Pokémon Showdown bugs](#bugs) and to support its protocol in traces,
|
|
206
202
|
additional information is stored in `Move.Data` (`targets`) about what Pokémon Showdown believes the
|
|
207
203
|
`Move.Target` to be (despite the concept of targeting not existing until Generation III when Double
|
|
208
204
|
battles were introduced). More specifically, a move's "targeting" status is required in various
|
|
@@ -335,33 +331,28 @@ does not produce an equivalent to Pokémon Showdown's `|request|` protocol messa
|
|
|
335
331
|
must be gleaned through the `Battle` state). Useful size and offset information can be found in
|
|
336
332
|
the [`layout.json`](../../data/layout.json) which exists to simplify writing driver code.
|
|
337
333
|
|
|
338
|
-
Documentation of the wire protocol used for
|
|
339
|
-
|
|
340
|
-
[`pkmn-debug`](../../../README.md#pkmn-debug) tool exists to display the binary protocol and battle
|
|
341
|
-
data in the browser for ease of debugging.
|
|
334
|
+
Documentation of the wire protocol used for logging traces when `-Dtrace` is enabled can be found in
|
|
335
|
+
[PROTOCOL.md](../../../docs/PROTOCOL.md).
|
|
342
336
|
|
|
343
337
|
### `Battle`
|
|
344
338
|
|
|
345
|
-
| Start | End | Data
|
|
346
|
-
| ------- | ------- |
|
|
347
|
-
| 0 | 184 | [`sides[0]`](#side)
|
|
348
|
-
| 184 | 368 | [`sides[1]`](#side)
|
|
349
|
-
| 368 | 370 | `turn`
|
|
350
|
-
| 370 | 372 | `last_damage`
|
|
351
|
-
| 372 | 373-376 | `
|
|
352
|
-
| 373-376 | 384 | `rng`
|
|
339
|
+
| Start | End | Data | Description |
|
|
340
|
+
| ------- | ------- | ----------------------- | ------------------------------------------------------- |
|
|
341
|
+
| 0 | 184 | [`sides[0]`](#side) | Player 1's side |
|
|
342
|
+
| 184 | 368 | [`sides[1]`](#side) | Player 2's side |
|
|
343
|
+
| 368 | 370 | `turn` | The current turn number |
|
|
344
|
+
| 370 | 372 | `last_damage` | The last damage dealt by either side |
|
|
345
|
+
| 372 | 373-376 | `last_selected_indexes` | The slot index of the last selected moves for each side |
|
|
346
|
+
| 373-376 | 384 | `rng` | The RNG state |
|
|
353
347
|
|
|
354
348
|
- the current `turn` is 2 bytes, written in native-endianness
|
|
355
|
-
- `
|
|
356
|
-
(`-Dshowdown`). In either case it stores
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
- otherwise the first 3 bits of byte 372 stores the last selected move index of `side[0]` and the
|
|
363
|
-
next bit stores whether that side's last executed move would have been considered "counterable",
|
|
364
|
-
with the same information for `side[1]`'s being stored in the second 4 bits
|
|
349
|
+
- `last_selected_indexes` layout depends on whether or not Pokémon Showdown compatibility mode is
|
|
350
|
+
enabled (`-Dshowdown`). In either case it stores a move "slot", where 0 is used as an empty value and
|
|
351
|
+
1-4 represent actual moves:
|
|
352
|
+
- if `showdown` is enabled bytes 372 and 373 are used to store the last selected move index of
|
|
353
|
+
`side[0]` and bytes 374 and 375 store the last selected move index of `side[1]`
|
|
354
|
+
- otherwise byte 372 stores the last selected move index of `side[0]` in its first 4 bits and
|
|
355
|
+
`side[1]`'s in its second 4 bits
|
|
365
356
|
- the `rng` depends on whether or not Pokémon Showdown compatibility mode is enabled (`-Dshowdown`):
|
|
366
357
|
- if `showdown` is enabled, the RNG state begins on byte 376 and consists of a 64-bit seed,
|
|
367
358
|
written in native-endianness
|
|
@@ -476,7 +467,7 @@ data in the browser for ease of debugging.
|
|
|
476
467
|
|
|
477
468
|
In addition to its alternative [RNG semantics](#rng), Pokémon Showdown's implementation of the first
|
|
478
469
|
generation of Pokémon contains a number bugs, [many of which are known and have been documented on
|
|
479
|
-
Smogon](https://www.smogon.com/forums/
|
|
470
|
+
Smogon](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/#post-5933177):
|
|
480
471
|
|
|
481
472
|
- moves on Pokémon Showdown can do 0 damage instead of failing or causing a [division-by-zero
|
|
482
473
|
freeze](https://pkmn.cc/bulba-glitch-1#Division_by_0).
|
|
@@ -485,19 +476,12 @@ Smogon](https://www.smogon.com/forums/posts/5933177/show):
|
|
|
485
476
|
- Confusion self-hits use the wrong damage formula resulting in off-by-one errors (and also fail to
|
|
486
477
|
account for an opponent's Reflect). Furthermore, the confusion self-hit damage will erroneously be
|
|
487
478
|
inflicted to the confused user's substitute if the confused user had been attempting to use a
|
|
488
|
-
self-targeting move.
|
|
489
|
-
damage for the purposes of tracking the battle's last damage.
|
|
479
|
+
self-targeting move.
|
|
490
480
|
|
|
491
481
|
Beyond the general bugs listed above, several move effects are implemented incorrectly by Pokémon
|
|
492
482
|
Showdown. Some of these moves are [too fundamentally broken to be implemented](#unimplementable) by
|
|
493
483
|
the pkmn engine, but the following moves have their broken behavior preserved in `-Dshowdown` mode:
|
|
494
484
|
|
|
495
|
-
- **Bide**: Bide's damage can overflow if OHKO moves are involved because OHKO moves work by setting
|
|
496
|
-
the damage to 65535 - Pokémon Showdown doesn't implement this overflow and instead lets Bide's
|
|
497
|
-
damage grow unbounded. Additionally, if the opponent faints after Bide inflicts damage on Pokémon
|
|
498
|
-
Showdown residual damage incorrectly still gets applied to Bide's user.
|
|
499
|
-
- **Counter**: On Pokémon Showdown choices made while sleeping (which should not have been
|
|
500
|
-
registered) can erroneously cause Counter to trigger Desync Clause Mod behavior.
|
|
501
485
|
- **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
|
|
502
486
|
recoil/crash damage on Pokémon Showdown.
|
|
503
487
|
- **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
|
|
@@ -506,17 +490,9 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
506
490
|
instead cleared in Pokémon Showdown's "residual" phase, meaning the flinch status gets erroneously
|
|
507
491
|
preserved across fainting (as fainting triggers Pokémon Showdown's "instaswitch" behavior which
|
|
508
492
|
skips end-of-turn residuals).
|
|
509
|
-
- **Rage**: Rage boosts should still result in burn/paralysis [stat modification
|
|
510
|
-
errors](https://pkmn.cc/bulba-glitch-1#Stat_modification_errors) but don't on Pokémon Showdown.
|
|
511
|
-
Furthermore, Pokémon Showdown only builds Rage for Disable/Explosion (hit/miss) when attacking
|
|
512
|
-
into a Substitute instead of all moves. Pokémon Showdown also implements the [Rage and Thrash /
|
|
513
|
-
Petal Dance accuracy bug]( https://www.youtube.com/watch?v=NC5gbJeExbs) incorrectly, as the
|
|
514
|
-
accuracy only gets written when the volatile is present which can lead to incorrect accuracy
|
|
515
|
-
values on turns where Rage is used on the same turn as a move which modifies accuracy or evasion.
|
|
516
493
|
- **Thrash** / **Petal Dance**: once a Pokémon is locked into a thrashing move they will lose all
|
|
517
494
|
speed ties on Pokémon Showdown (due to the fact that if they win the speed tie their action will
|
|
518
|
-
then get "changed" and inserted back into the queue after their opponent's action).
|
|
519
|
-
Showdown also implements accuracy incorrectly, as covered above.
|
|
495
|
+
then get "changed" and inserted back into the queue after their opponent's action).
|
|
520
496
|
- **Freeze** / **Sleep**: Pokémon Showdown requires a move to be selected when a Pokémon is frozen
|
|
521
497
|
or sleeping and uses that in the event that the status is removed while on the cartridge no
|
|
522
498
|
selection is possible and no turn exists for the thawed/woken Pokémon to act except in the case of
|
|
@@ -532,21 +508,15 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
532
508
|
implement by Pokémon Showdown.
|
|
533
509
|
- **Roar** / **Whirlwind**: these moves can miss on Pokémon Showdown (and advance the RNG when
|
|
534
510
|
checking) which is incorrect (these moves should always fail, but do not check accuracy or advance
|
|
535
|
-
the RNG).
|
|
536
|
-
zeroed, but on Pokémon Showdown they do.
|
|
511
|
+
the RNG).
|
|
537
512
|
- **Substitute**: in addition to the [Substitute + Confusion
|
|
538
513
|
glitch](https://pkmn.cc/bulba-glitch-1#Substitute_.2B_Confusion_glitch) not being implemented
|
|
539
514
|
correctly (covered above), the [Substitute 1/4
|
|
540
515
|
glitch](https://glitchcity.wiki/Substitute_%C2%BC_HP_glitch) also fails in many cases due to
|
|
541
516
|
Pokémon Showdown implementing the health check based on floating point division instead of integer
|
|
542
517
|
divison like on the cartridge (meaning the Substitute 1/4 glitch will only occur if the Pokémon's
|
|
543
|
-
maximum HP is evenly divisible by 4). Substitute also incorrectly blocks Dream Eater on
|
|
544
|
-
Pokémon Showdown
|
|
545
|
-
damage. Finally, Pokémon Showdown uses a `subFainted` field to track whether a Substitute was
|
|
546
|
-
broken in order to know when to nullify a move's effect, only it doesn't get cleared at the end of
|
|
547
|
-
the turn and can result in incorrect behavior on subsequent turns with the moves Mirror Move and
|
|
548
|
-
Metronome that invoke `runMove` (which is where `subFainted` gets cleared) on the user but skips
|
|
549
|
-
calling it for the eventual true target.
|
|
518
|
+
maximum HP is evenly divisible by 4). Finally, Substitute also incorrectly blocks Dream Eater on
|
|
519
|
+
Pokémon Showdown.
|
|
550
520
|
|
|
551
521
|
In addition to numerous cases where Pokémon Showdown uses the wrong type of message (e.g. `|-fail`
|
|
552
522
|
vs. `|-miss|` vs. `|-immune|`, e.g. in the case of Leech Seed) which are not documented here, Pokémon
|
|
@@ -580,7 +550,7 @@ called out in the `|rule|` section at the beginning of a battle's log):
|
|
|
580
550
|
`|rule|` section** in Generation I (or II) as the actual order of switches here does not have
|
|
581
551
|
competitive implications like it does in Generation III, but it is still contrary to how the games
|
|
582
552
|
work where the [host (Player 1)'s Pokemon would switch
|
|
583
|
-
first](https://www.smogon.com/forums/
|
|
553
|
+
first](https://www.smogon.com/forums/threads/gen-3-on-ps-final-fixes.3527268/post-5989318).
|
|
584
554
|
|
|
585
555
|
Pokémon Showdown enforces several clauses *before* the battle: **Cleric Clause** (all Pokémon must
|
|
586
556
|
have full HP and PP, and not have any status conditions prior to the battle), **Stat Tradeback
|
|
@@ -601,12 +571,13 @@ left up to a client to support.
|
|
|
601
571
|
|
|
602
572
|
Numerous moves on Pokémon Showdown are broken not simply due to local issues in the implementation
|
|
603
573
|
of their effects but instead due to **global issues** related to fundamental mechanics such as
|
|
604
|
-
[broken move
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
the
|
|
574
|
+
[broken move
|
|
575
|
+
selection](https://www.smogon.com/forums/threads/rby-fight-button-simulation-improvements-fix-partial-trapping-improve-counter.3673280/#post-8655897),
|
|
576
|
+
using move name instead of slot to determine move identity, implementing volatile statuses
|
|
577
|
+
incorrectly or not understanding how moves which call other moves work means that it isn't possible
|
|
578
|
+
to completely implement Pokémon Showdown's behavior for the following moves (the pkmn engine
|
|
579
|
+
attempts to reproduce as much of the behavior that can be reproduced without making data structure
|
|
580
|
+
changes or dramatically deviating from the correct control flow):
|
|
610
581
|
|
|
611
582
|
- **Wrap**: Binding moves like Wrap are implemented on Pokémon Showdown with an artificial
|
|
612
583
|
`partialtrappinglock` volatile as opposed to how it works on the cartridge which simply relies on
|
|
@@ -616,9 +587,9 @@ the correct control flow):
|
|
|
616
587
|
still gets a turn under the [trapping sleep
|
|
617
588
|
glitch](https://glitchcity.wiki/Trapping_move_and_sleep_glitch), Wrap does 0 damage against
|
|
618
589
|
Ghost-type Pokémon instead of properly respecting immunity, and binding effects are handled in the
|
|
619
|
-
wrong order in the code
|
|
620
|
-
|
|
621
|
-
|
|
590
|
+
wrong order in the code.
|
|
591
|
+
- **Counter**: On Pokémon Showdown choices made while sleeping (which should not have been
|
|
592
|
+
registered) can erroneously cause Counter to trigger Desync Clause Mod behavior.
|
|
622
593
|
- **Mimic**: Pokémon Showdown checks that the user of Mimic has Mimic in one of their move slots,
|
|
623
594
|
which means Mimic legally called via Metronome or Mirror Move will only work if the user also has
|
|
624
595
|
Mimic (and the moved mimicked by Mimic called via Metronome / Mirror Move will erroneously
|
|
@@ -626,27 +597,19 @@ the correct control flow):
|
|
|
626
597
|
because Pokémon Showdown deducts PP based on a move's name instead of slot, if Mimic copies a move
|
|
627
598
|
the Pokémon already knows, PP deduction for using either the original move of the mimicked move
|
|
628
599
|
will instead deduct PP for whichever appears at the lower move slot index and the PP will be
|
|
629
|
-
allowed to go negative (effectively allowing for infinite PP use).
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
Mirror Move (though Pokémon Showdown has its own weird behavior and does not implement the
|
|
633
|
-
[partial trapping move Mirror Move
|
|
600
|
+
allowed to go negative (effectively allowing for infinite PP use).
|
|
601
|
+
- **Mirror Move**: Binding moves misbehave when used via Mirror Move (though Pokémon Showdown has
|
|
602
|
+
its own weird behavior and does not implement the [partial trapping move Mirror Move
|
|
634
603
|
glitch](https://glitchcity.wiki/Partial_trapping_move_Mirror_Move_link_battle_glitch) that exists
|
|
635
|
-
on the cartridge).
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
- **
|
|
640
|
-
Move cannot mutually call each other more than 3 times in a row without causing the Pokémon
|
|
641
|
-
Showdown simulator to crash due to defensive safety checks that do not exist on the cartridge.
|
|
642
|
-
- **Transform**: Transform screws up the effect of Disable, because on Pokémon Showdown, Disable
|
|
604
|
+
on the cartridge).
|
|
605
|
+
- **Metronome**: In addition to the issues with binding moves, Metronome and Mirror Move cannot
|
|
606
|
+
mutually call each other more than 3 times in a row without causing the Pokémon Showdown simulator
|
|
607
|
+
to crash due to defensive safety checks that do not exist on the cartridge.
|
|
608
|
+
- **Transform**: Transform screws up the effect of Disable, because on Pokémon Showdown, Disable
|
|
643
609
|
prevents moves of a given *name* from being used (e.g. "Water Gun") as opposed to moves in a
|
|
644
610
|
specific *slot* (e.g. the 2nd move slot), and a Pokémon's moves can change after Transform (this
|
|
645
|
-
is not an issue with Disable + Mimic because Mimic happens to replace the same slot).
|
|
646
|
-
|
|
647
|
-
Showdown does not copy unmodified stats, leaving the Transformed Pokémon with incorrect stats.
|
|
648
|
-
Furthermore, transforming and then using Mirror Move / Metronome can result in [glitchy behavior
|
|
649
|
-
and
|
|
611
|
+
is not an issue with Disable + Mimic because Mimic happens to replace the same slot). Furthermore,
|
|
612
|
+
transforming and then using Mirror Move / Metronome can result in [glitchy behavior and
|
|
650
613
|
softlocks](https://pkmn.cc/bulba/Transform_glitches#Transform_.2B_Mirror_Move.2FMetronome_PP_error)
|
|
651
614
|
which Pokémon Showdown does not implement.
|
|
652
615
|
|
|
@@ -703,10 +666,10 @@ compatibility mode, the implications of these differences are outlined below:
|
|
|
703
666
|
Finally, the **initial 10-byte seed for link battles on Pokémon Red cannot include bytes larger than
|
|
704
667
|
the `SERIAL_PREAMBLE_BYTE`**, so must be in the range $\left[0, 252\right]$. This has implications
|
|
705
668
|
on the first 10 random numbers generated during the battle and has [**non-trivial competitive
|
|
706
|
-
implications**](https://www.smogon.com/forums/
|
|
707
|
-
effects become more likely, the ["1/256-miss"
|
|
708
|
-
cannot happen, Player 1 is more likely to win
|
|
709
|
-
replicate due to everything described above.
|
|
669
|
+
implications**](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/page-16#post-9068411)
|
|
670
|
+
(at the start of the battle move effects become more likely, the ["1/256-miss"
|
|
671
|
+
glitch](https://glitchcity.wiki/1/256_miss_glitch) cannot happen, Player 1 is more likely to win
|
|
672
|
+
speed ties, etc) that Pokémon Showdown cannot replicate due to everything described above.
|
|
710
673
|
|
|
711
674
|
All of places in the link battle code where randomness is required are outlined below:
|
|
712
675
|
|
|
@@ -805,8 +768,11 @@ The pkmn engine attempts to adhere to certain naming conventions:
|
|
|
805
768
|
## Resources
|
|
806
769
|
|
|
807
770
|
- [pret/pokered](https://github.com/pret/pokered/) disassembly
|
|
808
|
-
- [Gen I Main Battle
|
|
771
|
+
- [Gen I Main Battle
|
|
772
|
+
Function](https://www.smogon.com/forums/threads/past-gens-research-thread.3506992/#post-5878612) -
|
|
773
|
+
Crystal_
|
|
809
774
|
- [Pokemon Showdown!](https://github.com/smogon/pokemon-showdown)
|
|
810
775
|
- [List of glitches (Generation
|
|
811
776
|
I)](https://bulbapedia.bulbagarden.net/wiki/List_of_glitches_(Generation_I))
|
|
812
|
-
- [Pokémon Showdown RBY
|
|
777
|
+
- [Pokémon Showdown RBY
|
|
778
|
+
Bugs](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/#post-5933177)
|
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_OPTIONS: 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_OPTIONS.
|
|
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 OPTIONS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
27
|
+
MAX_OPTIONS
|
|
28
28
|
else
|
|
29
|
-
std.math.ceilPowerOfTwo(usize,
|
|
29
|
+
std.math.ceilPowerOfTwo(usize, MAX_OPTIONS) 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)
|
|
@@ -55,8 +55,8 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
55
55
|
turn: u16 = 0,
|
|
56
56
|
/// The last damage dealt by either side.
|
|
57
57
|
last_damage: u16 = 0,
|
|
58
|
-
///
|
|
59
|
-
|
|
58
|
+
/// The slot index of the last selected moves for each side
|
|
59
|
+
last_selected_indexes: MoveIndexes = .{},
|
|
60
60
|
/// The pseudo random number generator.
|
|
61
61
|
rng: RNG,
|
|
62
62
|
|
|
@@ -76,7 +76,7 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/// Returns the result of applying Player 1's choice `c1` and Player 2's choice `c2` to the
|
|
79
|
-
/// battle, optionally writing protocol
|
|
79
|
+
/// battle, optionally writing protocol logs to `log` if `options.trace` is enabled.
|
|
80
80
|
pub fn update(self: *Self, c1: Choice, c2: Choice, log: anytype) !Result {
|
|
81
81
|
return mechanics.update(self, c1, c2, log);
|
|
82
82
|
}
|
|
@@ -201,19 +201,17 @@ pub const MoveSlot = extern struct {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
///
|
|
209
|
-
|
|
210
|
-
///
|
|
211
|
-
|
|
212
|
-
/// Whether the last move executed by Player 2 was counterable.
|
|
213
|
-
p2_counterable: if (showdown) u8 else u1 = 0,
|
|
204
|
+
const uindex = if (showdown) u16 else u4;
|
|
205
|
+
|
|
206
|
+
/// Representation of the move slot indexes for each side in a Generation I Pokémon battle.
|
|
207
|
+
pub const MoveIndexes = packed struct {
|
|
208
|
+
/// Player 1's move index.
|
|
209
|
+
p1: uindex = 0,
|
|
210
|
+
/// Player 1's move index.
|
|
211
|
+
p2: uindex = 0,
|
|
214
212
|
|
|
215
213
|
comptime {
|
|
216
|
-
assert(@sizeOf(
|
|
214
|
+
assert(@sizeOf(MoveIndexes) == if (showdown) 4 else 1);
|
|
217
215
|
}
|
|
218
216
|
};
|
|
219
217
|
|
package/src/lib/gen1/helpers.zig
CHANGED
|
@@ -55,16 +55,21 @@ pub const Battle = struct {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
pub fn random(rand: *PSRNG, opt: Options) data.Battle(data.PRNG) {
|
|
58
|
-
|
|
58
|
+
var p1: u4 = 0;
|
|
59
|
+
var p2: u4 = 0;
|
|
60
|
+
var battle: data.Battle(data.PRNG) = .{
|
|
59
61
|
.rng = prng(rand),
|
|
60
62
|
.turn = 0,
|
|
61
63
|
.last_damage = 0,
|
|
62
64
|
.sides = .{ Side.random(rand, opt), Side.random(rand, opt) },
|
|
63
65
|
};
|
|
66
|
+
battle.last_selected_indexes.p1 = p1;
|
|
67
|
+
battle.last_selected_indexes.p2 = p2;
|
|
68
|
+
return battle;
|
|
64
69
|
}
|
|
65
70
|
};
|
|
66
71
|
|
|
67
|
-
fn prng(rand: *PSRNG) data.PRNG {
|
|
72
|
+
pub fn prng(rand: *PSRNG) data.PRNG {
|
|
68
73
|
// GLITCH: initial bytes in seed can only range from 0-252, not 0-255
|
|
69
74
|
const max: u8 = 253;
|
|
70
75
|
return .{
|
|
@@ -206,10 +211,16 @@ pub const Pokemon = struct {
|
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
213
|
|
|
214
|
+
// cat src/test/showdown/blocklist.json | jq '."1".moves'
|
|
209
215
|
fn blocked(m: Move) bool {
|
|
210
|
-
|
|
216
|
+
if (Move.get(m).effect == .Binding) return true;
|
|
211
217
|
return switch (m) {
|
|
212
|
-
.
|
|
218
|
+
.Counter,
|
|
219
|
+
.Mimic,
|
|
220
|
+
.Metronome,
|
|
221
|
+
.MirrorMove,
|
|
222
|
+
.Transform,
|
|
223
|
+
=> true,
|
|
213
224
|
else => false,
|
|
214
225
|
};
|
|
215
226
|
}
|