@pkmn/engine 0.1.0-dev.900756a9 → 0.1.0-dev.9257876b

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.
@@ -14,7 +14,7 @@ const util = @import("../common/util.zig");
14
14
  const Player = @import("../common/data.zig").Player;
15
15
  const Optional = @import("../common/optional.zig").Optional;
16
16
 
17
- const data = @import("./data.zig");
17
+ const data = @import("data.zig");
18
18
 
19
19
  const enabled = options.chance;
20
20
  const showdown = options.showdown;
@@ -97,16 +97,17 @@ pub const Actions = extern struct {
97
97
  }
98
98
  };
99
99
 
100
+ // TODO: ziglang/zig#19730
100
101
  test Actions {
101
102
  const a: Actions = .{ .p1 = .{ .hit = .true, .critical_hit = .false, .damage = 245 } };
102
103
  const b: Actions = .{ .p1 = .{ .hit = .false, .critical_hit = .true, .damage = 246 } };
103
104
  const c: Actions = .{ .p1 = .{ .hit = .true } };
104
- const d: Actions = .{ .p2 = .{ .hit = .true, .durations = .{ .sleep = 2 } } };
105
- const e: Actions = .{ .p2 = .{ .hit = .false, .durations = .{ .sleep = 4 } } };
106
- const f: Actions = .{ .p1 = .{ .hit = .false, .durations = .{ .sleep = 4 } } };
107
- const g: Actions = .{ .p1 = .{ .hit = .false, .durations = .{ .confusion = 1 } } };
108
- const h: Actions =
109
- .{ .p1 = .{ .hit = .false, .durations = .{ .confusion = 1, .thrash = true } } };
105
+ // const d: Actions = .{ .p2 = .{ .hit = .true, .durations = .{ .sleep = 2 } } };
106
+ // const e: Actions = .{ .p2 = .{ .hit = .false, .durations = .{ .sleep = 4 } } };
107
+ // const f: Actions = .{ .p1 = .{ .hit = .false, .durations = .{ .sleep = 4 } } };
108
+ // const g: Actions = .{ .p1 = .{ .hit = .false, .durations = .{ .confusion = 1 } } };
109
+ // const h: Actions =
110
+ // .{ .p1 = .{ .hit = .false, .durations = .{ .confusion = 1, .thrash = true } } };
110
111
 
111
112
  try expect(a.eql(a));
112
113
  try expect(!a.eql(b));
@@ -119,10 +120,10 @@ test Actions {
119
120
  try expect(b.matches(a));
120
121
  try expect(!a.matches(c));
121
122
  try expect(!c.matches(a));
122
- try expect(d.matches(e));
123
- try expect(!d.matches(f));
124
- try expect(!g.matches(h));
125
- try expect(h.matches(h));
123
+ // try expect(d.matches(e));
124
+ // try expect(!d.matches(f));
125
+ // try expect(!g.matches(h));
126
+ // try expect(h.matches(h));
126
127
  }
127
128
 
128
129
  /// Information about the RNG that was observed during a Generation II battle `update` for a
@@ -699,7 +700,7 @@ test "Chance.damage" {
699
700
  var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
700
701
 
701
702
  try chance.damage(.P1, 217);
702
- try expectValue(@as(u8, 217), chance.actions.p1.damage);
703
+ try expectValue(217, chance.actions.p1.damage);
703
704
  try expectProbability(&chance.probability, 1, 39);
704
705
  }
705
706
 
@@ -824,7 +825,7 @@ test "Chance.present" {
824
825
  } else {
825
826
  try expectProbability(&chance.probability, 25, 256);
826
827
  }
827
- try expectValue(@as(u3, 4), chance.actions.p2.present);
828
+ try expectValue(4, chance.actions.p2.present);
828
829
 
829
830
  chance.reset();
830
831
 
@@ -834,7 +835,7 @@ test "Chance.present" {
834
835
  } else {
835
836
  try expectProbability(&chance.probability, 51, 256);
836
837
  }
837
- try expectValue(@as(u3, 1), chance.actions.p1.present);
838
+ try expectValue(1, chance.actions.p1.present);
838
839
  }
839
840
 
840
841
  test "Chance.magnitude" {
@@ -846,7 +847,7 @@ test "Chance.magnitude" {
846
847
  } else {
847
848
  try expectProbability(&chance.probability, 13, 256);
848
849
  }
849
- try expectValue(@as(u3, 7), chance.actions.p2.magnitude);
850
+ try expectValue(7, chance.actions.p2.magnitude);
850
851
 
851
852
  chance.reset();
852
853
 
@@ -856,7 +857,7 @@ test "Chance.magnitude" {
856
857
  } else {
857
858
  try expectProbability(&chance.probability, 51, 256);
858
859
  }
859
- try expectValue(@as(u3, 5), chance.actions.p1.magnitude);
860
+ try expectValue(5, chance.actions.p1.magnitude);
860
861
  }
861
862
 
862
863
  test "Chance.tripleKick" {
@@ -864,7 +865,7 @@ test "Chance.tripleKick" {
864
865
 
865
866
  try chance.tripleKick(.P1, 2);
866
867
  try expectProbability(&chance.probability, 1, 3);
867
- try expectValue(@as(u2, 2), chance.actions.p1.triple_kick);
868
+ try expectValue(2, chance.actions.p1.triple_kick);
868
869
  }
869
870
 
870
871
  test "Chance.spite" {
@@ -872,7 +873,7 @@ test "Chance.spite" {
872
873
 
873
874
  try chance.spite(.P1, 3);
874
875
  try expectProbability(&chance.probability, 1, 4);
875
- try expectValue(@as(u3, 3), chance.actions.p1.spite);
876
+ try expectValue(3, chance.actions.p1.spite);
876
877
  }
877
878
 
878
879
  test "Chance.conversion2" {
@@ -899,7 +900,7 @@ test "Chance.psywave" {
899
900
 
900
901
  try chance.psywave(.P2, 100, 150);
901
902
  try expectProbability(&chance.probability, 1, 150);
902
- try expectValue(@as(u8, 100), chance.actions.p2.psywave);
903
+ try expectValue(100, chance.actions.p2.psywave);
903
904
  }
904
905
 
905
906
  test "Chance.metronome" {
@@ -915,19 +916,19 @@ test "Chance.moveSlot" {
915
916
 
916
917
  try chance.moveSlot(.P2, 2, 2);
917
918
  try expectProbability(&chance.probability, 1, 2);
918
- try expectValue(@as(u4, 2), chance.actions.p2.move_slot);
919
+ try expectValue(2, chance.actions.p2.move_slot);
919
920
 
920
921
  chance.reset();
921
922
 
922
923
  try chance.moveSlot(.P1, 1, 3);
923
924
  try expectProbability(&chance.probability, 1, 3);
924
- try expectValue(@as(u4, 1), chance.actions.p1.move_slot);
925
+ try expectValue(1, chance.actions.p1.move_slot);
925
926
 
926
927
  chance.reset();
927
928
 
928
929
  try chance.moveSlot(.P1, 4, 1);
929
930
  try expectProbability(&chance.probability, 1, 1);
930
- try expectValue(@as(u4, 4), chance.actions.p1.move_slot);
931
+ try expectValue(4, chance.actions.p1.move_slot);
931
932
  }
932
933
 
933
934
  test "Chance.forceSwitch" {
@@ -935,19 +936,19 @@ test "Chance.forceSwitch" {
935
936
 
936
937
  try chance.forceSwitch(.P2, 2, 2);
937
938
  try expectProbability(&chance.probability, 1, 2);
938
- try expectValue(@as(u4, 2), chance.actions.p2.force_switch);
939
+ try expectValue(2, chance.actions.p2.force_switch);
939
940
 
940
941
  chance.reset();
941
942
 
942
943
  try chance.forceSwitch(.P1, 1, 3);
943
944
  try expectProbability(&chance.probability, 1, 3);
944
- try expectValue(@as(u4, 1), chance.actions.p1.force_switch);
945
+ try expectValue(1, chance.actions.p1.force_switch);
945
946
 
946
947
  chance.reset();
947
948
 
948
949
  try chance.forceSwitch(.P1, 4, 1);
949
950
  try expectProbability(&chance.probability, 1, 1);
950
- try expectValue(@as(u4, 4), chance.actions.p1.force_switch);
951
+ try expectValue(4, chance.actions.p1.force_switch);
951
952
  }
952
953
 
953
954
  test "Chance.multiHit" {
@@ -955,21 +956,21 @@ test "Chance.multiHit" {
955
956
 
956
957
  try chance.multiHit(.P1, 3);
957
958
  try expectProbability(&chance.probability, 3, 8);
958
- try expectValue(@as(u4, 3), chance.actions.p1.multi_hit);
959
+ try expectValue(3, chance.actions.p1.multi_hit);
959
960
 
960
961
  chance.reset();
961
962
 
962
963
  try chance.multiHit(.P2, 5);
963
964
  try expectProbability(&chance.probability, 1, 8);
964
- try expectValue(@as(u4, 5), chance.actions.p2.multi_hit);
965
+ try expectValue(5, chance.actions.p2.multi_hit);
965
966
  }
966
967
 
967
968
  test "Chance.duration" {
968
969
  var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
969
970
 
970
971
  chance.duration(.sleep, .P1, .P2, 2);
971
- try expectValue(@as(u4, 2), chance.actions.p1.duration);
972
- try expectValue(@as(u3, 1), chance.actions.p2.durations.sleep);
972
+ try expectValue(2, chance.actions.p1.duration);
973
+ try expectValue(1, chance.actions.p2.durations.sleep);
973
974
  }
974
975
 
975
976
  test "Chance.sleep" {
@@ -979,7 +980,7 @@ test "Chance.sleep" {
979
980
  chance.actions.p1.durations.sleep = @intCast(i);
980
981
  try chance.sleep(.P1, 0);
981
982
  try expectProbability(&chance.probability, 1, d);
982
- try expectValue(@as(u3, 0), chance.actions.p1.durations.sleep);
983
+ try expectValue(0, chance.actions.p1.durations.sleep);
983
984
 
984
985
  chance.reset();
985
986
 
@@ -1003,7 +1004,7 @@ test "Chance.confusion" {
1003
1004
  chance.actions.p2.durations.confusion = @intCast(i);
1004
1005
  try chance.confusion(.P2, 0);
1005
1006
  try expectProbability(&chance.probability, 1, d);
1006
- try expectValue(@as(u3, 0), chance.actions.p2.durations.confusion);
1007
+ try expectValue(0, chance.actions.p2.durations.confusion);
1007
1008
  try expectValue(false, chance.actions.p2.durations.thrash);
1008
1009
 
1009
1010
  chance.reset();
@@ -1028,7 +1029,7 @@ test "Chance.confusion" {
1028
1029
  chance.actions.p2.durations.confusion = @intCast(i);
1029
1030
  try chance.confusion(.P2, 0);
1030
1031
  try expectProbability(&chance.probability, 1, d);
1031
- try expectValue(@as(u3, 0), chance.actions.p2.durations.confusion);
1032
+ try expectValue(0, chance.actions.p2.durations.confusion);
1032
1033
  try expectValue(true, chance.actions.p2.durations.thrash);
1033
1034
 
1034
1035
  chance.reset();
@@ -1054,7 +1055,7 @@ test "Chance.disable" {
1054
1055
  chance.actions.p2.durations.disable = @intCast(i);
1055
1056
  try chance.disable(.P2, 0);
1056
1057
  try expectProbability(&chance.probability, 1, d);
1057
- try expectValue(@as(u4, 0), chance.actions.p2.durations.disable);
1058
+ try expectValue(0, chance.actions.p2.durations.disable);
1058
1059
 
1059
1060
  chance.reset();
1060
1061
  }
@@ -1074,7 +1075,7 @@ test "Chance.disable" {
1074
1075
  chance.actions.p2.durations.disable = @intCast(i);
1075
1076
  try chance.disable(.P2, 0);
1076
1077
  try expectProbability(&chance.probability, 1, d);
1077
- try expectValue(@as(u4, 0), chance.actions.p2.durations.disable);
1078
+ try expectValue(0, chance.actions.p2.durations.disable);
1078
1079
 
1079
1080
  chance.reset();
1080
1081
  }
@@ -1099,7 +1100,7 @@ test "Chance.attacking" {
1099
1100
  chance.actions.p2.durations.attacking = @intCast(i);
1100
1101
  try chance.attacking(.P2, 0);
1101
1102
  try expectProbability(&chance.probability, 1, d);
1102
- try expectValue(@as(u3, 0), chance.actions.p2.durations.attacking);
1103
+ try expectValue(0, chance.actions.p2.durations.attacking);
1103
1104
 
1104
1105
  chance.reset();
1105
1106
  }
@@ -1123,7 +1124,7 @@ test "Chance.binding" {
1123
1124
  chance.actions.p2.durations.binding = @intCast(i);
1124
1125
  try chance.binding(.P2, 0);
1125
1126
  try expectProbability(&chance.probability, 1, d);
1126
- try expectValue(@as(u3, 0), chance.actions.p2.durations.binding);
1127
+ try expectValue(0, chance.actions.p2.durations.binding);
1127
1128
 
1128
1129
  chance.reset();
1129
1130
  }
@@ -1147,7 +1148,7 @@ test "Chance.encore" {
1147
1148
  chance.actions.p2.durations.encore = @intCast(i);
1148
1149
  try chance.encore(.P2, 0);
1149
1150
  try expectProbability(&chance.probability, 1, d);
1150
- try expectValue(@as(u3, 0), chance.actions.p2.durations.encore);
1151
+ try expectValue(0, chance.actions.p2.durations.encore);
1151
1152
 
1152
1153
  chance.reset();
1153
1154
  }
@@ -239,7 +239,7 @@ pub const DVs = packed struct(u16) {
239
239
  };
240
240
  const p: u6 = @intCast(1 + ((5 * @as(u8, (dvs.atk & 0b1000) | ((dvs.def & 0b1000)) >> 1 |
241
241
  ((dvs.spe & 0b1000)) >> 2 | ((dvs.spc & 0b1000)) >> 3) + (dvs.spc & 0b0011)) >> 1));
242
- var t = @as(u8, dvs.def & 0b0011) + (@as(u8, dvs.atk & 0b0011) << 2);
242
+ const t = @as(u8, dvs.def & 0b0011) + (@as(u8, dvs.atk & 0b0011) << 2);
243
243
  return .{ .gender = g, .pow = p, .type = Type.hiddenPower(t) };
244
244
  }
245
245
  };
@@ -248,12 +248,12 @@ test DVs {
248
248
  var dvs = DVs.from(.Mewtwo, .{ .def = 13 });
249
249
  try expectEqual(Gender.Unknown, dvs.gender);
250
250
  try expectEqual(Type.Ice, dvs.type);
251
- try expectEqual(@as(u8, 70), dvs.power());
251
+ try expectEqual(70, dvs.power());
252
252
 
253
253
  dvs = DVs.from(.Pikachu, .{ .spc = 14 });
254
254
  try expectEqual(Gender.Male, dvs.gender);
255
255
  try expectEqual(Type.Dark, dvs.type);
256
- try expectEqual(@as(u8, 69), dvs.power());
256
+ try expectEqual(69, dvs.power());
257
257
 
258
258
  dvs = DVs.from(.Cyndaquil, .{ .atk = 1, .def = 3, .spe = 10, .spc = 9 });
259
259
  try expectEqual(Gender.Female, dvs.gender);
@@ -380,9 +380,9 @@ test Stats {
380
380
  try expectEqual(0, stats.def);
381
381
 
382
382
  var base = Species.get(.Gyarados).stats;
383
- try expectEqual(@as(u16, 127), Stats(u16).calc("hp", base.hp, 0, 5120, 38));
383
+ try expectEqual(127, Stats(u16).calc("hp", base.hp, 0, 5120, 38));
384
384
  base = Species.get(.Pidgeot).stats;
385
- try expectEqual(@as(u16, 279), Stats(u16).calc("spe", base.spe, 15, 63001, 100));
385
+ try expectEqual(279, Stats(u16).calc("spe", base.spe, 15, 63001, 100));
386
386
  }
387
387
 
388
388
  pub const Boosts = packed struct(u32) {
@@ -428,8 +428,8 @@ test Move {
428
428
  try expectEqual(Move.Effect.ConfusionChance, move.effect);
429
429
  try expectEqual(rng.Gen12.percent(50), move.accuracy);
430
430
  try expectEqual(rng.Gen12.percent(100), move.chance);
431
- try expectEqual(@as(u8, 5), Move.pp(.DynamicPunch));
432
- try expectEqual(@as(i8, -1), Move.get(.Counter).priority);
431
+ try expectEqual(5, Move.pp(.DynamicPunch));
432
+ try expectEqual(-1, Move.get(.Counter).priority);
433
433
  try expect(!move.effect.isHighCritical());
434
434
  try expect(Move.get(.KarateChop).effect.isHighCritical());
435
435
  try expect(Move.get(.RazorWind).effect.isHighCritical());
@@ -439,7 +439,7 @@ pub const Species = species.Species;
439
439
 
440
440
  test Species {
441
441
  try expectEqual(152, @intFromEnum(Species.Chikorita));
442
- try expectEqual(@as(u8, 100), Species.get(.Celebi).stats.spd);
442
+ try expectEqual(100, Species.get(.Celebi).stats.spd);
443
443
  }
444
444
 
445
445
  pub const Type = types.Type;
@@ -452,7 +452,7 @@ test Types {
452
452
  try expect(!Type.Steel.special());
453
453
  try expect(Type.Dark.special());
454
454
 
455
- try expectEqual(@as(u8, 3), Type.Water.precedence());
455
+ try expectEqual(3, Type.Water.precedence());
456
456
  try expect(Type.Bug.precedence() > Type.Poison.precedence());
457
457
 
458
458
  try expectEqual(Effectiveness.Super, Type.effectiveness(.Ghost, .Psychic));
@@ -7,8 +7,6 @@ const common = @import("../common/data.zig");
7
7
  const data = @import("data.zig");
8
8
  const mechanics = @import("mechanics.zig");
9
9
 
10
- const assert = std.debug.assert;
11
-
12
10
  const Player = common.Player;
13
11
  const Result = common.Result;
14
12
 
@@ -42,7 +40,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
42
40
  var log = options.log;
43
41
 
44
42
  var side = battle.side(player);
45
- var volatiles = &side.active.volatiles;
43
+ const volatiles = &side.active.volatiles;
46
44
 
47
45
  const ident = battle.active(player);
48
46
  const foe_ident = battle.active(player.foe());
@@ -175,7 +173,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
175
173
  if (!skip_pp) _ = decrementPP(side, state.move, state.mslot); // TODO if no pp return
176
174
  // TODO rampage
177
175
  // usedmovetext
178
- try log.move(ident, state.move, foe_ident); // FIXME self? from?
176
+ try log.move(.{ ident, state.move, foe_ident }); // FIXME self? from?
179
177
  try checkHit(battle, player, state, options);
180
178
  try checkCriticalHit(battle, player, state, options);
181
179
  try calcDamage(battle, player, state, options);
@@ -368,7 +366,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
368
366
  (volatiles.BeatUp or volatiles.Thrashing or volatiles.Bide);
369
367
  if (!skip_pp) _ = decrementPP(side, state.move, state.mslot); // TODO if no pp return
370
368
  // usedmovetext
371
- try log.move(ident, state.move, foe_ident); // FIXME self? from?
369
+ try log.move(.{ ident, state.move, foe_ident }); // FIXME self? from?
372
370
  try Effects.bide.unleash(battle, player, state, options);
373
371
 
374
372
  if (state.immune()) {
@@ -555,7 +553,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
555
553
  (volatiles.BeatUp or volatiles.Thrashing or volatiles.Bide);
556
554
  if (!skip_pp) _ = decrementPP(side, state.move, state.mslot); // TODO if no pp return
557
555
  // usedmovetext
558
- try log.move(ident, state.move, foe_ident); // FIXME self? from?
556
+ try log.move(.{ ident, state.move, foe_ident }); // FIXME self? from?
559
557
  try checkCriticalHit(battle, player, state, options);
560
558
  try calcDamage(battle, player, state, options);
561
559
  try adjustDamage(battle, player, state, options);