@pkmn/engine 0.1.0-dev.a5a9f4b2 → 0.1.0-dev.b9fb6eab
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 +9 -37
- package/build/pkg/data.d.ts +2 -1
- package/build/pkg/data.js +5 -3
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +1 -1
- package/build.zig +15 -10
- package/package.json +28 -38
- package/src/bin/install-pkmn-engine +1 -1
- package/src/lib/binding/node.zig +4 -4
- package/src/lib/binding/wasm.zig +2 -2
- package/src/lib/gen1/README.md +5 -16
- package/src/lib/gen1/data.zig +5 -5
- package/src/lib/gen1/mechanics.zig +242 -247
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +3 -3
- package/build/pkg/addon.d.ts +0 -7
- package/build/pkg/addon.js +0 -111
- package/build/pkg/addon.js.map +0 -1
- package/build/test/display.js +0 -383
- package/build/test/display.js.map +0 -1
- package/build/tools/debug.js +0 -133
- package/build/tools/debug.js.map +0 -1
- package/src/bin/pkmn-debug +0 -62
- package/src/test/display/pkmn.html.tmpl +0 -368
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ $ zig build --prefix /usr/local -Doptimize=ReleaseFast
|
|
|
50
50
|
|
|
51
51
|
The Zig website has [installation instructions](https://ziglang.org/learn/getting-started/) which
|
|
52
52
|
walk through how to install Zig on each platform - the engine code should work on Zig v0.11.0 dev
|
|
53
|
-
build
|
|
53
|
+
build 2168 or greater, though tracks Zig's master branch so this may change in the future if
|
|
54
54
|
breaking language changes are introduced:
|
|
55
55
|
|
|
56
56
|
`libpkmn` can be built with `-Dshowdown` to instead produce the Pokémon Showdown compatible
|
|
@@ -121,7 +121,7 @@ for each player.
|
|
|
121
121
|
Unlike [Pokémon Showdown's
|
|
122
122
|
SIM-PROTOCOL](https://github.com/smogon/pokemon-showdown/blob/master/sim/SIM-PROTOCOL.md#choice-requests)
|
|
123
123
|
which provides a rich request object at each decision point, the pkmn engine computes the possible
|
|
124
|
-
choices on demand based on the result of the previous `update` and the battle state (`
|
|
124
|
+
choices on demand based on the result of the previous `update` and the battle state (`OPTIONS_SIZE`
|
|
125
125
|
is a good size to initialize the buffer passed to `choices`). **Attempting to update the battle with
|
|
126
126
|
a choice not present in the options returned by `choices` is undefined behavior and may corrupt
|
|
127
127
|
state or cause the engine to crash.**
|
|
@@ -216,7 +216,7 @@ const std = @import("std");
|
|
|
216
216
|
const pkmn = @import("pkmn");
|
|
217
217
|
|
|
218
218
|
var random = std.rand.DefaultPrng.init(seed).random();
|
|
219
|
-
var
|
|
219
|
+
var options: [pkmn.OPTIONS_SIZE]pkmn.Choice = undefined;
|
|
220
220
|
|
|
221
221
|
var battle = ...
|
|
222
222
|
var log = ...
|
|
@@ -226,8 +226,8 @@ var c2 = pkmn.Choice{};
|
|
|
226
226
|
|
|
227
227
|
var result = try battle.update(c1, c2, log);
|
|
228
228
|
while (result.type == .None) : (result = try battle.update(c1, c2, log)) {
|
|
229
|
-
c1 =
|
|
230
|
-
c2 =
|
|
229
|
+
c1 = options[random.uintLessThan(u8, battle.choices(.P1, result.p1, &options))];
|
|
230
|
+
c2 = options[random.uintLessThan(u8, battle.choices(.P2, result.p2, &options))];
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
std.debug.print("{}\n", .{result.type});
|
|
@@ -250,38 +250,10 @@ following is a list of known `libpkmn` bindings written by developers outside of
|
|
|
250
250
|
organization](https://github.com/pkmn) that may be helpful (though note that these projects may not
|
|
251
251
|
necessarily be up-to-date/complete/correct - inclusion in this list does not imply endorsement):
|
|
252
252
|
|
|
253
|
-
| Language | License | URL
|
|
254
|
-
| ---------- | --------- |
|
|
255
|
-
| **C++** | `BSL-1.0` | https://github.com/pasyg/
|
|
256
|
-
| **Python** | `MIT` | https://github.com/AnnikaCodes/PyKMN
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
#### `pkmn-debug`
|
|
260
|
-
|
|
261
|
-
The [`@pkmn/engine`](#pkmnengine) package ships with a `pkmn-debug` tool which exists to decode the
|
|
262
|
-
binary data structures and protocols used by the engine and to output a [standalone
|
|
263
|
-
webpage](https://pkmn.cc/debug.html) that can be used for debugging. To use this tool in a folder
|
|
264
|
-
that has the `@pkmn/engine` package installed locally you can use `npx pkmn-debug`, though you may
|
|
265
|
-
also wish to install the package globally to be able to use this tool anywhere without
|
|
266
|
-
[`npx`](https://docs.npmjs.com/cli/v7/commands/npx):
|
|
267
|
-
|
|
268
|
-
```sh
|
|
269
|
-
$ npm install --global @pkmn/engine
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
By default, `pkmn-debug` expects to read [binary debug protocol](docs/PROTOCOL.md#debugging) from
|
|
273
|
-
[standard input](https://en.wikipedia.org/wiki/Standard_streams) and output HTML to standard output:
|
|
274
|
-
|
|
275
|
-
```sh
|
|
276
|
-
$ <cmd> | pkmn-debug > index.html
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
Alternatively, if a single filename argument is passed to the `pkmn-debug` it will read from that
|
|
280
|
-
instead:
|
|
281
|
-
|
|
282
|
-
```sh
|
|
283
|
-
$ pkmn-debug <file> > index.html
|
|
284
|
-
```
|
|
253
|
+
| Language | License | URL |
|
|
254
|
+
| ---------- | --------- | --------------------------------------- |
|
|
255
|
+
| **C++** | `BSL-1.0` | https://github.com/pasyg/engine-wrapper |
|
|
256
|
+
| **Python** | `MIT` | https://github.com/AnnikaCodes/PyKMN |
|
|
285
257
|
|
|
286
258
|
## Status
|
|
287
259
|
|
package/build/pkg/data.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export declare const LAYOUT: {
|
|
|
26
26
|
};
|
|
27
27
|
}[];
|
|
28
28
|
export declare const Data: {
|
|
29
|
-
|
|
29
|
+
buffer(data: number[]): Buffer;
|
|
30
|
+
view(data: number[]): DataView;
|
|
30
31
|
};
|
|
31
32
|
/**
|
|
32
33
|
* Translation table for encoding/decoding Pokémon Showdown string identifiers
|
package/build/pkg/data.js
CHANGED
|
@@ -27,9 +27,11 @@ for (const gen of exports.LAYOUT) {
|
|
|
27
27
|
gen.offsets.Battle.p2 = gen.offsets.Battle.sides + gen.sizes.Side;
|
|
28
28
|
}
|
|
29
29
|
exports.Data = new class {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
buffer(data) {
|
|
31
|
+
return Buffer.from(new Uint8Array(data).buffer);
|
|
32
|
+
}
|
|
33
|
+
view(data) {
|
|
34
|
+
return new DataView(this.buffer(data).buffer);
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
37
|
const LOOKUPS = [];
|
package/build/pkg/data.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/pkg/data.ts"],"names":[],"mappings":";;;;;;AAEA,+DAAsC;AACtC,qEAA6C;AAC7C,yEAAgD;AAEnC,QAAA,EAAE,GAAG,CAAC,GAAG,EAAE;IACtB,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC,EAAE,CAAC;AAOQ,QAAA,GAAG,GAAG,kBAAc,CAAC;AAErB,QAAA,QAAQ,GAA+C,EAAE,CAAC;AACvE,KAAK,MAAM,IAAI,IAAI,uBAAY,EAAE;IAC/B,gBAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,IAAI,IAAI,uBAAY,CAAC,IAAiC,CAAC,EAAE;QAClE,gBAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;KAC5B;CACF;AAEY,QA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;;OAGG;IACH,SAAS,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,EAAkB;QACzB,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AArHD,wBAqHC"}
|
package/build/pkg/gen1.js
CHANGED
|
@@ -50,7 +50,7 @@ class Battle {
|
|
|
50
50
|
this.config = config;
|
|
51
51
|
this.lookup = lookup;
|
|
52
52
|
this.data = data;
|
|
53
|
-
this.options = new ArrayBuffer(addon.size(0, '
|
|
53
|
+
this.options = new ArrayBuffer(addon.size(0, 'options'));
|
|
54
54
|
this.buf = config.log ? new ArrayBuffer(addon.size(0, 'log')) : undefined;
|
|
55
55
|
this.log = config.log ? new DataView(this.buf) : undefined;
|
|
56
56
|
this.cache = [undefined, undefined];
|
package/build.zig
CHANGED
|
@@ -27,7 +27,6 @@ pub fn build(b: *std.Build) !void {
|
|
|
27
27
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
28
28
|
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
|
|
29
29
|
const pic = b.option(bool, "pic", "Force position independent code") orelse false;
|
|
30
|
-
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
31
30
|
|
|
32
31
|
const cmd = b.findProgram(&.{"strip"}, &.{}) catch null;
|
|
33
32
|
|
|
@@ -80,7 +79,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
80
79
|
//
|
|
81
80
|
// But ziglang/zig#14647 broke this so we now need to do an install() and then manually
|
|
82
81
|
// rename the file ourself in install-pkmn-engine
|
|
83
|
-
|
|
82
|
+
lib.install();
|
|
84
83
|
} else if (wasm) {
|
|
85
84
|
const lib = b.addSharedLibrary(.{
|
|
86
85
|
.name = name,
|
|
@@ -106,7 +105,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
106
105
|
sh.addFileSourceArg(.{ .path = out });
|
|
107
106
|
b.getInstallStep().dependOn(&sh.step);
|
|
108
107
|
}
|
|
109
|
-
|
|
108
|
+
lib.install();
|
|
110
109
|
} else if (dynamic) {
|
|
111
110
|
const lib = b.addSharedLibrary(.{
|
|
112
111
|
.name = name,
|
|
@@ -120,7 +119,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
120
119
|
lib.addIncludePath("src/include");
|
|
121
120
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
122
121
|
if (pic) lib.force_pic = pic;
|
|
123
|
-
|
|
122
|
+
lib.install();
|
|
124
123
|
c = true;
|
|
125
124
|
} else {
|
|
126
125
|
const lib = b.addStaticLibrary(.{
|
|
@@ -135,8 +134,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
135
134
|
lib.bundle_compiler_rt = true;
|
|
136
135
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
137
136
|
if (pic) lib.force_pic = pic;
|
|
138
|
-
|
|
139
|
-
b.installArtifact(lib);
|
|
137
|
+
lib.install();
|
|
140
138
|
c = true;
|
|
141
139
|
}
|
|
142
140
|
|
|
@@ -207,7 +205,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
207
205
|
const lint_exe =
|
|
208
206
|
b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
|
|
209
207
|
if (tests.build) tests.step.dependOn(&lint_exe.step);
|
|
210
|
-
const lint =
|
|
208
|
+
const lint = lint_exe.run();
|
|
211
209
|
|
|
212
210
|
b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
|
|
213
211
|
b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
|
|
@@ -258,8 +256,11 @@ const TestStep = struct {
|
|
|
258
256
|
pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
|
|
259
257
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
260
258
|
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
259
|
+
const test_bin = b.option([]const u8, "test-bin", "Emit test binary to");
|
|
261
260
|
const test_filter =
|
|
262
261
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
262
|
+
const test_no_exec =
|
|
263
|
+
b.option(bool, "test-no-exec", "Compiles test binary without running it") orelse false;
|
|
263
264
|
|
|
264
265
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
265
266
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
@@ -273,17 +274,21 @@ const TestStep = struct {
|
|
|
273
274
|
.root_source_file = .{ .path = path },
|
|
274
275
|
.optimize = config.optimize,
|
|
275
276
|
.target = config.target,
|
|
276
|
-
.filter = test_filter,
|
|
277
277
|
});
|
|
278
278
|
tests.setMainPkgPath("./");
|
|
279
|
+
tests.setFilter(test_filter);
|
|
279
280
|
tests.addOptions("build_options", options);
|
|
280
281
|
tests.single_threaded = true;
|
|
281
282
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
282
283
|
if (config.pic) tests.force_pic = config.pic;
|
|
284
|
+
if (test_bin) |bin| {
|
|
285
|
+
tests.name = std.fs.path.basename(bin);
|
|
286
|
+
if (std.fs.path.dirname(bin)) |dir| tests.setOutputDir(dir);
|
|
287
|
+
}
|
|
283
288
|
if (coverage) |c| {
|
|
284
289
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
285
290
|
}
|
|
286
|
-
self.step.dependOn(&
|
|
291
|
+
self.step.dependOn(if (test_no_exec) &tests.step else &tests.run().step);
|
|
287
292
|
}
|
|
288
293
|
return self;
|
|
289
294
|
}
|
|
@@ -321,7 +326,7 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
321
326
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
322
327
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
323
328
|
|
|
324
|
-
const run =
|
|
329
|
+
const run = exe.run();
|
|
325
330
|
maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
|
|
326
331
|
if (b.args) |args| run.addArgs(args);
|
|
327
332
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkmn/engine",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.b9fb6eab",
|
|
4
4
|
"description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
|
|
5
5
|
"repository": "github:pkmn/engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,28 +9,6 @@
|
|
|
9
9
|
"types": "build/pkg/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"build.zig",
|
|
12
|
-
"build/pkg/data.d.ts",
|
|
13
|
-
"build/pkg/data.js.map",
|
|
14
|
-
"build/pkg/addon.d.ts",
|
|
15
|
-
"build/pkg/addon.js.map",
|
|
16
|
-
"build/pkg/addon.js",
|
|
17
|
-
"build/pkg/data.js",
|
|
18
|
-
"build/pkg/data/ids.json",
|
|
19
|
-
"build/pkg/data/layout.json",
|
|
20
|
-
"build/pkg/data/protocol.json",
|
|
21
|
-
"build/pkg/gen1.d.ts",
|
|
22
|
-
"build/pkg/gen1.js.map",
|
|
23
|
-
"build/pkg/gen1.js",
|
|
24
|
-
"build/pkg/index.d.ts",
|
|
25
|
-
"build/pkg/index.js.map",
|
|
26
|
-
"build/pkg/index.js",
|
|
27
|
-
"build/pkg/protocol.d.ts",
|
|
28
|
-
"build/pkg/protocol.js.map",
|
|
29
|
-
"build/pkg/protocol.js",
|
|
30
|
-
"build/test/display.js.map",
|
|
31
|
-
"build/test/display.js",
|
|
32
|
-
"build/tools/debug.js.map",
|
|
33
|
-
"build/tools/debug.js",
|
|
34
12
|
"src/bin/install-pkmn-engine",
|
|
35
13
|
"src/lib/binding/node.zig",
|
|
36
14
|
"src/lib/binding/wasm.zig",
|
|
@@ -39,66 +17,78 @@
|
|
|
39
17
|
"src/lib/common/options.zig",
|
|
40
18
|
"src/lib/common/protocol.zig",
|
|
41
19
|
"src/lib/common/rng.zig",
|
|
42
|
-
"src/lib/gen1/data.zig",
|
|
43
20
|
"src/lib/gen1/data/moves.zig",
|
|
44
21
|
"src/lib/gen1/data/species.zig",
|
|
45
22
|
"src/lib/gen1/data/types.zig",
|
|
23
|
+
"src/lib/gen1/data.zig",
|
|
46
24
|
"src/lib/gen1/helpers.zig",
|
|
47
25
|
"src/lib/gen1/mechanics.zig",
|
|
48
|
-
"src/lib/gen2/data.zig",
|
|
49
26
|
"src/lib/gen2/data/items.zig",
|
|
50
27
|
"src/lib/gen2/data/moves.zig",
|
|
51
28
|
"src/lib/gen2/data/species.zig",
|
|
52
29
|
"src/lib/gen2/data/types.zig",
|
|
30
|
+
"src/lib/gen2/data.zig",
|
|
53
31
|
"src/lib/gen2/helpers.zig",
|
|
54
32
|
"src/lib/gen2/mechanics.zig",
|
|
55
33
|
"src/lib/pkmn.zig",
|
|
56
|
-
"
|
|
34
|
+
"build/pkg/data/ids.json",
|
|
35
|
+
"build/pkg/data/layout.json",
|
|
36
|
+
"build/pkg/data/protocol.json",
|
|
37
|
+
"build/pkg/data.d.ts",
|
|
38
|
+
"build/pkg/data.js",
|
|
39
|
+
"build/pkg/data.js.map",
|
|
40
|
+
"build/pkg/gen1.d.ts",
|
|
41
|
+
"build/pkg/gen1.js",
|
|
42
|
+
"build/pkg/gen1.js.map",
|
|
43
|
+
"build/pkg/index.d.ts",
|
|
44
|
+
"build/pkg/index.js",
|
|
45
|
+
"build/pkg/index.js.map",
|
|
46
|
+
"build/pkg/protocol.d.ts",
|
|
47
|
+
"build/pkg/protocol.js",
|
|
48
|
+
"build/pkg/protocol.js.map"
|
|
57
49
|
],
|
|
58
50
|
"engines": {
|
|
59
51
|
"node": ">=16.0.0"
|
|
60
52
|
},
|
|
61
53
|
"bin": {
|
|
62
|
-
"install-pkmn-engine": "src/bin/install-pkmn-engine"
|
|
63
|
-
"pkmn-debug": "src/bin/pkmn-debug"
|
|
54
|
+
"install-pkmn-engine": "src/bin/install-pkmn-engine"
|
|
64
55
|
},
|
|
65
56
|
"publishConfig": {
|
|
66
57
|
"access": "public"
|
|
67
58
|
},
|
|
68
59
|
"dependencies": {
|
|
69
|
-
"@pkmn/data": "^0.7.
|
|
60
|
+
"@pkmn/data": "^0.7.35",
|
|
70
61
|
"@pkmn/protocol": "^0.6.11"
|
|
71
62
|
},
|
|
72
63
|
"devDependencies": {
|
|
73
64
|
"@pkmn/eslint-config": "^3.0.0",
|
|
74
65
|
"@pkmn/img": "^0.2.8",
|
|
75
66
|
"@pkmn/sets": "^5.0.4",
|
|
76
|
-
"@pkmn/sim": "0.7.
|
|
67
|
+
"@pkmn/sim": "0.7.35",
|
|
77
68
|
"@types/html-minifier": "^4.0.2",
|
|
78
69
|
"@types/jest": "^29.5.0",
|
|
79
70
|
"@types/minimist": "^1.2.2",
|
|
80
71
|
"@types/mustache": "^4.2.2",
|
|
81
72
|
"@types/node": "^18.15.11",
|
|
82
|
-
"@vitest/coverage-c8": "^0.
|
|
73
|
+
"@vitest/coverage-c8": "^0.29.8",
|
|
83
74
|
"binaryen": "^112.0.0",
|
|
84
|
-
"eslint": "^8.
|
|
75
|
+
"eslint": "^8.37.0",
|
|
85
76
|
"html-minifier": "^4.0.0",
|
|
86
|
-
"json-stringify-pretty-compact": "
|
|
77
|
+
"json-stringify-pretty-compact": "3.0.0",
|
|
87
78
|
"minimist": "^1.2.8",
|
|
88
79
|
"mustache": "^4.2.0",
|
|
89
80
|
"source-map-support": "^0.5.21",
|
|
90
81
|
"trakr": "^0.2.0",
|
|
91
|
-
"typescript": "^5.0.
|
|
92
|
-
"vitest": "^0.
|
|
82
|
+
"typescript": "^5.0.3",
|
|
83
|
+
"vitest": "^0.29.8"
|
|
93
84
|
},
|
|
94
85
|
"scripts": {
|
|
95
|
-
"lint": "eslint --cache src --ext ts,js && eslint src/bin
|
|
96
|
-
"fix": "eslint --fix src --ext ts,js && eslint --fix src/bin
|
|
86
|
+
"lint": "eslint --cache src --ext ts,js && eslint src/bin/install-pkmn-engine",
|
|
87
|
+
"fix": "eslint --fix src --ext ts,js && eslint --fix src/bin/install-pkmn-engine",
|
|
97
88
|
"compile": "tsc -p .",
|
|
98
89
|
"build": "npm run compile",
|
|
99
90
|
"test": "vitest src/pkg",
|
|
100
91
|
"test:integration": "vitest src/test",
|
|
101
|
-
"debug": "npm run compile && node build/tools/debug",
|
|
102
92
|
"fuzz": "npm run compile && node build/test/fuzz",
|
|
103
93
|
"generate": "npm run compile && node build/tools/generate",
|
|
104
94
|
"release": "npm run compile && node build/tools/release",
|
|
@@ -10,7 +10,7 @@ const path = require('path');
|
|
|
10
10
|
const {pipeline} = require('stream/promises');
|
|
11
11
|
const tty = require('tty');
|
|
12
12
|
|
|
13
|
-
const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev:
|
|
13
|
+
const ZIG_VERSION = {major: 0, minor: 11, patch: 0, dev: 2168};
|
|
14
14
|
const DEV = ZIG_VERSION.dev ? `-dev.${ZIG_VERSION.dev}` : '';
|
|
15
15
|
const VERSION = `${ZIG_VERSION.major}.${ZIG_VERSION.minor}.${ZIG_VERSION.patch}${DEV}`;
|
|
16
16
|
const INDEX = 'https://ziglang.org/download/index.json';
|
package/src/lib/binding/node.zig
CHANGED
|
@@ -34,11 +34,11 @@ fn bindings(env: c.napi_env) c.napi_value {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
fn bind(env: c.napi_env, gen: anytype) c.napi_value {
|
|
37
|
-
const
|
|
37
|
+
const options_size = @intCast(u32, gen.OPTIONS_SIZE);
|
|
38
38
|
const logs_size = @intCast(u32, gen.LOGS_SIZE);
|
|
39
39
|
var object = Object.init(env);
|
|
40
40
|
const properties = [_]c.napi_property_descriptor{
|
|
41
|
-
Property.init("
|
|
41
|
+
Property.init("OPTIONS_SIZE", .{ .value = Number.init(env, options_size) }),
|
|
42
42
|
Property.init("LOGS_SIZE", .{ .value = Number.init(env, logs_size) }),
|
|
43
43
|
Property.init("update", .{ .method = update(gen) }),
|
|
44
44
|
Property.init("choices", .{ .method = choices(gen) }),
|
|
@@ -108,10 +108,10 @@ fn choices(gen: anytype) c.napi_callback {
|
|
|
108
108
|
const request = @intToEnum(pkmn.Choice.Type, Number.get(env, argv[2], u8));
|
|
109
109
|
|
|
110
110
|
assert(c.napi_get_arraybuffer_info(env, argv[3], &data, &len) == c.napi_ok);
|
|
111
|
-
assert(len == gen.
|
|
111
|
+
assert(len == gen.OPTIONS_SIZE);
|
|
112
112
|
assert(data != null);
|
|
113
113
|
|
|
114
|
-
var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.
|
|
114
|
+
var out = @ptrCast([*]pkmn.Choice, data.?)[0..gen.OPTIONS_SIZE];
|
|
115
115
|
const n = battle.choices(player, request, out);
|
|
116
116
|
return Number.init(env, @bitCast(u8, n));
|
|
117
117
|
}
|
package/src/lib/binding/wasm.zig
CHANGED
|
@@ -4,7 +4,7 @@ const pkmn = @import("../pkmn.zig");
|
|
|
4
4
|
export const SHOWDOWN = pkmn.options.showdown;
|
|
5
5
|
export const TRACE = pkmn.options.trace;
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.
|
|
7
|
+
export const GEN1_OPTIONS_SIZE =
|
|
8
|
+
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.OPTIONS_SIZE)) catch unreachable;
|
|
9
9
|
export const GEN1_LOGS_SIZE =
|
|
10
10
|
std.math.ceilPowerOfTwo(u32, @intCast(u32, pkmn.gen1.LOGS_SIZE)) catch unreachable;
|
package/src/lib/gen1/README.md
CHANGED
|
@@ -332,9 +332,7 @@ must be gleaned through the `Battle` state). Useful size and offset information
|
|
|
332
332
|
the [`layout.json`](../../data/layout.json) which exists to simplify writing driver code.
|
|
333
333
|
|
|
334
334
|
Documentation of the wire protocol used for logging traces when `-Dtrace` is enabled can be found in
|
|
335
|
-
[PROTOCOL.md](../../../docs/PROTOCOL.md).
|
|
336
|
-
[`pkmn-debug`](../../../README.md#pkmn-debug) tool exists to display the binary protocol and battle
|
|
337
|
-
data in the browser for ease of debugging.
|
|
335
|
+
[PROTOCOL.md](../../../docs/PROTOCOL.md).
|
|
338
336
|
|
|
339
337
|
### `Battle`
|
|
340
338
|
|
|
@@ -478,8 +476,7 @@ Smogon](https://www.smogon.com/forums/posts/5933177/show):
|
|
|
478
476
|
- Confusion self-hits use the wrong damage formula resulting in off-by-one errors (and also fail to
|
|
479
477
|
account for an opponent's Reflect). Furthermore, the confusion self-hit damage will erroneously be
|
|
480
478
|
inflicted to the confused user's substitute if the confused user had been attempting to use a
|
|
481
|
-
self-targeting move.
|
|
482
|
-
damage for the purposes of tracking the battle's last damage.
|
|
479
|
+
self-targeting move.
|
|
483
480
|
|
|
484
481
|
Beyond the general bugs listed above, several move effects are implemented incorrectly by Pokémon
|
|
485
482
|
Showdown. Some of these moves are [too fundamentally broken to be implemented](#unimplementable) by
|
|
@@ -489,8 +486,7 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
489
486
|
incorrectly still gets applied to Bide's user.
|
|
490
487
|
- **Leech Seed**: Leech Seed fails to heal its source side if a seeded target faints due to
|
|
491
488
|
recoil/crash damage on Pokémon Showdown. Pokémon Showdown also updates the battle's last damage
|
|
492
|
-
field with the uncapped Leech Seed damage
|
|
493
|
-
for Bide and Counter.
|
|
489
|
+
field with the uncapped Leech Seed damage which has consequences for Bide and Counter.
|
|
494
490
|
- **Pay Day**: Pay Day should still scatter coins if it hits (but doesn't break) and opponent's
|
|
495
491
|
Substitute but doesn't on Pokémon Showdown.
|
|
496
492
|
- **Flinch**: Flinching does not get cleared during move selection on Pokémon Showdown and is
|
|
@@ -499,15 +495,9 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
499
495
|
skips end-of-turn residuals).
|
|
500
496
|
- **Rage**: Rage boosts should still result in burn/paralysis [stat modification
|
|
501
497
|
errors](https://pkmn.cc/bulba-glitch-1#Stat_modification_errors) but don't on Pokémon Showdown.
|
|
502
|
-
Furthermore, Pokémon Showdown only builds Rage for Disable/Explosion (hit/miss) when attacking
|
|
503
|
-
into a Substitute instead of all moves. Pokémon Showdown also implements the [Rage and Thrash /
|
|
504
|
-
Petal Dance accuracy bug]( https://www.youtube.com/watch?v=NC5gbJeExbs) incorrectly, as the
|
|
505
|
-
accuracy only gets written when the volatile is present which can lead to incorrect accuracy
|
|
506
|
-
values on turns where Rage is used on the same turn as a move which modifies accuracy or evasion.
|
|
507
498
|
- **Thrash** / **Petal Dance**: once a Pokémon is locked into a thrashing move they will lose all
|
|
508
499
|
speed ties on Pokémon Showdown (due to the fact that if they win the speed tie their action will
|
|
509
|
-
then get "changed" and inserted back into the queue after their opponent's action).
|
|
510
|
-
Showdown also implements accuracy incorrectly, as covered above.
|
|
500
|
+
then get "changed" and inserted back into the queue after their opponent's action).
|
|
511
501
|
- **Freeze** / **Sleep**: Pokémon Showdown requires a move to be selected when a Pokémon is frozen
|
|
512
502
|
or sleeping and uses that in the event that the status is removed while on the cartridge no
|
|
513
503
|
selection is possible and no turn exists for the thawed/woken Pokémon to act except in the case of
|
|
@@ -532,8 +522,7 @@ the pkmn engine, but the following moves have their broken behavior preserved in
|
|
|
532
522
|
Pokémon Showdown implementing the health check based on floating point division instead of integer
|
|
533
523
|
divison like on the cartridge (meaning the Substitute 1/4 glitch will only occur if the Pokémon's
|
|
534
524
|
maximum HP is evenly divisible by 4). Finally, Substitute also incorrectly blocks Dream Eater on
|
|
535
|
-
Pokémon Showdown
|
|
536
|
-
damage.
|
|
525
|
+
Pokémon Showdown.
|
|
537
526
|
|
|
538
527
|
In addition to numerous cases where Pokémon Showdown uses the wrong type of message (e.g. `|-fail`
|
|
539
528
|
vs. `|-miss|` vs. `|-immune|`, e.g. in the case of Leech Seed) which are not documented here, Pokémon
|
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_OPTIONS: 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_OPTIONS.
|
|
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 OPTIONS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
27
|
+
MAX_OPTIONS
|
|
28
28
|
else
|
|
29
|
-
std.math.ceilPowerOfTwo(usize,
|
|
29
|
+
std.math.ceilPowerOfTwo(usize, MAX_OPTIONS) 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)
|