@pkmn/engine 0.1.0-dev.4eeb346e → 0.1.0-dev.53335a32

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.
@@ -332,9 +332,7 @@ 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). 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.
335
+ [PROTOCOL.md](../../../docs/PROTOCOL.md).
338
336
 
339
337
  ### `Battle`
340
338
 
@@ -469,7 +467,7 @@ data in the browser for ease of debugging.
469
467
 
470
468
  In addition to its alternative [RNG semantics](#rng), Pokémon Showdown's implementation of the first
471
469
  generation of Pokémon contains a number bugs, [many of which are known and have been documented on
472
- Smogon](https://www.smogon.com/forums/posts/5933177/show):
470
+ Smogon](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/#post-5933177):
473
471
 
474
472
  - moves on Pokémon Showdown can do 0 damage instead of failing or causing a [division-by-zero
475
473
  freeze](https://pkmn.cc/bulba-glitch-1#Division_by_0).
@@ -478,8 +476,7 @@ Smogon](https://www.smogon.com/forums/posts/5933177/show):
478
476
  - Confusion self-hits use the wrong damage formula resulting in off-by-one errors (and also fail to
479
477
  account for an opponent's Reflect). Furthermore, the confusion self-hit damage will erroneously be
480
478
  inflicted to the confused user's substitute if the confused user had been attempting to use a
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.
479
+ self-targeting move.
483
480
 
484
481
  Beyond the general bugs listed above, several move effects are implemented incorrectly by Pokémon
485
482
  Showdown. Some of these moves are [too fundamentally broken to be implemented](#unimplementable) by
@@ -489,25 +486,16 @@ the pkmn engine, but the following moves have their broken behavior preserved in
489
486
  incorrectly still gets applied to Bide's user.
490
487
  - **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
491
488
  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.
489
+ field with the uncapped Leech Seed damage which has consequences for Bide and Counter.
494
490
  - **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
495
491
  Substitute but doesn't on Pokémon Showdown.
496
492
  - **Flinch**: Flinching does not get cleared during move selection on Pokémon Showdown and is
497
493
  instead cleared in Pokémon Showdown's "residual" phase, meaning the flinch status gets erroneously
498
494
  preserved across fainting (as fainting triggers Pokémon Showdown's "instaswitch" behavior which
499
495
  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.
507
496
  - **Thrash** / **Petal Dance**: once a Pokémon is locked into a thrashing move they will lose all
508
497
  speed ties on Pokémon Showdown (due to the fact that if they win the speed tie their action will
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.
498
+ then get "changed" and inserted back into the queue after their opponent's action).
511
499
  - **Freeze** / **Sleep**: Pokémon Showdown requires a move to be selected when a Pokémon is frozen
512
500
  or sleeping and uses that in the event that the status is removed while on the cartridge no
513
501
  selection is possible and no turn exists for the thawed/woken Pokémon to act except in the case of
@@ -532,8 +520,7 @@ the pkmn engine, but the following moves have their broken behavior preserved in
532
520
  Pokémon Showdown implementing the health check based on floating point division instead of integer
533
521
  divison like on the cartridge (meaning the Substitute 1/4 glitch will only occur if the Pokémon's
534
522
  maximum HP is evenly divisible by 4). Finally, Substitute also incorrectly blocks Dream Eater on
535
- Pokémon Showdown and will incorrectly still heal 1 HP for any draining moves if the attack does 0
536
- damage.
523
+ Pokémon Showdown.
537
524
 
538
525
  In addition to numerous cases where Pokémon Showdown uses the wrong type of message (e.g. `|-fail`
539
526
  vs. `|-miss|` vs. `|-immune|`, e.g. in the case of Leech Seed) which are not documented here, Pokémon
@@ -567,7 +554,7 @@ called out in the `|rule|` section at the beginning of a battle's log):
567
554
  `|rule|` section** in Generation I (or II) as the actual order of switches here does not have
568
555
  competitive implications like it does in Generation III, but it is still contrary to how the games
569
556
  work where the [host (Player 1)'s Pokemon would switch
570
- first](https://www.smogon.com/forums/posts/5989318/show).
557
+ first](https://www.smogon.com/forums/threads/gen-3-on-ps-final-fixes.3527268/post-5989318).
571
558
 
572
559
  Pokémon Showdown enforces several clauses *before* the battle: **Cleric Clause** (all Pokémon must
573
560
  have full HP and PP, and not have any status conditions prior to the battle), **Stat Tradeback
@@ -588,12 +575,13 @@ left up to a client to support.
588
575
 
589
576
  Numerous moves on Pokémon Showdown are broken not simply due to local issues in the implementation
590
577
  of their effects but instead due to **global issues** related to fundamental mechanics such as
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):
578
+ [broken move
579
+ selection](https://www.smogon.com/forums/threads/rby-fight-button-simulation-improvements-fix-partial-trapping-improve-counter.3673280/#post-8655897),
580
+ using move name instead of slot to determine move identity, implementing volatile statuses
581
+ incorrectly or not understanding how moves which call other moves work means that it isn't possible
582
+ to completely implement Pokémon Showdown's behavior for the following moves (the pkmn engine
583
+ attempts to reproduce as much of the behavior that can be reproduced without making data structure
584
+ changes or dramatically deviating from the correct control flow):
597
585
 
598
586
  - **Wrap**: Binding moves like Wrap are implemented on Pokémon Showdown with an artificial
599
587
  `partialtrappinglock` volatile as opposed to how it works on the cartridge which simply relies on
@@ -682,10 +670,10 @@ compatibility mode, the implications of these differences are outlined below:
682
670
  Finally, the **initial 10-byte seed for link battles on Pokémon Red cannot include bytes larger than
683
671
  the `SERIAL_PREAMBLE_BYTE`**, so must be in the range $\left[0, 252\right]$. This has implications
684
672
  on the first 10 random numbers generated during the battle and has [**non-trivial competitive
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
+ implications**](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/page-16#post-9068411)
674
+ (at the start of the battle move effects become more likely, the ["1/256-miss"
675
+ glitch](https://glitchcity.wiki/1/256_miss_glitch) cannot happen, Player 1 is more likely to win
676
+ speed ties, etc) that Pokémon Showdown cannot replicate due to everything described above.
689
677
 
690
678
  All of places in the link battle code where randomness is required are outlined below:
691
679
 
@@ -784,8 +772,11 @@ The pkmn engine attempts to adhere to certain naming conventions:
784
772
  ## Resources
785
773
 
786
774
  - [pret/pokered](https://github.com/pret/pokered/) disassembly
787
- - [Gen I Main Battle Function](https://www.smogon.com/forums/posts/5878612/show) - Crystal_
775
+ - [Gen I Main Battle
776
+ Function](https://www.smogon.com/forums/threads/past-gens-research-thread.3506992/#post-5878612) -
777
+ Crystal_
788
778
  - [Pokemon Showdown!](https://github.com/smogon/pokemon-showdown)
789
779
  - [List of glitches (Generation
790
780
  I)](https://bulbapedia.bulbagarden.net/wiki/List_of_glitches_(Generation_I))
791
- - [Pokémon Showdown RBY Bugs](https://www.smogon.com/forums/posts/5933177/show)
781
+ - [Pokémon Showdown RBY
782
+ Bugs](https://www.smogon.com/forums/threads/rby-tradebacks-bug-report-thread.3524844/#post-5933177)
@@ -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 MAX_CHOICES: usize = 9; // move 1..4, switch 2..6
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 MAX_CHOICES.
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 CHOICES_SIZE = if (builtin.mode == .ReleaseSmall)
27
- MAX_CHOICES
26
+ pub const OPTIONS_SIZE = if (builtin.mode == .ReleaseSmall)
27
+ MAX_OPTIONS
28
28
  else
29
- std.math.ceilPowerOfTwo(usize, MAX_CHOICES) catch unreachable;
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)