@pkmn/engine 0.1.0-dev.84cc1a02 → 0.1.0-dev.93b7cb0d
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/README.md +50 -22
- package/build/pkg/addon.d.ts +7 -0
- package/build/pkg/addon.js +111 -0
- package/build/pkg/addon.js.map +1 -0
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/data.d.ts +1 -2
- package/build/pkg/data.js +3 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +5 -4
- package/build/pkg/gen1.js +43 -24
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +15 -12
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +4 -2
- package/build/pkg/protocol.js +4 -2
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +400 -0
- package/build/test/display.js.map +1 -0
- package/build/tools/debug.js +133 -0
- package/build/tools/debug.js.map +1 -0
- package/build.zig +27 -35
- package/package.json +40 -29
- package/src/bin/install-pkmn-engine +47 -28
- package/src/bin/pkmn-debug +62 -0
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +1 -0
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +104 -70
- package/src/lib/gen1/data.zig +19 -17
- package/src/lib/gen1/helpers.zig +4 -15
- package/src/lib/gen1/mechanics.zig +399 -306
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
- package/src/test/display/pkmn.html.tmpl +368 -0
package/src/lib/gen1/data.zig
CHANGED
|
@@ -17,16 +17,16 @@ const expectEqual = std.testing.expectEqual;
|
|
|
17
17
|
const expect = std.testing.expect;
|
|
18
18
|
|
|
19
19
|
/// The minimum size in bytes required to hold all Generation I choice options.
|
|
20
|
-
pub const
|
|
20
|
+
pub const MAX_CHOICES: usize = 9; // move 1..4, switch 2..6
|
|
21
21
|
/// The optimal size in bytes required to hold all Generation I choice options.
|
|
22
|
-
/// At least as large as
|
|
22
|
+
/// At least as large as MAX_CHOICES.
|
|
23
23
|
pub const MAX_LOGS: usize = 180;
|
|
24
24
|
|
|
25
25
|
/// The maximum number of bytes possibly logged by a single Generation I update.
|
|
26
|
-
pub const
|
|
27
|
-
|
|
26
|
+
pub const CHOICES_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
27
|
+
MAX_CHOICES
|
|
28
28
|
else
|
|
29
|
-
std.math.ceilPowerOfTwo(usize,
|
|
29
|
+
std.math.ceilPowerOfTwo(usize, MAX_CHOICES) catch unreachable;
|
|
30
30
|
/// The optimal size in bytes required to hold the largest amount of log data possible from a
|
|
31
31
|
/// single Generation I update. At least as large as MAX_LOGS.
|
|
32
32
|
pub const LOGS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
@@ -55,8 +55,8 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
55
55
|
turn: u16 = 0,
|
|
56
56
|
/// The last damage dealt by either side.
|
|
57
57
|
last_damage: u16 = 0,
|
|
58
|
-
///
|
|
59
|
-
|
|
58
|
+
/// Details about the last move selected/used by each player required to detect desyncs.
|
|
59
|
+
last_moves: MoveDetails = .{},
|
|
60
60
|
/// The pseudo random number generator.
|
|
61
61
|
rng: RNG,
|
|
62
62
|
|
|
@@ -76,7 +76,7 @@ pub fn Battle(comptime RNG: anytype) type {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/// Returns the result of applying Player 1's choice `c1` and Player 2's choice `c2` to the
|
|
79
|
-
/// battle, optionally writing protocol logs to `log` if `options.
|
|
79
|
+
/// battle, optionally writing protocol message logs to `log` if `options.log` is enabled.
|
|
80
80
|
pub fn update(self: *Self, c1: Choice, c2: Choice, log: anytype) !Result {
|
|
81
81
|
return mechanics.update(self, c1, c2, log);
|
|
82
82
|
}
|
|
@@ -201,17 +201,19 @@ pub const MoveSlot = extern struct {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
///
|
|
207
|
-
|
|
208
|
-
/// Player 1
|
|
209
|
-
|
|
210
|
-
///
|
|
211
|
-
|
|
204
|
+
/// Details required to detect desyncs based on the move last selected/executed by players.
|
|
205
|
+
pub const MoveDetails = packed struct {
|
|
206
|
+
/// The move slot index of the last move selected in the battle menu by Player 1
|
|
207
|
+
p1_index: if (showdown) u8 else u3 = 0,
|
|
208
|
+
/// Whether the last move executed by Player 1 was counterable.
|
|
209
|
+
p1_counterable: if (showdown) u8 else u1 = 0,
|
|
210
|
+
/// The move slot index of the last move selected in the battle menu by Player 2
|
|
211
|
+
p2_index: if (showdown) u8 else u3 = 0,
|
|
212
|
+
/// Whether the last move executed by Player 2 was counterable.
|
|
213
|
+
p2_counterable: if (showdown) u8 else u1 = 0,
|
|
212
214
|
|
|
213
215
|
comptime {
|
|
214
|
-
assert(@sizeOf(
|
|
216
|
+
assert(@sizeOf(MoveDetails) == if (showdown) 4 else 1);
|
|
215
217
|
}
|
|
216
218
|
};
|
|
217
219
|
|
package/src/lib/gen1/helpers.zig
CHANGED
|
@@ -55,21 +55,16 @@ pub const Battle = struct {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
pub fn random(rand: *PSRNG, opt: Options) data.Battle(data.PRNG) {
|
|
58
|
-
|
|
59
|
-
var p2: u4 = 0;
|
|
60
|
-
var battle: data.Battle(data.PRNG) = .{
|
|
58
|
+
return .{
|
|
61
59
|
.rng = prng(rand),
|
|
62
60
|
.turn = 0,
|
|
63
61
|
.last_damage = 0,
|
|
64
62
|
.sides = .{ Side.random(rand, opt), Side.random(rand, opt) },
|
|
65
63
|
};
|
|
66
|
-
battle.last_selected_indexes.p1 = p1;
|
|
67
|
-
battle.last_selected_indexes.p2 = p2;
|
|
68
|
-
return battle;
|
|
69
64
|
}
|
|
70
65
|
};
|
|
71
66
|
|
|
72
|
-
|
|
67
|
+
fn prng(rand: *PSRNG) data.PRNG {
|
|
73
68
|
// GLITCH: initial bytes in seed can only range from 0-252, not 0-255
|
|
74
69
|
const max: u8 = 253;
|
|
75
70
|
return .{
|
|
@@ -211,16 +206,10 @@ pub const Pokemon = struct {
|
|
|
211
206
|
}
|
|
212
207
|
};
|
|
213
208
|
|
|
214
|
-
// cat src/test/showdown/blocklist.json | jq '."1".moves'
|
|
215
209
|
fn blocked(m: Move) bool {
|
|
216
|
-
|
|
210
|
+
// Binding moves are borked but only via Mirror Move / Metronome which are already blocked
|
|
217
211
|
return switch (m) {
|
|
218
|
-
.
|
|
219
|
-
.Mimic,
|
|
220
|
-
.Metronome,
|
|
221
|
-
.MirrorMove,
|
|
222
|
-
.Transform,
|
|
223
|
-
=> true,
|
|
212
|
+
.Mimic, .Metronome, .MirrorMove, .Transform => true,
|
|
224
213
|
else => false,
|
|
225
214
|
};
|
|
226
215
|
}
|