@pkmn/engine 0.1.0-dev.44b2e6ec → 0.1.0-dev.47dcb76c
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.
- package/LICENSE +1 -3
- package/README.md +1 -1
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +2 -2
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.js.map +1 -1
- package/build/tools/debug.js.map +1 -1
- package/build.zig +50 -53
- package/package.json +27 -20
- package/src/bin/install-pkmn-engine +14 -14
- package/src/lib/common/data.zig +4 -4
- package/src/lib/common/optional.zig +1 -1
- package/src/lib/common/protocol.zig +10 -20
- package/src/lib/common/rng.zig +11 -11
- package/src/lib/gen1/chance.zig +21 -21
- package/src/lib/gen1/data/species.zig +1 -1
- package/src/lib/gen1/data.zig +18 -18
- package/src/lib/gen1/helpers.zig +7 -7
- package/src/lib/gen1/mechanics.zig +41 -5
- package/src/lib/gen2/chance.zig +27 -27
- package/src/lib/gen2/data.zig +8 -8
- package/src/lib/{binding/node.zig → node.zig} +3 -2
- package/src/lib/pkmn.zig +26 -3
- package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
package/src/lib/gen2/chance.zig
CHANGED
|
@@ -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("
|
|
17
|
+
const data = @import("data.zig");
|
|
18
18
|
|
|
19
19
|
const enabled = options.chance;
|
|
20
20
|
const showdown = options.showdown;
|
|
@@ -699,7 +699,7 @@ test "Chance.damage" {
|
|
|
699
699
|
var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
|
|
700
700
|
|
|
701
701
|
try chance.damage(.P1, 217);
|
|
702
|
-
try expectValue(
|
|
702
|
+
try expectValue(217, chance.actions.p1.damage);
|
|
703
703
|
try expectProbability(&chance.probability, 1, 39);
|
|
704
704
|
}
|
|
705
705
|
|
|
@@ -824,7 +824,7 @@ test "Chance.present" {
|
|
|
824
824
|
} else {
|
|
825
825
|
try expectProbability(&chance.probability, 25, 256);
|
|
826
826
|
}
|
|
827
|
-
try expectValue(
|
|
827
|
+
try expectValue(4, chance.actions.p2.present);
|
|
828
828
|
|
|
829
829
|
chance.reset();
|
|
830
830
|
|
|
@@ -834,7 +834,7 @@ test "Chance.present" {
|
|
|
834
834
|
} else {
|
|
835
835
|
try expectProbability(&chance.probability, 51, 256);
|
|
836
836
|
}
|
|
837
|
-
try expectValue(
|
|
837
|
+
try expectValue(1, chance.actions.p1.present);
|
|
838
838
|
}
|
|
839
839
|
|
|
840
840
|
test "Chance.magnitude" {
|
|
@@ -846,7 +846,7 @@ test "Chance.magnitude" {
|
|
|
846
846
|
} else {
|
|
847
847
|
try expectProbability(&chance.probability, 13, 256);
|
|
848
848
|
}
|
|
849
|
-
try expectValue(
|
|
849
|
+
try expectValue(7, chance.actions.p2.magnitude);
|
|
850
850
|
|
|
851
851
|
chance.reset();
|
|
852
852
|
|
|
@@ -856,7 +856,7 @@ test "Chance.magnitude" {
|
|
|
856
856
|
} else {
|
|
857
857
|
try expectProbability(&chance.probability, 51, 256);
|
|
858
858
|
}
|
|
859
|
-
try expectValue(
|
|
859
|
+
try expectValue(5, chance.actions.p1.magnitude);
|
|
860
860
|
}
|
|
861
861
|
|
|
862
862
|
test "Chance.tripleKick" {
|
|
@@ -864,7 +864,7 @@ test "Chance.tripleKick" {
|
|
|
864
864
|
|
|
865
865
|
try chance.tripleKick(.P1, 2);
|
|
866
866
|
try expectProbability(&chance.probability, 1, 3);
|
|
867
|
-
try expectValue(
|
|
867
|
+
try expectValue(2, chance.actions.p1.triple_kick);
|
|
868
868
|
}
|
|
869
869
|
|
|
870
870
|
test "Chance.spite" {
|
|
@@ -872,7 +872,7 @@ test "Chance.spite" {
|
|
|
872
872
|
|
|
873
873
|
try chance.spite(.P1, 3);
|
|
874
874
|
try expectProbability(&chance.probability, 1, 4);
|
|
875
|
-
try expectValue(
|
|
875
|
+
try expectValue(3, chance.actions.p1.spite);
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
test "Chance.conversion2" {
|
|
@@ -899,7 +899,7 @@ test "Chance.psywave" {
|
|
|
899
899
|
|
|
900
900
|
try chance.psywave(.P2, 100, 150);
|
|
901
901
|
try expectProbability(&chance.probability, 1, 150);
|
|
902
|
-
try expectValue(
|
|
902
|
+
try expectValue(100, chance.actions.p2.psywave);
|
|
903
903
|
}
|
|
904
904
|
|
|
905
905
|
test "Chance.metronome" {
|
|
@@ -915,19 +915,19 @@ test "Chance.moveSlot" {
|
|
|
915
915
|
|
|
916
916
|
try chance.moveSlot(.P2, 2, 2);
|
|
917
917
|
try expectProbability(&chance.probability, 1, 2);
|
|
918
|
-
try expectValue(
|
|
918
|
+
try expectValue(2, chance.actions.p2.move_slot);
|
|
919
919
|
|
|
920
920
|
chance.reset();
|
|
921
921
|
|
|
922
922
|
try chance.moveSlot(.P1, 1, 3);
|
|
923
923
|
try expectProbability(&chance.probability, 1, 3);
|
|
924
|
-
try expectValue(
|
|
924
|
+
try expectValue(1, chance.actions.p1.move_slot);
|
|
925
925
|
|
|
926
926
|
chance.reset();
|
|
927
927
|
|
|
928
928
|
try chance.moveSlot(.P1, 4, 1);
|
|
929
929
|
try expectProbability(&chance.probability, 1, 1);
|
|
930
|
-
try expectValue(
|
|
930
|
+
try expectValue(4, chance.actions.p1.move_slot);
|
|
931
931
|
}
|
|
932
932
|
|
|
933
933
|
test "Chance.forceSwitch" {
|
|
@@ -935,19 +935,19 @@ test "Chance.forceSwitch" {
|
|
|
935
935
|
|
|
936
936
|
try chance.forceSwitch(.P2, 2, 2);
|
|
937
937
|
try expectProbability(&chance.probability, 1, 2);
|
|
938
|
-
try expectValue(
|
|
938
|
+
try expectValue(2, chance.actions.p2.force_switch);
|
|
939
939
|
|
|
940
940
|
chance.reset();
|
|
941
941
|
|
|
942
942
|
try chance.forceSwitch(.P1, 1, 3);
|
|
943
943
|
try expectProbability(&chance.probability, 1, 3);
|
|
944
|
-
try expectValue(
|
|
944
|
+
try expectValue(1, chance.actions.p1.force_switch);
|
|
945
945
|
|
|
946
946
|
chance.reset();
|
|
947
947
|
|
|
948
948
|
try chance.forceSwitch(.P1, 4, 1);
|
|
949
949
|
try expectProbability(&chance.probability, 1, 1);
|
|
950
|
-
try expectValue(
|
|
950
|
+
try expectValue(4, chance.actions.p1.force_switch);
|
|
951
951
|
}
|
|
952
952
|
|
|
953
953
|
test "Chance.multiHit" {
|
|
@@ -955,21 +955,21 @@ test "Chance.multiHit" {
|
|
|
955
955
|
|
|
956
956
|
try chance.multiHit(.P1, 3);
|
|
957
957
|
try expectProbability(&chance.probability, 3, 8);
|
|
958
|
-
try expectValue(
|
|
958
|
+
try expectValue(3, chance.actions.p1.multi_hit);
|
|
959
959
|
|
|
960
960
|
chance.reset();
|
|
961
961
|
|
|
962
962
|
try chance.multiHit(.P2, 5);
|
|
963
963
|
try expectProbability(&chance.probability, 1, 8);
|
|
964
|
-
try expectValue(
|
|
964
|
+
try expectValue(5, chance.actions.p2.multi_hit);
|
|
965
965
|
}
|
|
966
966
|
|
|
967
967
|
test "Chance.duration" {
|
|
968
968
|
var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
|
|
969
969
|
|
|
970
970
|
chance.duration(.sleep, .P1, .P2, 2);
|
|
971
|
-
try expectValue(
|
|
972
|
-
try expectValue(
|
|
971
|
+
try expectValue(2, chance.actions.p1.duration);
|
|
972
|
+
try expectValue(1, chance.actions.p2.durations.sleep);
|
|
973
973
|
}
|
|
974
974
|
|
|
975
975
|
test "Chance.sleep" {
|
|
@@ -979,7 +979,7 @@ test "Chance.sleep" {
|
|
|
979
979
|
chance.actions.p1.durations.sleep = @intCast(i);
|
|
980
980
|
try chance.sleep(.P1, 0);
|
|
981
981
|
try expectProbability(&chance.probability, 1, d);
|
|
982
|
-
try expectValue(
|
|
982
|
+
try expectValue(0, chance.actions.p1.durations.sleep);
|
|
983
983
|
|
|
984
984
|
chance.reset();
|
|
985
985
|
|
|
@@ -1003,7 +1003,7 @@ test "Chance.confusion" {
|
|
|
1003
1003
|
chance.actions.p2.durations.confusion = @intCast(i);
|
|
1004
1004
|
try chance.confusion(.P2, 0);
|
|
1005
1005
|
try expectProbability(&chance.probability, 1, d);
|
|
1006
|
-
try expectValue(
|
|
1006
|
+
try expectValue(0, chance.actions.p2.durations.confusion);
|
|
1007
1007
|
try expectValue(false, chance.actions.p2.durations.thrash);
|
|
1008
1008
|
|
|
1009
1009
|
chance.reset();
|
|
@@ -1028,7 +1028,7 @@ test "Chance.confusion" {
|
|
|
1028
1028
|
chance.actions.p2.durations.confusion = @intCast(i);
|
|
1029
1029
|
try chance.confusion(.P2, 0);
|
|
1030
1030
|
try expectProbability(&chance.probability, 1, d);
|
|
1031
|
-
try expectValue(
|
|
1031
|
+
try expectValue(0, chance.actions.p2.durations.confusion);
|
|
1032
1032
|
try expectValue(true, chance.actions.p2.durations.thrash);
|
|
1033
1033
|
|
|
1034
1034
|
chance.reset();
|
|
@@ -1054,7 +1054,7 @@ test "Chance.disable" {
|
|
|
1054
1054
|
chance.actions.p2.durations.disable = @intCast(i);
|
|
1055
1055
|
try chance.disable(.P2, 0);
|
|
1056
1056
|
try expectProbability(&chance.probability, 1, d);
|
|
1057
|
-
try expectValue(
|
|
1057
|
+
try expectValue(0, chance.actions.p2.durations.disable);
|
|
1058
1058
|
|
|
1059
1059
|
chance.reset();
|
|
1060
1060
|
}
|
|
@@ -1074,7 +1074,7 @@ test "Chance.disable" {
|
|
|
1074
1074
|
chance.actions.p2.durations.disable = @intCast(i);
|
|
1075
1075
|
try chance.disable(.P2, 0);
|
|
1076
1076
|
try expectProbability(&chance.probability, 1, d);
|
|
1077
|
-
try expectValue(
|
|
1077
|
+
try expectValue(0, chance.actions.p2.durations.disable);
|
|
1078
1078
|
|
|
1079
1079
|
chance.reset();
|
|
1080
1080
|
}
|
|
@@ -1099,7 +1099,7 @@ test "Chance.attacking" {
|
|
|
1099
1099
|
chance.actions.p2.durations.attacking = @intCast(i);
|
|
1100
1100
|
try chance.attacking(.P2, 0);
|
|
1101
1101
|
try expectProbability(&chance.probability, 1, d);
|
|
1102
|
-
try expectValue(
|
|
1102
|
+
try expectValue(0, chance.actions.p2.durations.attacking);
|
|
1103
1103
|
|
|
1104
1104
|
chance.reset();
|
|
1105
1105
|
}
|
|
@@ -1123,7 +1123,7 @@ test "Chance.binding" {
|
|
|
1123
1123
|
chance.actions.p2.durations.binding = @intCast(i);
|
|
1124
1124
|
try chance.binding(.P2, 0);
|
|
1125
1125
|
try expectProbability(&chance.probability, 1, d);
|
|
1126
|
-
try expectValue(
|
|
1126
|
+
try expectValue(0, chance.actions.p2.durations.binding);
|
|
1127
1127
|
|
|
1128
1128
|
chance.reset();
|
|
1129
1129
|
}
|
|
@@ -1147,7 +1147,7 @@ test "Chance.encore" {
|
|
|
1147
1147
|
chance.actions.p2.durations.encore = @intCast(i);
|
|
1148
1148
|
try chance.encore(.P2, 0);
|
|
1149
1149
|
try expectProbability(&chance.probability, 1, d);
|
|
1150
|
-
try expectValue(
|
|
1150
|
+
try expectValue(0, chance.actions.p2.durations.encore);
|
|
1151
1151
|
|
|
1152
1152
|
chance.reset();
|
|
1153
1153
|
}
|
package/src/lib/gen2/data.zig
CHANGED
|
@@ -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(
|
|
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(
|
|
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(
|
|
383
|
+
try expectEqual(127, Stats(u16).calc("hp", base.hp, 0, 5120, 38));
|
|
384
384
|
base = Species.get(.Pidgeot).stats;
|
|
385
|
-
try expectEqual(
|
|
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(
|
|
432
|
-
try expectEqual(
|
|
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(
|
|
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(
|
|
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));
|
package/src/lib/pkmn.zig
CHANGED
|
@@ -91,7 +91,7 @@ pub const gen1 = struct {
|
|
|
91
91
|
/// battle `update`.
|
|
92
92
|
pub const Summaries = @import("gen1/calc.zig").Summaries;
|
|
93
93
|
/// Information relevant to damage calculation that occured during a Generation I
|
|
94
|
-
///
|
|
94
|
+
/// battle `update` for a single player.
|
|
95
95
|
pub const Summary = @import("gen1/calc.zig").Summary;
|
|
96
96
|
/// Null object pattern implementation of Generation I `Calc` which does nothing,
|
|
97
97
|
/// though damage calculator support should additionally be turned off
|
|
@@ -102,12 +102,35 @@ pub const gen1 = struct {
|
|
|
102
102
|
pub const helpers = @import("gen1/helpers.zig");
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
+
/// TODO
|
|
106
|
+
pub const gen2 = struct {
|
|
107
|
+
pub usingnamespace @import("gen2/data.zig");
|
|
108
|
+
pub const Chance = @import("gen2/chance.zig").Chance;
|
|
109
|
+
pub const chance = struct {
|
|
110
|
+
pub const Actions = @import("gen2/chance.zig").Actions;
|
|
111
|
+
pub const Action = @import("gen2/chance.zig").Action;
|
|
112
|
+
pub const Durations = @import("gen2/chance.zig").Durations;
|
|
113
|
+
pub const Duration = @import("gen2/chance.zig").Duration;
|
|
114
|
+
pub const NULL = @import("gen2/chance.zig").NULL;
|
|
115
|
+
};
|
|
116
|
+
pub const Calc = @import("gen2/calc.zig").Calc;
|
|
117
|
+
pub const calc = if (options.internal) struct {
|
|
118
|
+
pub usingnamespace @import("gen2/calc.zig");
|
|
119
|
+
} else struct {
|
|
120
|
+
pub const Overrides = @import("gen2/calc.zig").Overrides;
|
|
121
|
+
pub const Summaries = @import("gen2/calc.zig").Summaries;
|
|
122
|
+
pub const Summary = @import("gen2/calc.zig").Summary;
|
|
123
|
+
pub const NULL = @import("gen2/calc.zig").NULL;
|
|
124
|
+
};
|
|
125
|
+
pub const helpers = @import("gen2/helpers.zig");
|
|
126
|
+
};
|
|
127
|
+
|
|
105
128
|
// Internal APIs used by other pkmn libraries, not actually part of the public API.
|
|
106
129
|
// NOTE: `pub usingnamespace struct { ... }` here results in a (false?) dependency loop
|
|
107
130
|
pub const js = if (options.internal) struct {
|
|
108
131
|
pub usingnamespace @import("common/js.zig");
|
|
109
132
|
} else struct {};
|
|
110
133
|
pub const bindings = if (options.internal) struct {
|
|
111
|
-
pub const node = @import("
|
|
112
|
-
pub const wasm = @import("
|
|
134
|
+
pub const node = @import("node.zig");
|
|
135
|
+
pub const wasm = @import("wasm.zig");
|
|
113
136
|
} else struct {};
|