@pkmn/engine 0.1.0-dev.46307385 → 0.1.0-dev.4c173f03

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.
@@ -1,4 +1,4 @@
1
- //! Code generated by `tools/generate` - manual edits will be overwritten
1
+ //! Code generated by `tools/generate` - manual edits will be overwritten.
2
2
 
3
3
  const std = @import("std");
4
4
 
@@ -1,4 +1,4 @@
1
- //! Code generated by `tools/generate` - manual edits will be overwritten
1
+ //! Code generated by `tools/generate` - manual edits will be overwritten.
2
2
 
3
3
  const std = @import("std");
4
4
 
@@ -30,7 +30,7 @@ pub const Type = enum(u4) {
30
30
  Ice,
31
31
  Dragon,
32
32
 
33
- const CHART = [15][15]Effectiveness{
33
+ const CHART: [15][15]Effectiveness = .{
34
34
  [_]Effectiveness{ N, N, N, N, N, R, N, I, N, N, N, N, N, N, N }, // Normal
35
35
  [_]Effectiveness{ S, N, R, R, N, S, R, I, N, N, N, N, R, S, N }, // Fighting
36
36
  [_]Effectiveness{ N, S, N, N, N, R, S, N, N, N, S, R, N, N, N }, // Flying
@@ -99,7 +99,7 @@ pub const Type = enum(u4) {
99
99
  return CHART[@intFromEnum(t1)][@intFromEnum(t2)];
100
100
  }
101
101
 
102
- /// The precedence order of type `t2` vs. type `t1`.
102
+ /// The precedence order of Type `t2` vs. Type `t1`.
103
103
  pub fn precedence(t1: Type, t2: Type) u8 {
104
104
  for (PRECEDENCE, 0..) |matchup, i| {
105
105
  if (matchup.type1 == t1 and matchup.type2 == t2) return @intCast(i);
@@ -214,7 +214,7 @@ pub const Pokemon = extern struct {
214
214
  }
215
215
  };
216
216
 
217
- /// Representation of a Generation I & II Pokémon's move slot in a battle.
217
+ /// Representation of a Generation I Pokémon's move slot in a battle.
218
218
  pub const MoveSlot = extern struct {
219
219
  /// The identifier for the move.
220
220
  id: Move = .None,
@@ -222,20 +222,16 @@ pub const MoveSlot = extern struct {
222
222
  pp: u8 = 0,
223
223
 
224
224
  comptime {
225
- assert(@sizeOf(MoveSlot) == @sizeOf(u16));
225
+ assert(@sizeOf(MoveSlot) == 2);
226
226
  }
227
227
  };
228
228
 
229
229
  /// Details required to detect desyncs based on the move last selected/executed by players.
230
- pub const MoveDetails = packed struct {
230
+ pub const MoveDetails = packed struct(if (showdown) u16 else u8) {
231
231
  /// The move slot index of the last move selected in the battle menu.
232
232
  index: if (showdown) u8 else u4 = 0,
233
233
  /// Whether the last move executed was counterable.
234
234
  counterable: if (showdown) u8 else u4 = 0,
235
-
236
- comptime {
237
- assert(@sizeOf(MoveDetails) == if (showdown) 2 else 1);
238
- }
239
235
  };
240
236
 
241
237
  /// Bitfield representation of a Generation I & II Pokémon's major status condition.
@@ -329,7 +325,7 @@ test Status {
329
325
  }
330
326
 
331
327
  /// Bitfield representation of volatile statuses and associated data in Generation I.
332
- pub const Volatiles = packed struct {
328
+ pub const Volatiles = packed struct(u64) {
333
329
  /// Whether the "Bide" volatile status is present.
334
330
  Bide: bool = false,
335
331
  /// Whether the "Thrashing" volatile status is present.
@@ -382,19 +378,15 @@ pub const Volatiles = packed struct {
382
378
  /// The identity of whom the active Pokémon is transformed into.
383
379
  transform: u4 = 0,
384
380
  /// The remaining turns the move is disabled.
385
- disabled_duration: u4 = 0,
381
+ disable_duration: u4 = 0,
386
382
  /// The move slot (1-4) that is disabled.
387
- disabled_move: u3 = 0,
383
+ disable_move: u3 = 0,
388
384
  /// The number of turns toxic damage has been accumulating.
389
385
  toxic: u5 = 0,
390
-
391
- comptime {
392
- assert(@sizeOf(Volatiles) == 8);
393
- }
394
386
  };
395
387
 
396
388
  test Volatiles {
397
- var volatiles = Volatiles{};
389
+ var volatiles: Volatiles = .{};
398
390
  volatiles.Confusion = true;
399
391
  volatiles.confusion = 2;
400
392
  volatiles.Thrashing = true;
@@ -403,8 +395,8 @@ test Volatiles {
403
395
  volatiles.Substitute = true;
404
396
  volatiles.substitute = 42;
405
397
  volatiles.toxic = 4;
406
- volatiles.disabled_move = 2;
407
- volatiles.disabled_duration = 4;
398
+ volatiles.disable_move = 2;
399
+ volatiles.disable_duration = 4;
408
400
 
409
401
  try expect(volatiles.Confusion);
410
402
  try expect(volatiles.Thrashing);
@@ -415,8 +407,8 @@ test Volatiles {
415
407
 
416
408
  try expectEqual(@as(u16, 235), volatiles.state);
417
409
  try expectEqual(@as(u8, 42), volatiles.substitute);
418
- try expectEqual(@as(u4, 2), volatiles.disabled_move);
419
- try expectEqual(@as(u4, 4), volatiles.disabled_duration);
410
+ try expectEqual(@as(u4, 2), volatiles.disable_move);
411
+ try expectEqual(@as(u4, 4), volatiles.disable_duration);
420
412
  try expectEqual(@as(u4, 2), volatiles.confusion);
421
413
  try expectEqual(@as(u5, 4), volatiles.toxic);
422
414
  try expectEqual(@as(u4, 3), volatiles.attacks);
@@ -456,7 +448,7 @@ test Stats {
456
448
  }
457
449
 
458
450
  /// Representation of a Pokémon's boosts in Generation I.
459
- pub const Boosts = packed struct {
451
+ pub const Boosts = packed struct(u32) {
460
452
  /// A Pokémon's Attack boosts.
461
453
  atk: i4 = 0,
462
454
  /// A Pokémon's Defense boosts.
@@ -471,14 +463,10 @@ pub const Boosts = packed struct {
471
463
  evasion: i4 = 0,
472
464
 
473
465
  _: u8 = 0,
474
-
475
- comptime {
476
- assert(@sizeOf(Boosts) == 4);
477
- }
478
466
  };
479
467
 
480
468
  test Boosts {
481
- const boosts = Boosts{ .spc = -6 };
469
+ const boosts: Boosts = .{ .spc = -6 };
482
470
  try expectEqual(0, boosts.atk);
483
471
  try expectEqual(-6, boosts.spc);
484
472
  }
@@ -490,7 +478,7 @@ test Move {
490
478
  try expectEqual(2, @intFromEnum(Move.KarateChop));
491
479
  const move = Move.get(.Fissure);
492
480
  try expectEqual(Move.Effect.OHKO, move.effect);
493
- try expectEqual(@as(u8, 30), move.accuracy);
481
+ try expectEqual(rng.Gen12.percent(30), move.accuracy);
494
482
  try expectEqual(Type.Ground, move.type);
495
483
 
496
484
  try expect(!Move.Effect.onBegin(.None));
@@ -628,16 +616,16 @@ pub const DVs = struct {
628
616
  };
629
617
 
630
618
  test DVs {
631
- var dvs = DVs{ .spc = 15, .spe = 15 };
619
+ var dvs: DVs = .{ .spc = 15, .spe = 15 };
632
620
  try expectEqual(@as(u4, 15), dvs.hp());
633
- dvs = DVs{
621
+ dvs = .{
634
622
  .atk = 5,
635
623
  .def = 15,
636
624
  .spe = 13,
637
625
  .spc = 13,
638
626
  };
639
627
  try expectEqual(@as(u4, 15), dvs.hp());
640
- dvs = DVs{
628
+ dvs = .{
641
629
  .def = 3,
642
630
  .spe = 10,
643
631
  .spc = 11,
@@ -455,36 +455,21 @@ pub const Rolls = struct {
455
455
  }
456
456
 
457
457
  const MOVE_NONE = [_]Move{.None};
458
- const MOVES = init: {
459
- var moves: [Move.size - 2]Move = undefined;
460
- var i: usize = 0;
461
- for (@typeInfo(Move).Enum.fields) |f| {
462
- if (!(std.mem.eql(u8, f.name, "None") or
463
- std.mem.eql(u8, f.name, "Metronome") or
464
- std.mem.eql(u8, f.name, "Struggle") or
465
- std.mem.eql(u8, f.name, "SKIP_TURN")))
466
- {
467
- moves[i] = @field(Move, f.name);
468
- i += 1;
469
- }
470
- }
471
- break :init moves;
472
- };
473
458
 
474
459
  /// Returns a slice with the correct range of values for metronome given the `action` state.
475
460
  pub inline fn metronome(action: Action) []const Move {
476
- return if (@field(action, "metronome") == .None) &MOVE_NONE else &MOVES;
461
+ return if (@field(action, "metronome") == .None) &MOVE_NONE else &Move.METRONOME;
477
462
  }
478
463
  };
479
464
 
480
465
  test "Rolls.speedTie" {
481
- const actions = Actions{ .p1 = .{ .speed_tie = .P2 } };
466
+ const actions: Actions = .{ .p1 = .{ .speed_tie = .P2 } };
482
467
  try expectEqualSlices(Optional(Player), &.{ .P1, .P2 }, Rolls.speedTie(actions.p1));
483
468
  try expectEqualSlices(Optional(Player), &.{.None}, Rolls.speedTie(actions.p2));
484
469
  }
485
470
 
486
471
  test "Rolls.damage" {
487
- const actions = Actions{ .p2 = .{ .damage = 221 } };
472
+ const actions: Actions = .{ .p2 = .{ .damage = 221 } };
488
473
  try expectEqual(Rolls.Range{ .min = 0, .max = 1 }, Rolls.damage(actions.p1, .None));
489
474
  try expectEqual(Rolls.Range{ .min = 217, .max = 256 }, Rolls.damage(actions.p2, .None));
490
475
  try expectEqual(Rolls.Range{ .min = 0, .max = 1 }, Rolls.damage(actions.p2, .false));
@@ -502,7 +487,7 @@ test "Rolls.coalesce" {
502
487
  }
503
488
 
504
489
  test "Rolls.hit" {
505
- const actions = Actions{ .p2 = .{ .hit = .true } };
490
+ const actions: Actions = .{ .p2 = .{ .hit = .true } };
506
491
  try expectEqualSlices(Optional(bool), &.{.None}, Rolls.hit(actions.p1, .None));
507
492
  try expectEqualSlices(Optional(bool), &.{ .false, .true }, Rolls.hit(actions.p2, .None));
508
493
  try expectEqualSlices(Optional(bool), &.{.None}, Rolls.hit(actions.p2, .true));
@@ -510,7 +495,7 @@ test "Rolls.hit" {
510
495
  }
511
496
 
512
497
  test "Rolls.secondaryChance" {
513
- const actions = Actions{ .p1 = .{ .secondary_chance = .true } };
498
+ const actions: Actions = .{ .p1 = .{ .secondary_chance = .true } };
514
499
  try expectEqualSlices(
515
500
  Optional(bool),
516
501
  &.{ .false, .true },
@@ -521,7 +506,7 @@ test "Rolls.secondaryChance" {
521
506
  }
522
507
 
523
508
  test "Rolls.criticalHit" {
524
- const actions = Actions{ .p1 = .{ .critical_hit = .true } };
509
+ const actions: Actions = .{ .p1 = .{ .critical_hit = .true } };
525
510
  try expectEqualSlices(
526
511
  Optional(bool),
527
512
  &.{ .false, .true },
@@ -532,14 +517,14 @@ test "Rolls.criticalHit" {
532
517
  }
533
518
 
534
519
  test "Rolls.confused" {
535
- const actions = Actions{ .p2 = .{ .confused = .true } };
520
+ const actions: Actions = .{ .p2 = .{ .confused = .true } };
536
521
  try expectEqualSlices(Optional(bool), &.{.None}, Rolls.confused(actions.p1, 1));
537
522
  try expectEqualSlices(Optional(bool), &.{ .false, .true }, Rolls.confused(actions.p2, 1));
538
523
  try expectEqualSlices(Optional(bool), &.{.None}, Rolls.confused(actions.p2, 0));
539
524
  }
540
525
 
541
526
  test "Rolls.paralyzed" {
542
- const actions = Actions{ .p2 = .{ .paralyzed = .true } };
527
+ const actions: Actions = .{ .p2 = .{ .paralyzed = .true } };
543
528
  try expectEqualSlices(Optional(bool), &.{.None}, Rolls.paralyzed(actions.p1, .None));
544
529
  try expectEqualSlices(Optional(bool), &.{ .false, .true }, Rolls.paralyzed(actions.p2, .None));
545
530
  try expectEqualSlices(Optional(bool), &.{ .false, .true }, Rolls.paralyzed(actions.p2, .false));
@@ -547,7 +532,7 @@ test "Rolls.paralyzed" {
547
532
  }
548
533
 
549
534
  test "Rolls.duration" {
550
- const actions = Actions{ .p2 = .{ .duration = 3 } };
535
+ const actions: Actions = .{ .p2 = .{ .duration = 3 } };
551
536
  try expectEqualSlices(u1, &.{0}, Rolls.duration(actions.p1, .None));
552
537
  try expectEqualSlices(u1, &.{1}, Rolls.duration(actions.p2, .None));
553
538
  try expectEqualSlices(u1, &.{0}, Rolls.duration(actions.p2, .false));
@@ -757,27 +742,27 @@ test "Rolls.binding" {
757
742
  }
758
743
 
759
744
  test "Rolls.moveSlot" {
760
- const actions = Actions{ .p2 = .{ .move_slot = 3 } };
745
+ const actions: Actions = .{ .p2 = .{ .move_slot = 3 } };
761
746
  try expectEqualSlices(u4, &.{0}, Rolls.moveSlot(actions.p1, .None));
762
747
  try expectEqualSlices(u4, &.{ 1, 2, 3, 4 }, Rolls.moveSlot(actions.p2, .None));
763
748
  try expectEqualSlices(u4, &.{0}, Rolls.moveSlot(actions.p2, .false));
764
749
  }
765
750
 
766
751
  test "Rolls.multiHit" {
767
- const actions = Actions{ .p2 = .{ .multi_hit = 3 } };
752
+ const actions: Actions = .{ .p2 = .{ .multi_hit = 3 } };
768
753
  try expectEqualSlices(u4, &.{0}, Rolls.multiHit(actions.p1, .None));
769
754
  try expectEqualSlices(u4, &.{ 2, 3, 4, 5 }, Rolls.multiHit(actions.p2, .None));
770
755
  try expectEqualSlices(u4, &.{0}, Rolls.multiHit(actions.p2, .false));
771
756
  }
772
757
 
773
758
  test "Rolls.metronome" {
774
- const actions = Actions{ .p2 = .{ .metronome = .Surf } };
759
+ const actions: Actions = .{ .p2 = .{ .metronome = .Surf } };
775
760
  try expectEqualSlices(Move, &.{.None}, Rolls.metronome(actions.p1));
776
761
  try expectEqual(@as(Move, @enumFromInt(24)), Rolls.metronome(actions.p2)[23]);
777
762
  }
778
763
 
779
764
  test "Rolls.psywave" {
780
- const actions = Actions{ .p2 = .{ .psywave = 79 } };
765
+ const actions: Actions = .{ .p2 = .{ .psywave = 79 } };
781
766
  var side = Side.init(&[_]Pokemon{.{
782
767
  .species = .Bulbasaur,
783
768
  .level = 100,