@pkmn/engine 0.1.0-dev.c544e10e → 0.1.0-dev.cbdbb719

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.
Files changed (46) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +41 -14
  3. package/build/pkg/addon.js +6 -7
  4. package/build/pkg/addon.js.map +1 -1
  5. package/build/pkg/data.d.ts +4 -4
  6. package/build/pkg/data.js.map +1 -1
  7. package/build/pkg/gen1.js.map +1 -1
  8. package/build/pkg/index.d.ts +3 -2
  9. package/build/pkg/index.js.map +1 -1
  10. package/build/pkg/protocol.js +4 -4
  11. package/build/pkg/protocol.js.map +1 -1
  12. package/build/test/display.js +8 -3
  13. package/build/test/display.js.map +1 -1
  14. package/build/tools/debug.js +2 -3
  15. package/build/tools/debug.js.map +1 -1
  16. package/build.zig +208 -81
  17. package/package.json +32 -21
  18. package/src/bin/install-pkmn-engine +25 -17
  19. package/src/lib/common/array.zig +77 -0
  20. package/src/lib/common/data.zig +4 -4
  21. package/src/lib/common/debug.zig +2 -2
  22. package/src/lib/common/js.zig +4 -2
  23. package/src/lib/common/optional.zig +14 -10
  24. package/src/lib/common/options.zig +2 -0
  25. package/src/lib/common/protocol.zig +73 -73
  26. package/src/lib/common/rational.zig +121 -27
  27. package/src/lib/common/rng.zig +7 -7
  28. package/src/lib/common/util.zig +50 -1
  29. package/src/lib/gen1/calc.zig +511 -131
  30. package/src/lib/gen1/chance.zig +374 -267
  31. package/src/lib/gen1/data/species.zig +1 -1
  32. package/src/lib/gen1/data.zig +15 -14
  33. package/src/lib/gen1/helpers.zig +96 -536
  34. package/src/lib/gen1/mechanics.zig +285 -189
  35. package/src/lib/gen2/calc.zig +34 -16
  36. package/src/lib/gen2/chance.zig +85 -492
  37. package/src/lib/gen2/data.zig +8 -7
  38. package/src/lib/gen2/generated.zig +1 -3
  39. package/src/lib/gen2/helpers.zig +41 -9
  40. package/src/lib/gen2/mechanics.zig +178 -121
  41. package/src/lib/{binding/node.zig → node.zig} +9 -12
  42. package/src/lib/pkmn.zig +32 -15
  43. package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
  44. package/src/test/display/pkmn.html.tmpl +5 -5
  45. package/src/lib/gen1/README.md +0 -894
  46. package/src/lib/gen2/README.md +0 -329
@@ -1091,7 +1091,7 @@ pub const Species = enum(u8) {
1091
1091
  /// The number of Pokémon species in this generation.
1092
1092
  pub const size = 151;
1093
1093
 
1094
- /// The Pokémon's critical hit rate=io out of 256.
1094
+ /// The Pokémon's critical hit ratio out of 256.
1095
1095
  pub fn chance(id: Species) u8 {
1096
1096
  assert(id != .None);
1097
1097
  return CHANCES[@intFromEnum(id) - 1];
@@ -22,11 +22,11 @@ const expect = std.testing.expect;
22
22
 
23
23
  /// The minimum size in bytes required to hold all Generation I choice options.
24
24
  pub const MAX_CHOICES: usize = 9; // move 1..4, switch 2..6
25
- /// The optimal size in bytes required to hold all Generation I choice options.
26
- /// At least as large as MAX_CHOICES.
25
+ /// The maximum number of bytes possibly logged by a single Generation I update.
27
26
  pub const MAX_LOGS: usize = 180;
28
27
 
29
- /// The maximum number of bytes possibly logged by a single Generation I update.
28
+ /// The optimal size in bytes required to hold all Generation I choice options.
29
+ /// At least as large as MAX_CHOICES.
30
30
  pub const CHOICES_SIZE = if (builtin.mode == .ReleaseSmall)
31
31
  MAX_CHOICES
32
32
  else
@@ -47,6 +47,7 @@ const Player = data.Player;
47
47
  const Result = data.Result;
48
48
 
49
49
  const PointerType = util.PointerType;
50
+ const isPointerTo = util.isPointerTo;
50
51
 
51
52
  const showdown = pkmn.options.showdown;
52
53
 
@@ -71,13 +72,13 @@ pub fn Battle(comptime RNG: anytype) type {
71
72
 
72
73
  /// Returns the `Side` for the given `player`.
73
74
  pub fn side(self: anytype, player: Player) PointerType(@TypeOf(self), Side) {
74
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Self);
75
+ assert(isPointerTo(self, Self));
75
76
  return &self.sides[@intFromEnum(player)];
76
77
  }
77
78
 
78
79
  /// Returns the `Side` of the opponent for the given `player`
79
80
  pub fn foe(self: anytype, player: Player) PointerType(@TypeOf(self), Side) {
80
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Self);
81
+ assert(isPointerTo(self, Self));
81
82
  return &self.sides[@intFromEnum(player.foe())];
82
83
  }
83
84
 
@@ -91,7 +92,7 @@ pub fn Battle(comptime RNG: anytype) type {
91
92
  self: anytype,
92
93
  player: Player,
93
94
  ) PointerType(@TypeOf(self), MoveDetails) {
94
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Self);
95
+ assert(isPointerTo(self, Self));
95
96
  return &self.last_moves[@intFromEnum(player)];
96
97
  }
97
98
 
@@ -112,7 +113,7 @@ pub fn Battle(comptime RNG: anytype) type {
112
113
  /// make (i.e. on the cartridge a soft-lock occurs).
113
114
  ///
114
115
  /// This function will always return choices > 0 if `pkmn.options.showdown` is true.
115
- pub fn choices(self: *Self, player: Player, request: Choice.Type, out: []Choice) u8 {
116
+ pub fn choices(self: *const Self, player: Player, request: Choice.Type, out: []Choice) u8 {
116
117
  return mechanics.choices(self, player, request, out);
117
118
  }
118
119
  };
@@ -142,7 +143,7 @@ pub const Side = extern struct {
142
143
 
143
144
  /// Returns the stored `Pokemon` corresponding to the one-indexed party `slot`.
144
145
  pub fn get(self: anytype, slot: u8) PointerType(@TypeOf(self), Pokemon) {
145
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Side);
146
+ assert(isPointerTo(self, Side));
146
147
  assert(slot > 0 and slot <= 6);
147
148
  const id = self.order[slot - 1];
148
149
  assert(id > 0 and id <= 6);
@@ -151,7 +152,7 @@ pub const Side = extern struct {
151
152
 
152
153
  /// Returns the stored `Pokemon` corresponding to the `active` Pokémon (slot 1).
153
154
  pub fn stored(self: anytype) PointerType(@TypeOf(self), Pokemon) {
154
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Side);
155
+ assert(isPointerTo(self, Side));
155
156
  return self.get(1);
156
157
  }
157
158
  };
@@ -177,7 +178,7 @@ pub const ActivePokemon = extern struct {
177
178
 
178
179
  /// Returns the active Pokémon's current move slot located at the one-indexed `mslot`.
179
180
  pub fn move(self: anytype, mslot: u8) PointerType(@TypeOf(self), MoveSlot) {
180
- assert(@typeInfo(@TypeOf(self)).Pointer.child == ActivePokemon);
181
+ assert(isPointerTo(self, ActivePokemon));
181
182
  assert(mslot > 0 and mslot <= 4);
182
183
  assert(self.moves[mslot - 1].id != .None);
183
184
  return &self.moves[mslot - 1];
@@ -207,7 +208,7 @@ pub const Pokemon = extern struct {
207
208
 
208
209
  /// Returns the Pokémon's original move slot located at the one-indexed `mslot`.
209
210
  pub fn move(self: anytype, mslot: u8) PointerType(@TypeOf(self), MoveSlot) {
210
- assert(@typeInfo(@TypeOf(self)).Pointer.child == Pokemon);
211
+ assert(isPointerTo(self, Pokemon));
211
212
  assert(mslot > 0 and mslot <= 4);
212
213
  assert(self.moves[mslot - 1].id != .None);
213
214
  return &self.moves[mslot - 1];
@@ -409,12 +410,12 @@ test Volatiles {
409
410
  try expectEqual(@as(u8, 42), volatiles.substitute);
410
411
  try expectEqual(@as(u4, 2), volatiles.disable_move);
411
412
  try expectEqual(@as(u4, 4), volatiles.disable_duration);
412
- try expectEqual(@as(u4, 2), volatiles.confusion);
413
+ try expectEqual(@as(u3, 2), volatiles.confusion);
413
414
  try expectEqual(@as(u5, 4), volatiles.toxic);
414
- try expectEqual(@as(u4, 3), volatiles.attacks);
415
+ try expectEqual(@as(u3, 3), volatiles.attacks);
415
416
  }
416
417
 
417
- /// Representaiton of a Pokémon's stats in Generation I.
418
+ /// Representation of a Pokémon's stats in Generation I.
418
419
  pub fn Stats(comptime T: type) type {
419
420
  return extern struct {
420
421
  hp: T = 0,