@pkmn/engine 0.1.0-dev.f3aaee39 → 0.1.0-dev.f918c3bd
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/build/pkg/data/protocol.json +69 -12
- package/build/pkg/protocol.js +56 -37
- package/build/pkg/protocol.js.map +1 -1
- package/build.zig +2 -2
- package/package.json +20 -11
- package/src/lib/binding/node.zig +1 -1
- package/src/lib/common/data.zig +4 -16
- package/src/lib/common/protocol.zig +514 -66
- package/src/lib/common/rational.zig +1 -1
- package/src/lib/common/rng.zig +6 -6
- package/src/lib/gen1/README.md +3 -1
- package/src/lib/gen1/calc.zig +2 -3
- package/src/lib/gen1/chance.zig +26 -12
- package/src/lib/gen1/data/moves.zig +168 -170
- package/src/lib/gen1/data/types.zig +1 -1
- package/src/lib/gen1/data.zig +11 -23
- package/src/lib/gen1/helpers.zig +12 -12
- package/src/lib/gen1/mechanics.zig +32 -36
- package/src/lib/gen2/README.md +90 -70
- package/src/lib/gen2/data/moves.zig +634 -562
- package/src/lib/gen2/data/types.zig +1 -1
- package/src/lib/gen2/data.zig +74 -52
- package/src/lib/gen2/helpers.zig +8 -12
- package/src/lib/gen2/mechanics.zig +1142 -7
|
@@ -275,7 +275,7 @@ pub const BigRational = struct {
|
|
|
275
275
|
/// Create a new BigRational wrapper. A small amount of memory will be allocated on
|
|
276
276
|
/// initialization. Not default initialized to 1 - you must explicitly `reset` first.
|
|
277
277
|
pub fn init(alloc: std.mem.Allocator) !BigRational {
|
|
278
|
-
return
|
|
278
|
+
return .{ .val = try std.math.big.Rational.init(alloc) };
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
/// Frees all memory associated with a rational.
|
package/src/lib/common/rng.zig
CHANGED
|
@@ -64,7 +64,7 @@ pub const PSRNG = extern struct {
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
test PSRNG {
|
|
67
|
-
var psrng =
|
|
67
|
+
var psrng: PSRNG = .{ .src = .{ .seed = 0x0001000200030004 } };
|
|
68
68
|
try expectEqual(@as(u8, 121), psrng.range(u8, 0, 256));
|
|
69
69
|
try expectEqual(false, psrng.chance(u8, 128, 256)); // 226 < 128
|
|
70
70
|
}
|
|
@@ -79,7 +79,7 @@ pub const Gen12 = extern struct {
|
|
|
79
79
|
assert(@sizeOf(Gen12) == 10);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
pub fn percent(p:
|
|
82
|
+
pub fn percent(comptime p: comptime_int) u8 {
|
|
83
83
|
return @intCast((@as(u16, p) * 0xFF) / 100);
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -93,7 +93,7 @@ pub const Gen12 = extern struct {
|
|
|
93
93
|
|
|
94
94
|
test Gen12 {
|
|
95
95
|
const expected = [_]u8{ 6, 11, 16, 21, 26, 31, 36, 41, 46, 31, 56, 81 };
|
|
96
|
-
var rng =
|
|
96
|
+
var rng: Gen12 = .{ .seed = .{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } };
|
|
97
97
|
for (expected) |e| {
|
|
98
98
|
try expectEqual(e, rng.next());
|
|
99
99
|
}
|
|
@@ -129,7 +129,7 @@ test Gen34 {
|
|
|
129
129
|
.{ 0x80000000, 5, 0x0E425287 }, .{ 0x80000000, 10, 0x6F2CF4B2 },
|
|
130
130
|
};
|
|
131
131
|
for (data) |d| {
|
|
132
|
-
var rng =
|
|
132
|
+
var rng: Gen34 = .{ .seed = d[0] };
|
|
133
133
|
for (0..d[1]) |_| _ = rng.next();
|
|
134
134
|
try expectEqual(d[2], rng.seed);
|
|
135
135
|
}
|
|
@@ -161,7 +161,7 @@ test Gen56 {
|
|
|
161
161
|
.{ 0x8000000000000000, 10, 0xE7795501267F125A },
|
|
162
162
|
};
|
|
163
163
|
for (data) |d| {
|
|
164
|
-
var rng =
|
|
164
|
+
var rng: Gen56 = .{ .seed = d[0] };
|
|
165
165
|
for (0..d[1]) |_| _ = rng.next();
|
|
166
166
|
try expectEqual(d[2], rng.seed);
|
|
167
167
|
}
|
|
@@ -213,7 +213,7 @@ pub fn FixedRNG(comptime gen: comptime_int, comptime len: usize) type {
|
|
|
213
213
|
test FixedRNG {
|
|
214
214
|
const Type = if (showdown) u32 else u8;
|
|
215
215
|
const expected = [_]Type{ 42, 255, 0 };
|
|
216
|
-
var rng
|
|
216
|
+
var rng: FixedRNG(1, expected.len) = .{ .rolls = expected };
|
|
217
217
|
for (expected) |e| {
|
|
218
218
|
try expectEqual(e, rng.next());
|
|
219
219
|
}
|
package/src/lib/gen1/README.md
CHANGED
|
@@ -612,7 +612,8 @@ engine, but the following moves have their broken behavior preserved in `-Dshowd
|
|
|
612
612
|
- **Roar** / **Whirlwind**: these moves can miss on Pokémon Showdown (and advance the RNG when
|
|
613
613
|
checking) which is incorrect (these moves should always fail, but don't check accuracy or advance
|
|
614
614
|
the RNG). More importantly, these moves should *not* cause the tracked last battle damage to be
|
|
615
|
-
zeroed, but on Pokémon Showdown they do.
|
|
615
|
+
zeroed, but on Pokémon Showdown they do. These should also `|-fail|...|[still]` instead of doing
|
|
616
|
+
nothing.
|
|
616
617
|
- **Substitute**: in addition to the [Substitute + Confusion
|
|
617
618
|
glitch](https://pkmn.cc/bulba-glitch-1#Substitute_.2B_Confusion_glitch) not being implemented
|
|
618
619
|
correctly (covered earlier), the [Substitute 1/4
|
|
@@ -634,6 +635,7 @@ only pedantic UI correctness):
|
|
|
634
635
|
|
|
635
636
|
- **Rage**: Rage should report the `|-boost|` before the Disable `|-miss|`, not after.
|
|
636
637
|
- **Haze**: Haze clears the status/volatiles in an incorrect order.
|
|
638
|
+
- **Teleport**: Teleport should `|-fail|...|[still]` instead of doing nothing.
|
|
637
639
|
- **Twineedle**: the `|-hitcount|` ("Hit 2 times") should come before the `|-status|` message, not
|
|
638
640
|
after.
|
|
639
641
|
- **Thrash** / **Petal Dance**: confusion should silently get applied before the `|move|` message,
|
package/src/lib/gen1/calc.zig
CHANGED
|
@@ -29,7 +29,6 @@ const Optional = optional.Optional;
|
|
|
29
29
|
const Rational = rational.Rational;
|
|
30
30
|
|
|
31
31
|
const PointerType = util.PointerType;
|
|
32
|
-
const FieldType = util.FieldType;
|
|
33
32
|
|
|
34
33
|
const Actions = chance.Actions;
|
|
35
34
|
const Action = chance.Action;
|
|
@@ -158,7 +157,7 @@ pub const Calc = struct {
|
|
|
158
157
|
|
|
159
158
|
/// Null object pattern implementation of Generation I `Calc` which does nothing, though damage
|
|
160
159
|
/// calculator support should additionally be turned off entirely via `options.calc`.
|
|
161
|
-
pub const NULL =
|
|
160
|
+
pub const NULL: Null = .{};
|
|
162
161
|
|
|
163
162
|
const Null = struct {
|
|
164
163
|
pub fn overridden(
|
|
@@ -256,7 +255,7 @@ pub fn transitions(
|
|
|
256
255
|
|
|
257
256
|
try debug(writer, template, true, .{ .color = i, .bold = true, .background = true });
|
|
258
257
|
|
|
259
|
-
var a =
|
|
258
|
+
var a: Actions = .{ .p1 = .{ .metronome = p1_move }, .p2 = .{ .metronome = p2_move } };
|
|
260
259
|
|
|
261
260
|
for (Rolls.speedTie(template.p1)) |tie| { a.p1.speed_tie = tie; a.p2.speed_tie = tie;
|
|
262
261
|
for (Rolls.sleep(template.p1, actions.p1)) |p1_slp| { a.p1.durations.sleep = p1_slp;
|
package/src/lib/gen1/chance.zig
CHANGED
|
@@ -115,7 +115,7 @@ test Actions {
|
|
|
115
115
|
|
|
116
116
|
/// Information about the RNG that was observed during a Generation I battle `update` for a
|
|
117
117
|
/// single player.
|
|
118
|
-
pub const Action = packed struct {
|
|
118
|
+
pub const Action = packed struct(u64) {
|
|
119
119
|
/// If not 0, the roll to be returned Rolls.damage.
|
|
120
120
|
damage: u8 = 0,
|
|
121
121
|
|
|
@@ -156,10 +156,6 @@ pub const Action = packed struct {
|
|
|
156
156
|
|
|
157
157
|
pub const Field = std.meta.FieldEnum(Action);
|
|
158
158
|
|
|
159
|
-
comptime {
|
|
160
|
-
assert(@sizeOf(Action) == 8);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
159
|
/// Perform a reset by clearing fields which should not persist across updates.
|
|
164
160
|
pub inline fn reset(self: *Action) void {
|
|
165
161
|
self.* = @bitCast(@as(u64, @bitCast(self.*)) & DURATIONS);
|
|
@@ -219,7 +215,7 @@ pub const Action = packed struct {
|
|
|
219
215
|
};
|
|
220
216
|
|
|
221
217
|
test Action {
|
|
222
|
-
var a =
|
|
218
|
+
var a: Action = .{ .hit = .true, .durations = .{ .sleep = 3 }, .damage = 225 };
|
|
223
219
|
a.reset();
|
|
224
220
|
|
|
225
221
|
try expectEqual(Action{ .hit = .None, .durations = .{ .sleep = 3 }, .damage = 0 }, a);
|
|
@@ -239,7 +235,7 @@ pub const Durations = extern struct {
|
|
|
239
235
|
|
|
240
236
|
/// Observed values for various durations that need to be tracked in order to properly
|
|
241
237
|
/// deduplicate transitions with a primary key. TODO
|
|
242
|
-
pub const Duration = packed struct {
|
|
238
|
+
pub const Duration = packed struct(u16) {
|
|
243
239
|
/// The number of turns a Pokémon has been observed to be sleeping.
|
|
244
240
|
sleep: u3 = 0,
|
|
245
241
|
/// The number of turns a Pokémon has been observed to be confused.
|
|
@@ -252,10 +248,6 @@ pub const Duration = packed struct {
|
|
|
252
248
|
binding: u3 = 0,
|
|
253
249
|
|
|
254
250
|
pub const Field = std.meta.FieldEnum(Duration);
|
|
255
|
-
|
|
256
|
-
comptime {
|
|
257
|
-
assert(@sizeOf(Duration) == 2);
|
|
258
|
-
}
|
|
259
251
|
};
|
|
260
252
|
|
|
261
253
|
pub const Commit = enum { hit, miss, binding };
|
|
@@ -840,6 +832,28 @@ test "Chance.sleep" {
|
|
|
840
832
|
}
|
|
841
833
|
}
|
|
842
834
|
|
|
835
|
+
test "Chance.disable" {
|
|
836
|
+
var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
|
|
837
|
+
|
|
838
|
+
for ([_]u8{ 8, 7, 6, 5, 4, 3, 2, 1 }, 1..9) |d, i| {
|
|
839
|
+
chance.actions.p1.durations.disable = @intCast(i);
|
|
840
|
+
try chance.disable(.P1, 0);
|
|
841
|
+
try expectProbability(&chance.probability, 1, d);
|
|
842
|
+
try expectValue(@as(u4, 0), chance.actions.p1.durations.disable);
|
|
843
|
+
|
|
844
|
+
chance.reset();
|
|
845
|
+
|
|
846
|
+
if (i < 8) {
|
|
847
|
+
chance.actions.p1.durations.disable = @intCast(i);
|
|
848
|
+
try chance.disable(.P1, 1);
|
|
849
|
+
try expectProbability(&chance.probability, d - 1, d);
|
|
850
|
+
try expectValue(@as(u4, @intCast(i)) + 1, chance.actions.p1.durations.disable);
|
|
851
|
+
|
|
852
|
+
chance.reset();
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
843
857
|
test "Chance.confusion" {
|
|
844
858
|
var chance: Chance(rational.Rational(u64)) = .{ .probability = .{} };
|
|
845
859
|
|
|
@@ -947,7 +961,7 @@ pub fn expectValue(a: anytype, b: anytype) !void {
|
|
|
947
961
|
|
|
948
962
|
/// Null object pattern implementation of Generation I `Chance` which does nothing, though chance
|
|
949
963
|
/// tracking should additionally be turned off entirely via `options.chance`.
|
|
950
|
-
pub const NULL =
|
|
964
|
+
pub const NULL: Null = .{};
|
|
951
965
|
|
|
952
966
|
const Null = struct {
|
|
953
967
|
pub const Error = error{};
|