@pkmn/engine 0.1.0-dev.d716e940 → 0.1.0-dev.d952b7c9

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 (79) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +97 -59
  3. package/build/pkg/addon/browser.d.ts +3 -0
  4. package/build/pkg/addon/browser.js +43 -0
  5. package/build/pkg/addon/browser.js.map +1 -0
  6. package/build/pkg/addon/node.d.ts +3 -0
  7. package/build/pkg/addon/node.js +96 -0
  8. package/build/pkg/addon/node.js.map +1 -0
  9. package/build/pkg/addon.d.ts +2 -0
  10. package/build/pkg/addon.js +35 -57
  11. package/build/pkg/addon.js.map +1 -1
  12. package/build/pkg/data/ids.json +12 -12
  13. package/build/pkg/data/layout.json +26 -4
  14. package/build/pkg/data/protocol.json +69 -12
  15. package/build/pkg/data.d.ts +27 -5
  16. package/build/pkg/data.js.map +1 -1
  17. package/build/pkg/gen1.js +16 -19
  18. package/build/pkg/gen1.js.map +1 -1
  19. package/build/pkg/index.d.ts +24 -10
  20. package/build/pkg/index.js +15 -10
  21. package/build/pkg/index.js.map +1 -1
  22. package/build/pkg/protocol.d.ts +20 -1
  23. package/build/pkg/protocol.js +123 -102
  24. package/build/pkg/protocol.js.map +1 -1
  25. package/build/tools/debug.js +36 -68
  26. package/build/tools/debug.js.map +1 -1
  27. package/build/tools/display/debug.jsx +128 -0
  28. package/build/tools/display/debug.jsx.map +1 -0
  29. package/build/tools/display/index.js +132 -0
  30. package/build/tools/display/index.js.map +1 -0
  31. package/build/tools/display/ui.jsx +349 -0
  32. package/build/tools/display/ui.jsx.map +1 -0
  33. package/build/tools/display/util.js +18 -0
  34. package/build/tools/display/util.js.map +1 -0
  35. package/build.zig +286 -131
  36. package/package.json +73 -31
  37. package/src/bin/install-pkmn-engine +39 -24
  38. package/src/bin/pkmn-debug +1 -1
  39. package/src/lib/common/array.zig +77 -0
  40. package/src/lib/common/battle.zig +17 -0
  41. package/src/lib/common/data.zig +19 -31
  42. package/src/lib/common/debug.zig +30 -16
  43. package/src/lib/common/js.zig +120 -0
  44. package/src/lib/common/optional.zig +71 -0
  45. package/src/lib/common/options.zig +13 -0
  46. package/src/lib/common/protocol.zig +911 -367
  47. package/src/lib/common/rational.zig +447 -0
  48. package/src/lib/common/rng.zig +31 -22
  49. package/src/lib/common/util.zig +61 -0
  50. package/src/lib/gen1/calc.zig +950 -0
  51. package/src/lib/gen1/chance.zig +1169 -0
  52. package/src/lib/gen1/data/moves.zig +202 -190
  53. package/src/lib/gen1/data/species.zig +5 -5
  54. package/src/lib/gen1/data/types.zig +10 -10
  55. package/src/lib/gen1/data.zig +92 -79
  56. package/src/lib/gen1/helpers.zig +141 -28
  57. package/src/lib/gen1/mechanics.zig +1118 -773
  58. package/src/lib/gen2/calc.zig +161 -0
  59. package/src/lib/gen2/chance.zig +902 -0
  60. package/src/lib/gen2/data/items.zig +14 -20
  61. package/src/lib/gen2/data/moves.zig +664 -570
  62. package/src/lib/gen2/data/species.zig +2 -2
  63. package/src/lib/gen2/data/types.zig +137 -34
  64. package/src/lib/gen2/data.zig +125 -86
  65. package/src/lib/gen2/generated.zig +806 -0
  66. package/src/lib/gen2/helpers.zig +54 -32
  67. package/src/lib/gen2/mechanics.zig +3564 -15
  68. package/src/lib/node.zig +131 -0
  69. package/src/lib/pkmn.zig +81 -5
  70. package/src/lib/wasm.zig +13 -0
  71. package/src/tools/display/dom.ts +96 -0
  72. package/src/tools/display/ui.css +351 -0
  73. package/build/test/display.js +0 -400
  74. package/build/test/display.js.map +0 -1
  75. package/src/lib/binding/node.zig +0 -229
  76. package/src/lib/binding/wasm.zig +0 -10
  77. package/src/lib/gen1/README.md +0 -812
  78. package/src/lib/gen2/README.md +0 -309
  79. package/src/test/display/pkmn.html.tmpl +0 -368
@@ -0,0 +1,1169 @@
1
+ const std = @import("std");
2
+
3
+ const assert = std.debug.assert;
4
+ const print = std.debug.print;
5
+
6
+ const expect = std.testing.expect;
7
+ const expectEqual = std.testing.expectEqual;
8
+
9
+ const DEBUG = @import("../common/debug.zig").print;
10
+ const options = @import("../common/options.zig");
11
+ const rational = @import("../common/rational.zig");
12
+ const util = @import("../common/util.zig");
13
+
14
+ const Array = @import("../common/array.zig").Array;
15
+ const Player = @import("../common/data.zig").Player;
16
+ const Optional = @import("../common/optional.zig").Optional;
17
+
18
+ const data = @import("data.zig");
19
+
20
+ const enabled = options.chance;
21
+ const showdown = options.showdown;
22
+
23
+ const PointerType = util.PointerType;
24
+ const isPointerTo = util.isPointerTo;
25
+
26
+ const Move = data.Move;
27
+ const MoveSlot = data.MoveSlot;
28
+
29
+ const Int = if (@hasField(std.builtin.Type, "int")) .int else .Int;
30
+ const Enum = if (@hasField(std.builtin.Type, "enum")) .@"enum" else .Enum;
31
+ const Struct = if (@hasField(std.builtin.Type, "struct")) .@"struct" else .Struct;
32
+
33
+ /// Actions taken by a hypothetical "chance player" that convey information about which RNG events
34
+ /// were observed during a Generation I battle `update`. This can additionally be provided as input
35
+ /// to the `update` call to override the normal behavior of the RNG in order to force specific
36
+ /// outcomes.
37
+ pub const Actions = extern struct {
38
+ /// Information about the RNG activity for Player 1.
39
+ p1: Action = .{},
40
+ /// Information about the RNG activity for Player 2.
41
+ p2: Action = .{},
42
+
43
+ comptime {
44
+ assert(@sizeOf(Actions) == 16);
45
+ }
46
+
47
+ /// Returns the `Action` for the given `player`.
48
+ pub fn get(self: anytype, player: Player) PointerType(@TypeOf(self), Action) {
49
+ assert(isPointerTo(self, Actions));
50
+ return if (player == .P1) &self.p1 else &self.p2;
51
+ }
52
+
53
+ /// Returns true if `a` is equal to `b`.
54
+ pub fn eql(a: Actions, b: Actions) bool {
55
+ return @as(u128, @bitCast(a)) == @as(u128, @bitCast(b));
56
+ }
57
+
58
+ /// Returns true if `a` has the same "shape" as `b`, where `Actions` are defined to have the
59
+ /// same shape if they have the same fields set (though those fields need not necessarily be
60
+ /// set to the same value).
61
+ pub fn matches(a: Actions, b: Actions) bool {
62
+ inline for (@field(@typeInfo(Actions), @tagName(Struct)).fields) |player| {
63
+ inline for (@field(@typeInfo(Action), @tagName(Struct)).fields) |field| {
64
+ const a_val = @field(@field(a, player.name), field.name);
65
+ const b_val = @field(@field(b, player.name), field.name);
66
+
67
+ switch (@typeInfo(@TypeOf(a_val))) {
68
+ Enum => if ((@intFromEnum(a_val) > 0) != (@intFromEnum(b_val) > 0))
69
+ return false,
70
+ Int => if ((a_val > 0) != (b_val > 0)) return false,
71
+ else => unreachable,
72
+ }
73
+ }
74
+ }
75
+ return true;
76
+ }
77
+
78
+ pub fn fmt(self: Actions, writer: anytype, shape: bool) !void {
79
+ try writer.writeAll("<P1 = ");
80
+ try self.p1.fmt(writer, shape);
81
+ try writer.writeAll(", P2 = ");
82
+ try self.p2.fmt(writer, shape);
83
+ try writer.writeAll(">");
84
+ }
85
+
86
+ pub fn format(a: Actions, comptime f: []const u8, o: std.fmt.FormatOptions, w: anytype) !void {
87
+ _ = .{ f, o };
88
+ try fmt(a, w, false);
89
+ }
90
+ };
91
+
92
+ test Actions {
93
+ const a: Actions = .{ .p1 = .{ .hit = .true, .critical_hit = .false, .damage = 245 } };
94
+ const b: Actions = .{ .p1 = .{ .hit = .false, .critical_hit = .true, .damage = 246 } };
95
+ const c: Actions = .{ .p1 = .{ .hit = .true } };
96
+
97
+ try expect(a.eql(a));
98
+ try expect(!a.eql(b));
99
+ try expect(!b.eql(a));
100
+ try expect(!a.eql(c));
101
+ try expect(!c.eql(a));
102
+
103
+ try expect(a.matches(a));
104
+ try expect(a.matches(b));
105
+ try expect(b.matches(a));
106
+ try expect(!a.matches(c));
107
+ try expect(!c.matches(a));
108
+ }
109
+
110
+ /// Observation made about a duration - whether the duration has started, been continued, or ended.
111
+ pub const Observation = enum { started, continuing, ended };
112
+ /// An extension of Observation to account for "hidden" confusion.
113
+ pub const Confusion = enum {
114
+ started,
115
+ continuing,
116
+ ended,
117
+ /// An indicator that an existing confusion duration has been overwritten by a new confusion
118
+ /// duration due to a Thrashing move ending. This is not immediately observable to an opponent,
119
+ /// to compute probabilities from an opponent's point of view based solely on public information
120
+ /// extra work must be done to correct for the information leak
121
+ overwritten,
122
+ };
123
+
124
+ /// Information about the RNG that was observed during a Generation I battle `update` for a
125
+ /// single player.
126
+ pub const Action = packed struct(u64) {
127
+ /// If not 0, the roll to be returned Rolls.damage.
128
+ damage: u8 = 0,
129
+
130
+ /// If not None, the value to return for Rolls.hit.
131
+ hit: Optional(bool) = .None,
132
+ /// If not None, the value to be returned by Rolls.criticalHit.
133
+ critical_hit: Optional(bool) = .None,
134
+ /// If not None, the value to be returned for
135
+ /// Rolls.{confusionChance,secondaryChance,poisonChance}.
136
+ secondary_chance: Optional(bool) = .None,
137
+ /// If not None, the Player to be returned by Rolls.speedTie.
138
+ speed_tie: Optional(Player) = .None,
139
+
140
+ /// If not None, the value to return for Rolls.confused.
141
+ confused: Optional(bool) = .None,
142
+ /// If not None, the value to return for Rolls.paralyzed.
143
+ paralyzed: Optional(bool) = .None,
144
+ /// If not 0, the value to be returned by Rolls.distribution in the case of binding moves
145
+ /// or Rolls.{sleepDuration,disableDuration,confusionDuration,attackingDuration} otherwise.
146
+ duration: u4 = 0,
147
+
148
+ /// TODO
149
+ sleep: Optional(Observation) = .None,
150
+ /// TODO
151
+ confusion: Optional(Confusion) = .None,
152
+ /// TODO
153
+ disable: Optional(Observation) = .None,
154
+ /// TODO
155
+ attacking: Optional(Observation) = .None,
156
+ /// TODO
157
+ binding: Optional(Observation) = .None,
158
+
159
+ _: u1 = 0,
160
+
161
+ /// If not 0, the move slot (1-4) to return in Rolls.moveSlot. If present as an override,
162
+ /// invalid values (eg. due to empty move slots or 0 PP) will be ignored.
163
+ move_slot: u4 = 0,
164
+
165
+ /// TODO
166
+ pp: u4 = 0,
167
+ /// If not 0, the value (2-5) to return for Rolls.distribution for multi hit.
168
+ multi_hit: u4 = 0,
169
+
170
+ /// If not 0, psywave - 1 should be returned as the damage roll for Rolls.psywave.
171
+ psywave: u8 = 0,
172
+
173
+ /// If not None, the Move to return for Rolls.metronome.
174
+ metronome: Move = .None,
175
+
176
+ pub const Field = std.meta.FieldEnum(Action);
177
+
178
+ pub fn format(a: Action, comptime f: []const u8, o: std.fmt.FormatOptions, w: anytype) !void {
179
+ _ = .{ f, o };
180
+ try fmt(a, w, false);
181
+ }
182
+
183
+ pub fn fmt(self: Action, writer: anytype, shape: bool) !void {
184
+ try writer.writeByte('(');
185
+ var printed = false;
186
+ inline for (@field(@typeInfo(Action), @tagName(Struct)).fields) |field| {
187
+ const val = @field(self, field.name);
188
+ switch (@typeInfo(@TypeOf(val))) {
189
+ Enum => if (val != .None) {
190
+ if (printed) try writer.writeAll(", ");
191
+ if (shape) {
192
+ try writer.print("{s}:?", .{field.name});
193
+ } else if (@TypeOf(val) == Optional(bool)) {
194
+ try writer.print("{s}{s}", .{
195
+ if (val == .false) "!" else "",
196
+ field.name,
197
+ });
198
+ } else if (@TypeOf(val) == Optional(Observation) or
199
+ @TypeOf(val) == Optional(Confusion))
200
+ {
201
+ try writer.print("{s}{s}", .{
202
+ ([_][]const u8{ "+", "", "-", "#" })[@intFromEnum(val) - 1],
203
+ field.name,
204
+ });
205
+ } else {
206
+ try writer.print("{s}:{s}", .{ field.name, @tagName(val) });
207
+ }
208
+ printed = true;
209
+ },
210
+ Int => if (val != 0) {
211
+ if (printed) try writer.writeAll(", ");
212
+ if (shape) {
213
+ try writer.print("{s}:?", .{field.name});
214
+ } else {
215
+ try writer.print("{s}:{d}", .{ field.name, val });
216
+ }
217
+ printed = true;
218
+ },
219
+ else => unreachable,
220
+ }
221
+ }
222
+ try writer.writeByte(')');
223
+ }
224
+ };
225
+
226
+ /// TODO
227
+ pub const Durations = struct {
228
+ /// TODO
229
+ p1: Duration = .{},
230
+ /// TODO
231
+ p2: Duration = .{},
232
+
233
+ comptime {
234
+ assert(@sizeOf(Durations) == 8);
235
+ }
236
+
237
+ /// TODO
238
+ pub fn get(self: anytype, player: Player) PointerType(@TypeOf(self), Duration) {
239
+ assert(isPointerTo(self, Durations));
240
+ return if (player == .P1) &self.p1 else &self.p2;
241
+ }
242
+
243
+ pub fn format(
244
+ self: Durations,
245
+ comptime fmt: []const u8,
246
+ opts: std.fmt.FormatOptions,
247
+ writer: anytype,
248
+ ) !void {
249
+ _ = .{ fmt, opts };
250
+ try writer.print("[P1 = {}, P2 = {}]", .{ self.p1, self.p2 });
251
+ }
252
+ };
253
+
254
+ pub const Sleeps = Array(6, u3);
255
+
256
+ /// TODO
257
+ pub const Duration = packed struct(u32) {
258
+ sleeps: Sleeps.T = 0,
259
+ confusion: u3 = 0,
260
+ disable: u4 = 0,
261
+ attacking: u3 = 0,
262
+ binding: u3 = 0,
263
+
264
+ _: u1 = 0,
265
+
266
+ pub fn format(
267
+ self: Duration,
268
+ comptime fmt: []const u8,
269
+ opts: std.fmt.FormatOptions,
270
+ writer: anytype,
271
+ ) !void {
272
+ _ = .{ fmt, opts };
273
+ try writer.writeByte('(');
274
+ var printed = false;
275
+ inline for (@field(@typeInfo(Duration), @tagName(Struct)).fields) |field| {
276
+ const val = @field(self, field.name);
277
+ switch (@typeInfo(@TypeOf(val))) {
278
+ Int => if (val != 0) {
279
+ if (printed) try writer.writeAll(", ");
280
+ if (comptime std.mem.eql(u8, field.name, "sleeps")) {
281
+ try writer.print("{s}:[", .{field.name});
282
+ for (0..6) |i| {
283
+ if (i != 0) try writer.writeByte(',');
284
+ try writer.print("{d}", .{Sleeps.get(val, i)});
285
+ }
286
+ try writer.writeAll("]");
287
+ } else {
288
+ try writer.print("{s}:{d}", .{ field.name, val });
289
+ }
290
+ printed = true;
291
+ },
292
+ else => unreachable,
293
+ }
294
+ }
295
+ try writer.writeByte(')');
296
+ }
297
+ };
298
+
299
+ pub const Commit = enum { hit, miss, binding, err, glitch };
300
+
301
+ const uN = if (options.miss) u8 else u9;
302
+
303
+ /// Tracks chance actions and their associated probability during a Generation I battle update when
304
+ /// `options.chance` is enabled.
305
+ pub fn Chance(comptime Rational: type) type {
306
+ return struct {
307
+ const Self = @This();
308
+
309
+ /// The probability of the actions taken by a hypothetical "chance player" occurring.
310
+ probability: Rational,
311
+ /// The actions taken by a hypothetical "chance player" that convey information about which
312
+ /// RNG events were observed during a battle `update`.
313
+ actions: Actions = .{},
314
+ /// TODO
315
+ durations: Durations = .{},
316
+
317
+ // In many cases on both the cartridge and on Pokémon Showdown rolls are made even though
318
+ // later checks render their result irrelevant (missing when the target is actually immune,
319
+ // rolling for damage when the move is later revealed to have missed, etc). We can't reorder
320
+ // the logic to ensure we only ever make rolls when required due to our desire to maintain
321
+ // RNG frame accuracy, so instead we save these "pending" updates to the probability and
322
+ // only commit them once we know they are relevant (a naive solution would be to instead
323
+ // update the probability eagerly and later "undo" the update by multiplying by the inverse
324
+ // but this would be more costly and also error prone in the presence of
325
+ // overflow/normalization).
326
+ //
327
+ // This design deliberately make use of the fact that recursive moves on the cartridge may
328
+ // overwrite critical hit information multiple times as only the last update actually
329
+ // matters for the purposes of the logical results.
330
+ //
331
+ // Finally, because each player's actions are processed sequentially we only need a single
332
+ // shared structure to track this information (though it needs to be cleared appropriately)
333
+ pending: if (showdown) struct {} else struct {
334
+ crit: bool = false,
335
+ crit_probablity: u8 = 0,
336
+ damage_roll: u8 = 0,
337
+ hit: bool = false,
338
+ hit_probablity: uN = 0,
339
+ glitch: bool = false,
340
+ } = .{},
341
+
342
+ /// Possible error returned by operations tracking chance probability.
343
+ pub const Error = Rational.Error;
344
+
345
+ /// Convenience helper to clear fields which typically should be cleared between updates.
346
+ pub fn reset(self: *Self) void {
347
+ if (!enabled) return;
348
+
349
+ self.probability.reset();
350
+ self.actions = .{};
351
+ self.pending = .{};
352
+ }
353
+
354
+ pub fn commit(self: *Self, player: Player, kind: Commit) Error!void {
355
+ if (!enabled) return;
356
+
357
+ assert(!showdown);
358
+
359
+ if (kind == .glitch and !self.pending.glitch) return;
360
+
361
+ var action = self.actions.get(player);
362
+
363
+ if (kind == .err and self.pending.crit_probablity != 0) {
364
+ try self.probability.update(self.pending.crit_probablity, 256);
365
+ action.critical_hit = if (self.pending.crit) .true else .false;
366
+ return;
367
+ }
368
+
369
+ // Always commit the hit result if we make it here (commit won't be called at all if the
370
+ // target is immune*/behind a sub/etc)
371
+ if (self.pending.hit_probablity != 0) {
372
+ try self.probability.update(self.pending.hit_probablity, 256);
373
+ action.hit = if (self.pending.hit) .true else .false;
374
+ }
375
+
376
+ // If the move actually lands we can commit any past critical hit / damage rolls. Note
377
+ // we can't rely on the presence or absence of a damage roll to determine whether a
378
+ // "critical hit" was spurious or not as moves that do 1 or less damage don't rol for
379
+ // damage but can still crit (instead, whether or not a roll is deemed to be a no-op is
380
+ // passed to the critical hit helper).
381
+ //
382
+ // There is a special edge case with the division-by-zero freeze where we need to commit
383
+ // the status of critical hit roll the occured before the move missed to avoid missing
384
+ // out on the possibility that the alternative branch encountered an error
385
+ if (kind != .hit and !self.pending.glitch) {
386
+ return assert(!self.pending.crit or self.pending.crit_probablity > 0);
387
+ }
388
+
389
+ if (self.pending.crit_probablity != 0) {
390
+ try self.probability.update(self.pending.crit_probablity, 256);
391
+ action.critical_hit = if (self.pending.crit) .true else .false;
392
+ } else assert(!self.pending.glitch);
393
+
394
+ if (self.pending.damage_roll > 0) {
395
+ try self.probability.update(1, 39);
396
+ action.damage = self.pending.damage_roll;
397
+ }
398
+ }
399
+
400
+ pub fn glitch(self: *Self) void {
401
+ if (!enabled) return;
402
+
403
+ assert(!showdown);
404
+ self.pending.glitch = true;
405
+ }
406
+
407
+ pub fn clearPending(self: *Self) void {
408
+ if (!enabled) return;
409
+
410
+ assert(!showdown);
411
+ self.pending = .{};
412
+ }
413
+
414
+ pub fn switched(self: *Self, player: Player, slot: u8) void {
415
+ if (!enabled) return;
416
+
417
+ assert(slot >= 1 and slot <= 6);
418
+
419
+ var d = self.durations.get(player);
420
+
421
+ const out = Sleeps.get(d.sleeps, 0);
422
+ d.sleeps = Sleeps.set(d.sleeps, 0, Sleeps.get(d.sleeps, slot - 1));
423
+ d.sleeps = Sleeps.set(d.sleeps, slot - 1, out);
424
+
425
+ d.confusion = 0;
426
+ d.disable = 0;
427
+ d.attacking = 0;
428
+ d.binding = 0;
429
+
430
+ self.durations.get(player.foe()).binding = 0;
431
+ }
432
+
433
+ pub fn speedTie(self: *Self, p1: bool) Error!void {
434
+ if (!enabled) return;
435
+
436
+ try self.probability.update(1, 2);
437
+ self.actions.p1.speed_tie = if (p1) .P1 else .P2;
438
+ self.actions.p2.speed_tie = self.actions.p1.speed_tie;
439
+ }
440
+
441
+ pub fn hit(self: *Self, player: Player, ok: bool, accuracy: uN) Error!void {
442
+ if (!enabled) return;
443
+
444
+ const p = if (ok) accuracy else @as(u8, @intCast(256 - @as(u9, accuracy)));
445
+ if (showdown) {
446
+ try self.probability.update(p, 256);
447
+ self.actions.get(player).hit = if (ok) .true else .false;
448
+ } else {
449
+ self.pending.hit = ok;
450
+ self.pending.hit_probablity = p;
451
+ }
452
+ }
453
+
454
+ pub fn criticalHit(self: *Self, player: Player, crit: bool, rate: u8) Error!void {
455
+ if (!enabled) return;
456
+
457
+ const n = if (crit) rate else @as(u8, @intCast(256 - @as(u9, rate)));
458
+ if (showdown) {
459
+ try self.probability.update(n, 256);
460
+ self.actions.get(player).critical_hit = if (crit) .true else .false;
461
+ } else {
462
+ self.pending.crit = crit;
463
+ self.pending.crit_probablity = n;
464
+ }
465
+ }
466
+
467
+ pub fn damage(self: *Self, player: Player, roll: u8) Error!void {
468
+ if (!enabled) return;
469
+
470
+ if (showdown) {
471
+ try self.probability.update(1, 39);
472
+ self.actions.get(player).damage = roll;
473
+ } else {
474
+ self.pending.damage_roll = roll;
475
+ }
476
+ }
477
+
478
+ pub fn secondaryChance(self: *Self, player: Player, proc: bool, rate: u8) Error!void {
479
+ if (!enabled) return;
480
+
481
+ const n = if (proc) rate else @as(u8, @intCast(256 - @as(u9, rate)));
482
+ try self.probability.update(n, 256);
483
+ self.actions.get(player).secondary_chance = if (proc) .true else .false;
484
+ }
485
+
486
+ pub fn confused(self: *Self, player: Player, cfz: bool) Error!void {
487
+ if (!enabled) return;
488
+
489
+ try self.probability.update(1, 2);
490
+ self.actions.get(player).confused = if (cfz) .true else .false;
491
+ }
492
+
493
+ pub fn paralyzed(self: *Self, player: Player, par: bool) Error!void {
494
+ if (!enabled) return;
495
+
496
+ try self.probability.update(@as(u8, if (par) 1 else 3), 4);
497
+ self.actions.get(player).paralyzed = if (par) .true else .false;
498
+ }
499
+
500
+ pub fn moveSlot(
501
+ self: *Self,
502
+ player: Player,
503
+ slot: u4,
504
+ ms: []const MoveSlot,
505
+ n: u4,
506
+ ) Error!void {
507
+ if (!enabled) return;
508
+
509
+ const denominator = if (n != 0) n else denominator: {
510
+ var i: usize = ms.len;
511
+ while (i > 0) {
512
+ i -= 1;
513
+ if (ms[i].id != .None) break :denominator i + 1;
514
+ }
515
+ unreachable;
516
+ };
517
+
518
+ if (denominator != 1) try self.probability.update(1, denominator);
519
+ self.actions.get(player).move_slot = @intCast(slot);
520
+ }
521
+
522
+ pub fn multiHit(self: *Self, player: Player, n: u3) Error!void {
523
+ if (!enabled) return;
524
+
525
+ try self.probability.update(@as(u8, if (n > 3) 1 else 3), 8);
526
+ self.actions.get(player).multi_hit = n;
527
+ }
528
+
529
+ pub fn duration(self: *Self, player: Player, turns: u4) void {
530
+ if (!enabled) return;
531
+
532
+ self.actions.get(player).duration = if (options.key) 2 else turns;
533
+ }
534
+
535
+ pub fn observe(
536
+ self: *Self,
537
+ comptime field: Action.Field,
538
+ player: Player,
539
+ obs: Optional(Confusion),
540
+ ) void {
541
+ if (!enabled) return;
542
+
543
+ var a = self.actions.get(player);
544
+ const val = @field(a, @tagName(field));
545
+ switch (obs) {
546
+ .overwritten => {
547
+ assert(field == .confusion);
548
+ assert(val == .started or val == .continuing);
549
+ assert(a.duration > 0);
550
+ a.confusion = obs;
551
+ self.durations.get(player).confusion = 1;
552
+ },
553
+ .None => {
554
+ @field(a, @tagName(field)) = .None;
555
+ if (field == .sleep) {
556
+ var d = self.durations.get(player);
557
+ d.sleeps = Sleeps.set(d.sleeps, 0, 0);
558
+ } else {
559
+ @field(self.durations.get(player), @tagName(field)) = 0;
560
+ }
561
+ },
562
+ .started => {
563
+ assert(val == .None or val == .ended);
564
+ assert(switch (field) {
565
+ .confusion => a.duration > 0 or self.actions.get(player.foe()).duration > 0,
566
+ .sleep, .disable => self.actions.get(player.foe()).duration > 0,
567
+ else => a.duration > 0,
568
+ });
569
+ @field(a, @tagName(field)) = .started;
570
+ if (field == .sleep) {
571
+ var d = self.durations.get(player);
572
+ d.sleeps = Sleeps.set(d.sleeps, 0, 1);
573
+ } else {
574
+ @field(self.durations.get(player), @tagName(field)) = 1;
575
+ }
576
+ },
577
+ else => unreachable,
578
+ }
579
+ }
580
+
581
+ pub fn sleep(self: *Self, player: Player, obs: Optional(Observation)) Error!void {
582
+ if (!enabled) return;
583
+
584
+ var a = self.actions.get(player);
585
+ assert(a.sleep == .None or a.sleep == .started);
586
+ a.sleep = obs;
587
+
588
+ var d = self.durations.get(player);
589
+ const n = Sleeps.get(d.sleeps, 0);
590
+
591
+ if (obs == .None) {
592
+ d.sleeps = Sleeps.set(d.sleeps, 0, 0);
593
+ } else if (obs == .ended) {
594
+ assert(n >= 1 and n <= 7);
595
+ if (n != 7) try self.probability.update(1, 8 - @as(u4, n));
596
+ d.sleeps = Sleeps.set(d.sleeps, 0, 0);
597
+ } else {
598
+ assert(obs == .continuing);
599
+ assert(n >= 1 and n < 7);
600
+ try self.probability.update(8 - @as(u4, n) - 1, 8 - @as(u4, n));
601
+ d.sleeps = Sleeps.set(d.sleeps, 0, n + 1);
602
+ }
603
+ }
604
+
605
+ pub fn confusion(self: *Self, player: Player, obs: Optional(Confusion)) Error!void {
606
+ if (!enabled) return;
607
+
608
+ var a = self.actions.get(player);
609
+ assert(a.confusion == .None or a.confusion == .started);
610
+ a.confusion = obs;
611
+
612
+ var d = self.durations.get(player);
613
+ const n = d.confusion;
614
+
615
+ if (obs == .ended) {
616
+ assert(n >= 2 and n <= 5);
617
+ if (n != 5) try self.probability.update(1, 6 - @as(u4, n));
618
+ d.confusion = 0;
619
+ } else {
620
+ assert(obs == .continuing);
621
+ assert(n >= 1 and n < 5);
622
+ if (n > 1) try self.probability.update(6 - @as(u4, n) - 1, 6 - @as(u4, n));
623
+ d.confusion += 1;
624
+ }
625
+ }
626
+
627
+ pub fn disable(self: *Self, player: Player, obs: Optional(Observation)) Error!void {
628
+ if (!enabled) return;
629
+
630
+ var a = self.actions.get(player);
631
+ assert(a.disable == .None or a.disable == .started);
632
+ a.disable = obs;
633
+
634
+ var d = self.durations.get(player);
635
+ const n = d.disable;
636
+
637
+ if (obs == .ended) {
638
+ assert(n >= 1 and n <= 8);
639
+ if (n != 8) try self.probability.update(1, 9 - @as(u4, n));
640
+ d.disable = 0;
641
+ } else {
642
+ assert(obs == .continuing);
643
+ assert(n >= 1 and n < 8);
644
+ try self.probability.update(9 - @as(u4, n) - 1, 9 - @as(u4, n));
645
+ d.disable += 1;
646
+ }
647
+ }
648
+
649
+ pub fn attacking(self: *Self, player: Player, obs: Optional(Observation)) Error!void {
650
+ if (!enabled) return;
651
+
652
+ var a = self.actions.get(player);
653
+ assert(a.attacking == .None or a.attacking == .started);
654
+ a.attacking = obs;
655
+
656
+ var d = self.durations.get(player);
657
+ const n = d.attacking;
658
+ if (obs == .ended) {
659
+ // "3-4 turns" includes the turn for the initial attack *plus* the forced attacks
660
+ assert(n >= 2 and n <= 3);
661
+ if (n != 3) try self.probability.update(1, 4 - @as(u4, n));
662
+ d.attacking = 0;
663
+ } else {
664
+ assert(obs == .continuing);
665
+ assert(n >= 1 and n < 3);
666
+ if (n > 1) try self.probability.update(4 - @as(u4, n) - 1, 4 - @as(u4, n));
667
+ d.attacking += 1;
668
+ }
669
+ }
670
+
671
+ pub fn binding(self: *Self, player: Player, obs: Optional(Observation)) Error!void {
672
+ if (!enabled) return;
673
+
674
+ var a = self.actions.get(player);
675
+ assert(a.binding == .None or a.binding == .started);
676
+ a.binding = obs;
677
+
678
+ var d = self.durations.get(player);
679
+ const n = d.binding;
680
+
681
+ assert(n > 0);
682
+ const p: u4 = if (n < 3) 3 else 1;
683
+ const q: u4 = if (n < 3) 8 - ((n - 1) * p) else 2;
684
+
685
+ if (obs == .ended) {
686
+ // "2-5 turns" includes the turn for the initial attack *plus* the forced attacks
687
+ assert(n >= 1 and n <= 4);
688
+ if (n != 4) try self.probability.update(p, q);
689
+ d.binding = 0;
690
+ } else {
691
+ assert(obs == .continuing);
692
+ assert(n >= 1 and n < 4);
693
+ try self.probability.update(q - p, q);
694
+ d.binding += 1;
695
+ }
696
+ }
697
+
698
+ pub fn psywave(self: *Self, player: Player, power: u8, max: u8) Error!void {
699
+ if (!enabled) return;
700
+
701
+ try self.probability.update(1, max);
702
+ self.actions.get(player).psywave = power + 1;
703
+ }
704
+
705
+ pub fn metronome(self: *Self, player: Player, move: Move) Error!void {
706
+ if (!enabled) return;
707
+
708
+ try self.probability.update(1, Move.METRONOME.len);
709
+ self.actions.get(player).metronome = move;
710
+ }
711
+
712
+ pub fn pp(self: *Self, player: Player, n: u4) bool {
713
+ if (!enabled) return true;
714
+
715
+ var a = self.actions.get(player);
716
+ if (n > 1 and a.pp == n) return false;
717
+ if (a.metronome != .None) a.pp += n;
718
+ return true;
719
+ }
720
+ };
721
+ }
722
+
723
+ test "Chance.speedTie" {
724
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
725
+
726
+ try chance.speedTie(true);
727
+ try expectProbability(&chance.probability, 1, 2);
728
+ try expectValue(Optional(Player).P1, chance.actions.p1.speed_tie);
729
+ try expectValue(chance.actions.p1.speed_tie, chance.actions.p2.speed_tie);
730
+
731
+ chance.reset();
732
+
733
+ try chance.speedTie(false);
734
+ try expectProbability(&chance.probability, 1, 2);
735
+ try expectValue(Optional(Player).P2, chance.actions.p1.speed_tie);
736
+ try expectValue(chance.actions.p1.speed_tie, chance.actions.p2.speed_tie);
737
+ }
738
+
739
+ test "Chance.hit" {
740
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
741
+
742
+ try chance.hit(.P1, true, 229);
743
+ if (!showdown) {
744
+ try expectProbability(&chance.probability, 1, 1);
745
+ try expectValue(Optional(bool).None, chance.actions.p1.hit);
746
+
747
+ try chance.commit(.P1, .hit);
748
+ }
749
+ try expectValue(Optional(bool).true, chance.actions.p1.hit);
750
+ try expectProbability(&chance.probability, 229, 256);
751
+
752
+ chance.reset();
753
+
754
+ try chance.hit(.P2, false, 255);
755
+ if (!showdown) {
756
+ try expectProbability(&chance.probability, 1, 1);
757
+ try expectValue(Optional(bool).None, chance.actions.p2.hit);
758
+
759
+ try chance.commit(.P2, .miss);
760
+ }
761
+ try expectValue(Optional(bool).false, chance.actions.p2.hit);
762
+ try expectProbability(&chance.probability, 1, 256);
763
+ }
764
+
765
+ test "Chance.criticalHit" {
766
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
767
+
768
+ try chance.criticalHit(.P1, true, 17);
769
+ if (showdown) {
770
+ try expectValue(Optional(bool).true, chance.actions.p1.critical_hit);
771
+ try expectProbability(&chance.probability, 17, 256);
772
+ } else {
773
+ try expectProbability(&chance.probability, 1, 1);
774
+ try expectValue(Optional(bool).None, chance.actions.p1.critical_hit);
775
+
776
+ try chance.hit(.P1, true, 128);
777
+
778
+ try expectProbability(&chance.probability, 1, 1);
779
+ try expectValue(Optional(bool).None, chance.actions.p1.critical_hit);
780
+
781
+ try chance.damage(.P1, 217);
782
+
783
+ try expectProbability(&chance.probability, 1, 1);
784
+ try expectValue(Optional(bool).None, chance.actions.p1.critical_hit);
785
+
786
+ try chance.commit(.P1, .hit);
787
+
788
+ try expectProbability(&chance.probability, 17, 19968); // (1/2) * (17/256) * (1/39)
789
+ try expectValue(Optional(bool).true, chance.actions.p1.critical_hit);
790
+ }
791
+
792
+ chance.reset();
793
+
794
+ try chance.criticalHit(.P2, false, 5);
795
+ if (showdown) {
796
+ try expectProbability(&chance.probability, 251, 256);
797
+ try expectValue(Optional(bool).false, chance.actions.p2.critical_hit);
798
+ } else {
799
+ try expectProbability(&chance.probability, 1, 1);
800
+ try expectValue(Optional(bool).None, chance.actions.p1.critical_hit);
801
+
802
+ try chance.hit(.P1, true, 128);
803
+
804
+ try expectProbability(&chance.probability, 1, 1);
805
+ try expectValue(Optional(bool).None, chance.actions.p1.critical_hit);
806
+
807
+ try chance.damage(.P1, 217);
808
+ try chance.commit(.P1, .hit);
809
+
810
+ try expectProbability(&chance.probability, 251, 19968); // (1/2) * (251/256) * (1/39)
811
+ try expectValue(Optional(bool).false, chance.actions.p1.critical_hit);
812
+ }
813
+ }
814
+
815
+ test "Chance.damage" {
816
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
817
+
818
+ try chance.damage(.P1, 217);
819
+ if (showdown) {
820
+ try expectValue(@as(u8, 217), chance.actions.p1.damage);
821
+ try expectProbability(&chance.probability, 1, 39);
822
+ } else {
823
+ try expectProbability(&chance.probability, 1, 1);
824
+ try expectValue(@as(u8, 0), chance.actions.p1.damage);
825
+
826
+ try chance.commit(.P1, .hit);
827
+
828
+ try expectProbability(&chance.probability, 1, 39);
829
+ try expectValue(@as(u8, 217), chance.actions.p1.damage);
830
+ }
831
+ }
832
+
833
+ test "Chance.secondaryChance" {
834
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
835
+
836
+ try chance.secondaryChance(.P1, true, 25);
837
+ try expectProbability(&chance.probability, 25, 256);
838
+ try expectValue(Optional(bool).true, chance.actions.p1.secondary_chance);
839
+
840
+ chance.reset();
841
+
842
+ try chance.secondaryChance(.P2, false, 77);
843
+ try expectProbability(&chance.probability, 179, 256);
844
+ try expectValue(Optional(bool).false, chance.actions.p2.secondary_chance);
845
+ }
846
+
847
+ test "Chance.confused" {
848
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
849
+
850
+ try chance.confused(.P1, false);
851
+ try expectProbability(&chance.probability, 1, 2);
852
+ try expectValue(Optional(bool).false, chance.actions.p1.confused);
853
+
854
+ chance.reset();
855
+
856
+ try chance.confused(.P2, true);
857
+ try expectProbability(&chance.probability, 1, 2);
858
+ try expectValue(Optional(bool).true, chance.actions.p2.confused);
859
+ }
860
+
861
+ test "Chance.paralyzed" {
862
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
863
+
864
+ try chance.paralyzed(.P1, false);
865
+ try expectProbability(&chance.probability, 3, 4);
866
+ try expectValue(Optional(bool).false, chance.actions.p1.paralyzed);
867
+
868
+ chance.reset();
869
+
870
+ try chance.paralyzed(.P2, true);
871
+ try expectProbability(&chance.probability, 1, 4);
872
+ try expectValue(Optional(bool).true, chance.actions.p2.paralyzed);
873
+ }
874
+
875
+ test "Chance.moveSlot" {
876
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
877
+ var ms = [_]MoveSlot{ .{ .id = Move.Surf }, .{ .id = Move.Psychic }, .{ .id = Move.Recover } };
878
+
879
+ try chance.moveSlot(.P2, 2, &ms, 2);
880
+ try expectProbability(&chance.probability, 1, 2);
881
+ try expectValue(@as(u4, 2), chance.actions.p2.move_slot);
882
+
883
+ chance.reset();
884
+
885
+ try chance.moveSlot(.P1, 1, &ms, 0);
886
+ try expectProbability(&chance.probability, 1, 3);
887
+ try expectValue(@as(u4, 1), chance.actions.p1.move_slot);
888
+ }
889
+
890
+ test "Chance.multiHit" {
891
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
892
+
893
+ try chance.multiHit(.P1, 3);
894
+ try expectProbability(&chance.probability, 3, 8);
895
+ try expectValue(@as(u4, 3), chance.actions.p1.multi_hit);
896
+
897
+ chance.reset();
898
+
899
+ try chance.multiHit(.P2, 5);
900
+ try expectProbability(&chance.probability, 1, 8);
901
+ try expectValue(@as(u4, 5), chance.actions.p2.multi_hit);
902
+ }
903
+
904
+ test "Chance.duration" {
905
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
906
+
907
+ chance.duration(.P1, 2);
908
+ try expectValue(@as(u4, 2), chance.actions.p1.duration);
909
+
910
+ chance.reset();
911
+
912
+ chance.duration(.P2, 4);
913
+ try expectValue(@as(u4, 4), chance.actions.p2.duration);
914
+ }
915
+
916
+ test "Chance.sleep" {
917
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
918
+
919
+ for ([_]u8{ 7, 6, 5, 4, 3, 2, 1 }, 1..8) |d, i| {
920
+ chance.durations.p1.sleeps = Sleeps.set(chance.durations.p1.sleeps, 0, @intCast(i));
921
+ try chance.sleep(.P1, .ended);
922
+ try expectProbability(&chance.probability, 1, d);
923
+ try expectValue(@as(u3, 0), Sleeps.get(chance.durations.p1.sleeps, 0));
924
+
925
+ chance.reset();
926
+
927
+ if (i < 7) {
928
+ chance.durations.p1.sleeps = Sleeps.set(chance.durations.p1.sleeps, 0, @intCast(i));
929
+ try chance.sleep(.P1, .continuing);
930
+ try expectProbability(&chance.probability, d - 1, d);
931
+ try expectValue(@as(u3, @intCast(i)) + 1, Sleeps.get(chance.durations.p1.sleeps, 0));
932
+
933
+ chance.reset();
934
+ }
935
+ }
936
+ }
937
+
938
+ test "Chance.confusion" {
939
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
940
+
941
+ for ([_]u8{ 1, 4, 3, 2, 1 }, 1..6) |d, i| {
942
+ if (i > 1) {
943
+ chance.durations.p2.confusion = @intCast(i);
944
+ try chance.confusion(.P2, .ended);
945
+ try expectProbability(&chance.probability, 1, d);
946
+ try expectValue(@as(u3, 0), chance.durations.p2.confusion);
947
+
948
+ chance.reset();
949
+ }
950
+
951
+ if (i < 5) {
952
+ chance.durations.p2.confusion = @intCast(i);
953
+ try chance.confusion(.P2, .continuing);
954
+ try expectProbability(&chance.probability, if (d > 1) d - 1 else d, d);
955
+ try expectValue(@as(u3, @intCast(i)) + 1, chance.durations.p2.confusion);
956
+
957
+ chance.reset();
958
+ }
959
+ }
960
+ }
961
+
962
+ test "Chance.disable" {
963
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
964
+
965
+ for ([_]u8{ 8, 7, 6, 5, 4, 3, 2, 1 }, 1..9) |d, i| {
966
+ chance.durations.p1.disable = @intCast(i);
967
+ try chance.disable(.P1, .ended);
968
+ try expectProbability(&chance.probability, 1, d);
969
+ try expectValue(@as(u4, 0), chance.durations.p1.disable);
970
+
971
+ chance.reset();
972
+
973
+ if (i < 8) {
974
+ chance.durations.p1.disable = @intCast(i);
975
+ try chance.disable(.P1, .continuing);
976
+ try expectProbability(&chance.probability, d - 1, d);
977
+ try expectValue(@as(u4, @intCast(i)) + 1, chance.durations.p1.disable);
978
+
979
+ chance.reset();
980
+ }
981
+ }
982
+ }
983
+
984
+ test "Chance.attacking" {
985
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
986
+
987
+ for ([_]u8{ 1, 2, 1 }, 1..4) |d, i| {
988
+ if (i > 1) {
989
+ chance.durations.p2.attacking = @intCast(i);
990
+ try chance.attacking(.P2, .ended);
991
+ try expectProbability(&chance.probability, 1, d);
992
+ try expectValue(@as(u3, 0), chance.durations.p2.attacking);
993
+
994
+ chance.reset();
995
+ }
996
+
997
+ if (i < 3) {
998
+ chance.durations.p2.attacking = @intCast(i);
999
+ try chance.attacking(.P2, .continuing);
1000
+ try expectProbability(&chance.probability, if (d > 1) d - 1 else d, d);
1001
+ try expectValue(@as(u3, @intCast(i)) + 1, chance.durations.p2.attacking);
1002
+
1003
+ chance.reset();
1004
+ }
1005
+ }
1006
+ }
1007
+
1008
+ test "Chance.binding" {
1009
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
1010
+
1011
+ const ps = [_]u8{ 3, 3, 1, 1 };
1012
+ const qs = [_]u8{ 8, 5, 2, 1 };
1013
+
1014
+ for (ps, qs, 1..5) |p, q, i| {
1015
+ chance.durations.p1.binding = @intCast(i);
1016
+ try chance.binding(.P1, .ended);
1017
+ try expectProbability(&chance.probability, p, q);
1018
+ try expectValue(@as(u3, 0), chance.durations.p1.binding);
1019
+
1020
+ chance.reset();
1021
+
1022
+ if (i < 4) {
1023
+ chance.durations.p1.binding = @intCast(i);
1024
+ try chance.binding(.P1, .continuing);
1025
+ try expectProbability(&chance.probability, q - p, q);
1026
+ try expectValue(@as(u3, @intCast(i)) + 1, chance.durations.p1.binding);
1027
+
1028
+ chance.reset();
1029
+ }
1030
+ }
1031
+ }
1032
+
1033
+ test "Chance.psywave" {
1034
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
1035
+
1036
+ try chance.psywave(.P2, 100, 150);
1037
+ try expectProbability(&chance.probability, 1, 150);
1038
+ try expectValue(@as(u8, 101), chance.actions.p2.psywave);
1039
+ }
1040
+
1041
+ test "Chance.metronome" {
1042
+ var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
1043
+
1044
+ try chance.metronome(.P1, Move.HornAttack);
1045
+ try expectProbability(&chance.probability, 1, 163);
1046
+ try expectValue(Move.HornAttack, chance.actions.p1.metronome);
1047
+ }
1048
+
1049
+ pub fn expectProbability(r: anytype, p: u64, q: u64) !void {
1050
+ if (!enabled) return;
1051
+
1052
+ r.reduce();
1053
+ if (r.p != p or r.q != q) {
1054
+ print("expected {d}/{d}, found {}\n", .{ p, q, r });
1055
+ return error.TestExpectedEqual;
1056
+ }
1057
+ }
1058
+
1059
+ pub fn expectValue(a: anytype, b: anytype) !void {
1060
+ if (!enabled) return;
1061
+
1062
+ try expectEqual(a, b);
1063
+ }
1064
+
1065
+ /// Null object pattern implementation of Generation I `Chance` which does nothing, though chance
1066
+ /// tracking should additionally be turned off entirely via `options.chance`.
1067
+ pub const NULL: Null = .{};
1068
+
1069
+ const Null = struct {
1070
+ pub const Error = error{};
1071
+
1072
+ pub fn commit(self: Null, player: Player, kind: Commit) Error!void {
1073
+ _ = .{ self, player, kind };
1074
+ }
1075
+
1076
+ pub fn glitch(self: Null) void {
1077
+ _ = .{self};
1078
+ }
1079
+
1080
+ pub fn clearPending(self: Null) void {
1081
+ _ = .{self};
1082
+ }
1083
+
1084
+ pub fn switched(self: Null, player: Player, slot: u8) void {
1085
+ _ = .{ self, player, slot };
1086
+ }
1087
+
1088
+ pub fn speedTie(self: Null, p1: bool) Error!void {
1089
+ _ = .{ self, p1 };
1090
+ }
1091
+
1092
+ pub fn hit(self: Null, player: Player, ok: bool, accuracy: uN) Error!void {
1093
+ _ = .{ self, player, ok, accuracy };
1094
+ }
1095
+
1096
+ pub fn criticalHit(self: Null, player: Player, crit: bool, rate: u8) Error!void {
1097
+ _ = .{ self, player, crit, rate };
1098
+ }
1099
+
1100
+ pub fn damage(self: Null, player: Player, roll: u8) Error!void {
1101
+ _ = .{ self, player, roll };
1102
+ }
1103
+
1104
+ pub fn confused(self: Null, player: Player, ok: bool) Error!void {
1105
+ _ = .{ self, player, ok };
1106
+ }
1107
+
1108
+ pub fn paralyzed(self: Null, player: Player, ok: bool) Error!void {
1109
+ _ = .{ self, player, ok };
1110
+ }
1111
+
1112
+ pub fn secondaryChance(self: Null, player: Player, proc: bool, rate: u8) Error!void {
1113
+ _ = .{ self, player, proc, rate };
1114
+ }
1115
+
1116
+ pub fn moveSlot(self: Null, player: Player, slot: u4, ms: []const MoveSlot, n: u4) Error!void {
1117
+ _ = .{ self, player, slot, ms, n };
1118
+ }
1119
+
1120
+ pub fn multiHit(self: Null, player: Player, n: u3) Error!void {
1121
+ _ = .{ self, player, n };
1122
+ }
1123
+
1124
+ pub fn duration(self: Null, player: Player, turns: u4) void {
1125
+ _ = .{ self, player, turns };
1126
+ }
1127
+
1128
+ pub fn observe(
1129
+ self: Null,
1130
+ comptime field: Action.Field,
1131
+ player: Player,
1132
+ obs: Optional(Confusion),
1133
+ ) void {
1134
+ _ = .{ self, field, player, obs };
1135
+ }
1136
+
1137
+ pub fn sleep(self: Null, player: Player, obs: Optional(Observation)) Error!void {
1138
+ _ = .{ self, player, obs };
1139
+ }
1140
+
1141
+ pub fn confusion(self: Null, player: Player, obs: Optional(Confusion)) Error!void {
1142
+ _ = .{ self, player, obs };
1143
+ }
1144
+
1145
+ pub fn disable(self: Null, player: Player, obs: Optional(Observation)) Error!void {
1146
+ _ = .{ self, player, obs };
1147
+ }
1148
+
1149
+ pub fn attacking(self: Null, player: Player, obs: Optional(Observation)) Error!void {
1150
+ _ = .{ self, player, obs };
1151
+ }
1152
+
1153
+ pub fn binding(self: Null, player: Player, obs: Optional(Observation)) Error!void {
1154
+ _ = .{ self, player, obs };
1155
+ }
1156
+
1157
+ pub fn psywave(self: Null, player: Player, power: u8, max: u8) Error!void {
1158
+ _ = .{ self, player, power, max };
1159
+ }
1160
+
1161
+ pub fn metronome(self: Null, player: Player, move: Move) Error!void {
1162
+ _ = .{ self, player, move };
1163
+ }
1164
+
1165
+ pub fn pp(self: Null, player: Player, n: u4) bool {
1166
+ _ = .{ self, player, n };
1167
+ return true;
1168
+ }
1169
+ };