@pkmn/engine 0.1.0-dev.b9fb6eab → 0.1.0-dev.bb8e286d

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.
Files changed (60) hide show
  1. package/README.md +101 -62
  2. package/build/pkg/addon.d.ts +7 -0
  3. package/build/pkg/addon.js +112 -0
  4. package/build/pkg/addon.js.map +1 -0
  5. package/build/pkg/data/ids.json +12 -12
  6. package/build/pkg/data/layout.json +27 -5
  7. package/build/pkg/data/protocol.json +69 -12
  8. package/build/pkg/data.d.ts +4 -4
  9. package/build/pkg/data.js +3 -5
  10. package/build/pkg/data.js.map +1 -1
  11. package/build/pkg/gen1.d.ts +5 -4
  12. package/build/pkg/gen1.js +49 -33
  13. package/build/pkg/gen1.js.map +1 -1
  14. package/build/pkg/index.d.ts +17 -13
  15. package/build/pkg/index.js.map +1 -1
  16. package/build/pkg/protocol.d.ts +4 -2
  17. package/build/pkg/protocol.js +61 -40
  18. package/build/pkg/protocol.js.map +1 -1
  19. package/build/test/display.js +400 -0
  20. package/build/test/display.js.map +1 -0
  21. package/build/tools/debug.js +135 -0
  22. package/build/tools/debug.js.map +1 -0
  23. package/build.zig +130 -94
  24. package/package.json +75 -42
  25. package/src/bin/install-pkmn-engine +11 -6
  26. package/src/bin/pkmn-debug +62 -0
  27. package/src/lib/binding/node.zig +47 -146
  28. package/src/lib/binding/wasm.zig +6 -4
  29. package/src/lib/common/battle.zig +17 -0
  30. package/src/lib/common/data.zig +19 -31
  31. package/src/lib/common/debug.zig +21 -11
  32. package/src/lib/common/js.zig +118 -0
  33. package/src/lib/common/optional.zig +67 -0
  34. package/src/lib/common/options.zig +12 -3
  35. package/src/lib/common/protocol.zig +931 -387
  36. package/src/lib/common/rational.zig +357 -0
  37. package/src/lib/common/rng.zig +24 -15
  38. package/src/lib/common/util.zig +12 -0
  39. package/src/lib/gen1/README.md +295 -181
  40. package/src/lib/gen1/calc.zig +426 -0
  41. package/src/lib/gen1/chance.zig +1060 -0
  42. package/src/lib/gen1/data/moves.zig +202 -190
  43. package/src/lib/gen1/data/species.zig +4 -4
  44. package/src/lib/gen1/data/types.zig +10 -10
  45. package/src/lib/gen1/data.zig +90 -76
  46. package/src/lib/gen1/helpers.zig +577 -32
  47. package/src/lib/gen1/mechanics.zig +1143 -828
  48. package/src/lib/gen2/README.md +105 -85
  49. package/src/lib/gen2/calc.zig +143 -0
  50. package/src/lib/gen2/chance.zig +1314 -0
  51. package/src/lib/gen2/data/items.zig +14 -20
  52. package/src/lib/gen2/data/moves.zig +664 -570
  53. package/src/lib/gen2/data/species.zig +2 -2
  54. package/src/lib/gen2/data/types.zig +137 -34
  55. package/src/lib/gen2/data.zig +128 -90
  56. package/src/lib/gen2/generated.zig +806 -0
  57. package/src/lib/gen2/helpers.zig +16 -22
  58. package/src/lib/gen2/mechanics.zig +3506 -12
  59. package/src/lib/pkmn.zig +68 -9
  60. package/src/test/display/pkmn.html.tmpl +368 -0
package/build.zig CHANGED
@@ -1,13 +1,20 @@
1
1
  const std = @import("std");
2
2
  const builtin = @import("builtin");
3
3
 
4
- pub const Options = struct { showdown: ?bool = null, trace: ?bool = null };
4
+ pub const Options = struct {
5
+ showdown: ?bool = null,
6
+ log: ?bool = null,
7
+ chance: ?bool = null,
8
+ calc: ?bool = null,
9
+ };
5
10
 
6
11
  pub fn module(b: *std.Build, options: Options) *std.Build.Module {
7
12
  const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
8
13
  const build_options = b.addOptions();
9
14
  build_options.addOption(?bool, "showdown", options.showdown);
10
- build_options.addOption(?bool, "trace", options.trace);
15
+ build_options.addOption(?bool, "log", options.log);
16
+ build_options.addOption(?bool, "chance", options.chance);
17
+ build_options.addOption(?bool, "calc", options.calc);
11
18
  return b.createModule(.{
12
19
  .source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
13
20
  .dependencies = &.{.{ .name = "build_options", .module = build_options.createModule() }},
@@ -27,25 +34,30 @@ pub fn build(b: *std.Build) !void {
27
34
  const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
28
35
  const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse false;
29
36
  const pic = b.option(bool, "pic", "Force position independent code") orelse false;
37
+ const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
38
+ const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
30
39
 
31
40
  const cmd = b.findProgram(&.{"strip"}, &.{}) catch null;
32
41
 
33
- var parser = std.json.Parser.init(b.allocator, false);
34
- defer parser.deinit();
35
- var tree = try parser.parse(@embedFile("package.json"));
36
- defer tree.deinit();
37
- const version = tree.root.Object.get("version").?.String;
38
- const description = tree.root.Object.get("description").?.String;
39
- var repository = std.mem.split(u8, tree.root.Object.get("repository").?.String, ":");
42
+ const json = @embedFile("package.json");
43
+ var parsed = try std.json.parseFromSlice(std.json.Value, b.allocator, json, .{});
44
+ defer parsed.deinit();
45
+ const version = parsed.value.object.get("version").?.string;
46
+ const description = parsed.value.object.get("description").?.string;
47
+ var repository = std.mem.split(u8, parsed.value.object.get("repository").?.string, ":");
40
48
  std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
41
49
 
42
50
  const showdown =
43
51
  b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
44
- const trace = b.option(bool, "trace", "Enable trace logs") orelse false;
52
+ const log = b.option(bool, "log", "Enable protocol message logging") orelse false;
53
+ const chance = b.option(bool, "chance", "Enable update probability tracking") orelse false;
54
+ const calc = b.option(bool, "calc", "Enable damage calculator support") orelse false;
45
55
 
46
56
  const options = b.addOptions();
47
57
  options.addOption(?bool, "showdown", showdown);
48
- options.addOption(?bool, "trace", trace);
58
+ options.addOption(?bool, "log", log);
59
+ options.addOption(?bool, "chance", chance);
60
+ options.addOption(?bool, "calc", calc);
49
61
 
50
62
  const name = if (showdown) "pkmn-showdown" else "pkmn";
51
63
 
@@ -54,16 +66,16 @@ pub fn build(b: *std.Build) !void {
54
66
  const addon = b.fmt("{s}.node", .{name});
55
67
  const lib = b.addSharedLibrary(.{
56
68
  .name = addon,
69
+ .main_pkg_path = .{ .path = "." },
57
70
  .root_source_file = .{ .path = "src/lib/binding/node.zig" },
58
71
  .optimize = optimize,
59
72
  .target = target,
60
73
  });
61
74
  lib.addOptions("build_options", options);
62
- lib.setMainPkgPath("./");
63
- lib.addSystemIncludePath(headers);
75
+ lib.addSystemIncludePath(.{ .path = headers });
64
76
  lib.linkLibC();
65
77
  if (node_import_lib) |il| {
66
- lib.addObjectFile(il);
78
+ lib.addObjectFile(.{ .path = il });
67
79
  } else if ((try std.zig.system.NativeTargetInfo.detect(target)).target.os.tag == .windows) {
68
80
  try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
69
81
  std.process.exit(1);
@@ -79,10 +91,11 @@ pub fn build(b: *std.Build) !void {
79
91
  //
80
92
  // But ziglang/zig#14647 broke this so we now need to do an install() and then manually
81
93
  // rename the file ourself in install-pkmn-engine
82
- lib.install();
94
+ b.installArtifact(lib);
83
95
  } else if (wasm) {
84
- const lib = b.addSharedLibrary(.{
96
+ const exe = b.addExecutable(.{
85
97
  .name = name,
98
+ .main_pkg_path = .{ .path = "." },
86
99
  .root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
87
100
  .optimize = switch (optimize) {
88
101
  .ReleaseFast, .ReleaseSafe => .ReleaseSmall,
@@ -90,51 +103,75 @@ pub fn build(b: *std.Build) !void {
90
103
  },
91
104
  .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
92
105
  });
93
- lib.addOptions("build_options", options);
94
- lib.setMainPkgPath("./");
95
- lib.stack_size = wasm_stack_size;
96
- lib.rdynamic = true;
97
- lib.strip = strip;
98
- if (pic) lib.force_pic = pic;
106
+ exe.addOptions("build_options", options);
107
+ exe.export_symbol_names = &[_][]const u8{
108
+ "SHOWDOWN",
109
+ "LOG",
110
+ "CHANCE",
111
+ "CALC",
112
+ "GEN1_CHOICES_SIZE",
113
+ "GEN1_LOGS_SIZE",
114
+ };
115
+ exe.entry = .disabled;
116
+ exe.stack_size = wasm_stack_size;
117
+ exe.strip = strip;
118
+ if (pic) exe.force_pic = pic;
99
119
  const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
100
120
  if (optimize != .Debug and opt != null) {
101
121
  const out = b.fmt("build/lib/{s}.wasm", .{name});
102
122
  const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
103
- sh.addArtifactArg(lib);
123
+ sh.addArtifactArg(exe);
104
124
  sh.addArg("-o");
105
125
  sh.addFileSourceArg(.{ .path = out });
106
126
  b.getInstallStep().dependOn(&sh.step);
127
+ } else {
128
+ b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{
129
+ .dest_dir = .{ .override = std.Build.InstallDir{ .lib = {} } },
130
+ }).step);
107
131
  }
108
- lib.install();
109
132
  } else if (dynamic) {
110
133
  const lib = b.addSharedLibrary(.{
111
134
  .name = name,
135
+ .main_pkg_path = .{ .path = "." },
112
136
  .root_source_file = .{ .path = "src/lib/binding/c.zig" },
113
- .version = try std.builtin.Version.parse(version),
137
+ .version = try std.SemanticVersion.parse(version),
114
138
  .optimize = optimize,
115
139
  .target = target,
116
140
  });
117
141
  lib.addOptions("build_options", options);
118
- lib.setMainPkgPath("./");
119
- lib.addIncludePath("src/include");
142
+ lib.addIncludePath(.{ .path = "src/include" });
120
143
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
121
144
  if (pic) lib.force_pic = pic;
122
- lib.install();
145
+ b.installArtifact(lib);
123
146
  c = true;
124
147
  } else {
125
148
  const lib = b.addStaticLibrary(.{
126
149
  .name = name,
150
+ .main_pkg_path = .{ .path = "." },
127
151
  .root_source_file = .{ .path = "src/lib/binding/c.zig" },
128
152
  .optimize = optimize,
129
153
  .target = target,
130
154
  });
131
155
  lib.addOptions("build_options", options);
132
- lib.setMainPkgPath("./");
133
- lib.addIncludePath("src/include");
156
+ lib.addIncludePath(.{ .path = "src/include" });
134
157
  lib.bundle_compiler_rt = true;
135
158
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
136
159
  if (pic) lib.force_pic = pic;
137
- lib.install();
160
+ if (emit_asm) {
161
+ b.getInstallStep().dependOn(&b.addInstallFileWithDir(
162
+ lib.getEmittedAsm(),
163
+ .prefix,
164
+ b.fmt("{s}.s", .{name}),
165
+ ).step);
166
+ }
167
+ if (emit_ll) {
168
+ b.getInstallStep().dependOn(&b.addInstallFileWithDir(
169
+ lib.getEmittedLlvmIr(),
170
+ .prefix,
171
+ b.fmt("{s}.ll", .{name}),
172
+ ).step);
173
+ }
174
+ b.installArtifact(lib);
138
175
  c = true;
139
176
  }
140
177
 
@@ -176,14 +213,20 @@ pub fn build(b: *std.Build) !void {
176
213
  .strip = strip,
177
214
  .cmd = cmd,
178
215
  };
216
+
217
+ // TODO: tests can be run multiple times due to @imports
179
218
  const tests = TestStep.create(b, options, config);
180
219
 
181
220
  var exes = std.ArrayList(*std.Build.CompileStep).init(b.allocator);
182
221
  const tools: ToolConfig = .{
222
+ .options = .{
223
+ .showdown = showdown,
224
+ .log = log,
225
+ .chance = chance,
226
+ .calc = calc,
227
+ },
183
228
  .general = config,
184
229
  .tool = .{
185
- .showdown = showdown,
186
- .trace = trace,
187
230
  .tests = if (tests.build) tests else null,
188
231
  .exes = &exes,
189
232
  },
@@ -192,28 +235,32 @@ pub fn build(b: *std.Build) !void {
192
235
  var benchmark_config = tools;
193
236
  benchmark_config.general.optimize = .ReleaseFast;
194
237
  benchmark_config.general.strip = true;
195
- const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
238
+ const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
196
239
 
197
240
  var fuzz_config = tools;
198
241
  fuzz_config.general.strip = false;
199
242
  fuzz_config.tool.name = "fuzz";
200
- const fuzz = tool(b, "src/test/benchmark.zig", fuzz_config);
201
-
202
- const serde = tool(b, "src/tools/serde.zig", tools);
203
- const protocol = tool(b, "src/tools/protocol.zig", tools);
204
-
205
- const lint_exe =
206
- b.addExecutable(.{ .name = "lint", .root_source_file = .{ .path = "src/tools/lint.zig" } });
207
- if (tests.build) tests.step.dependOn(&lint_exe.step);
208
- const lint = lint_exe.run();
209
-
210
- b.step("benchmark", "Run benchmark code").dependOn(&benchmark.step);
211
- b.step("fuzz", "Run fuzz tester").dependOn(&fuzz.step);
212
- b.step("lint", "Lint source files").dependOn(&lint.step);
213
- b.step("protocol", "Run protocol dump tool").dependOn(&protocol.step);
214
- b.step("serde", "Run serialization/deserialization tool").dependOn(&serde.step);
243
+ const fuzz = try tool(b, "src/test/fuzz.zig", fuzz_config);
244
+
245
+ const analyze = try tool(b, "src/tools/analyze.zig", tools);
246
+ const dump = try tool(b, "src/tools/dump.zig", tools);
247
+ const transitions = try tool(b, "src/tools/transitions.zig", tools);
248
+
249
+ // FIXME: serde randomly fails to build in some release configurations
250
+ var hack = tools;
251
+ if (optimize != .Debug) hack.tool.tests = null;
252
+ const serde = try tool(b, "src/tools/serde.zig", hack);
253
+
254
+ if (analyze) |t| b.step("analyze", "Run LLVM analysis tool").dependOn(&t.step);
255
+ if (benchmark) |t| b.step("benchmark", "Run benchmark code").dependOn(&t.step);
256
+ if (dump) |t| b.step("dump", "Run protocol dump tool").dependOn(&t.step);
257
+ if (fuzz) |t| b.step("fuzz", "Run fuzz tester").dependOn(&t.step);
258
+ if (serde) |t| b.step("serde", "Run serialization/deserialization tool").dependOn(&t.step);
215
259
  b.step("test", "Run all tests").dependOn(&tests.step);
216
260
  b.step("tools", "Install tools").dependOn(&ToolsStep.create(b, &exes).step);
261
+ if (transitions) |t| {
262
+ b.step("transitions", "Visualize transitions algorithm search").dependOn(&t.step);
263
+ }
217
264
  }
218
265
 
219
266
  fn maybeStrip(
@@ -243,12 +290,6 @@ const Config = struct {
243
290
  cmd: ?[]const u8,
244
291
  };
245
292
 
246
- const TESTS = .{
247
- "src/lib/common/test.zig",
248
- "src/lib/gen1/test.zig",
249
- "src/lib/gen2/test.zig",
250
- };
251
-
252
293
  const TestStep = struct {
253
294
  step: std.Build.Step,
254
295
  build: bool,
@@ -256,60 +297,57 @@ const TestStep = struct {
256
297
  pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
257
298
  const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
258
299
  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");
260
300
  const test_filter =
261
301
  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;
264
302
 
265
303
  const self = b.allocator.create(TestStep) catch @panic("OOM");
266
304
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
267
- self.* = TestStep{ .step = step, .build = test_filter == null };
268
-
269
- const paths: []const []const u8 =
270
- if (test_file) |t| &.{t} else if (coverage != null) &.{"src/lib/test.zig"} else &TESTS;
271
- for (paths) |path| {
272
- const tests = b.addTest(.{
273
- .name = std.fs.path.basename(std.fs.path.dirname(path).?),
274
- .root_source_file = .{ .path = path },
275
- .optimize = config.optimize,
276
- .target = config.target,
277
- });
278
- tests.setMainPkgPath("./");
279
- tests.setFilter(test_filter);
280
- tests.addOptions("build_options", options);
281
- tests.single_threaded = true;
282
- maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
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
- }
288
- if (coverage) |c| {
289
- tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
290
- }
291
- self.step.dependOn(if (test_no_exec) &tests.step else &tests.run().step);
305
+ self.* = .{ .step = step, .build = test_filter == null };
306
+
307
+ const path = test_file orelse "src/lib/test.zig";
308
+ const tests = b.addTest(.{
309
+ .name = b.fmt("{s}-{s}", .{
310
+ std.fs.path.basename(std.fs.path.dirname(path).?),
311
+ std.fs.path.stem(std.fs.path.basename(path)),
312
+ }),
313
+ .main_pkg_path = .{ .path = "." },
314
+ .root_source_file = .{ .path = path },
315
+ .optimize = config.optimize,
316
+ .target = config.target,
317
+ .filter = test_filter,
318
+ });
319
+ tests.addOptions("build_options", options);
320
+ tests.single_threaded = true;
321
+ maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
322
+ if (config.pic) tests.force_pic = config.pic;
323
+ if (coverage) |c| {
324
+ tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
292
325
  }
326
+ self.step.dependOn(&b.addRunArtifact(tests).step);
327
+
293
328
  return self;
294
329
  }
295
330
  };
296
331
 
297
332
  const ToolConfig = struct {
333
+ options: Options,
298
334
  general: Config,
299
335
  tool: struct {
300
- showdown: bool,
301
- trace: bool,
302
336
  tests: ?*TestStep,
303
337
  name: ?[]const u8 = null,
304
338
  exes: *std.ArrayList(*std.Build.CompileStep),
305
339
  },
306
340
  };
307
341
 
308
- fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep {
342
+ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunStep {
343
+ std.fs.cwd().access(path, .{}) catch |err| switch (err) {
344
+ error.FileNotFound => return null,
345
+ else => |e| return e,
346
+ };
309
347
  var name = config.tool.name orelse std.fs.path.basename(path);
310
348
  const index = std.mem.lastIndexOfScalar(u8, name, '.');
311
349
  if (index) |i| name = name[0..i];
312
- if (config.tool.showdown) name = b.fmt("{s}-showdown", .{name});
350
+ if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
313
351
 
314
352
  const exe = b.addExecutable(.{
315
353
  .name = name,
@@ -317,16 +355,14 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
317
355
  .target = config.general.target,
318
356
  .optimize = config.general.optimize,
319
357
  });
320
- exe.addModule("pkmn", module(b, .{
321
- .showdown = config.tool.showdown,
322
- .trace = config.tool.trace,
323
- }));
358
+ exe.addModule("pkmn", module(b, config.options));
359
+
324
360
  exe.single_threaded = true;
325
361
  if (config.general.pic) exe.force_pic = config.general.pic;
326
362
  if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
327
363
  config.tool.exes.append(exe) catch @panic("OOM");
328
364
 
329
- const run = exe.run();
365
+ const run = b.addRunArtifact(exe);
330
366
  maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
331
367
  if (b.args) |args| run.addArgs(args);
332
368
 
@@ -339,8 +375,8 @@ const ToolsStep = struct {
339
375
  pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.CompileStep)) *ToolsStep {
340
376
  const self = b.allocator.create(ToolsStep) catch @panic("OOM");
341
377
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
342
- self.* = ToolsStep{ .step = step };
343
- for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t).step);
378
+ self.* = .{ .step = step };
379
+ for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t, .{}).step);
344
380
  return self;
345
381
  }
346
382
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/engine",
3
- "version": "0.1.0-dev.b9fb6eab",
3
+ "version": "0.1.0-dev.bb8e286d",
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,86 +9,107 @@
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",
12
34
  "src/bin/install-pkmn-engine",
13
35
  "src/lib/binding/node.zig",
14
36
  "src/lib/binding/wasm.zig",
37
+ "src/lib/common/battle.zig",
15
38
  "src/lib/common/data.zig",
16
39
  "src/lib/common/debug.zig",
40
+ "src/lib/common/js.zig",
41
+ "src/lib/common/optional.zig",
17
42
  "src/lib/common/options.zig",
18
43
  "src/lib/common/protocol.zig",
44
+ "src/lib/common/rational.zig",
19
45
  "src/lib/common/rng.zig",
46
+ "src/lib/common/util.zig",
47
+ "src/lib/gen1/calc.zig",
48
+ "src/lib/gen1/chance.zig",
49
+ "src/lib/gen1/data.zig",
20
50
  "src/lib/gen1/data/moves.zig",
21
51
  "src/lib/gen1/data/species.zig",
22
52
  "src/lib/gen1/data/types.zig",
23
- "src/lib/gen1/data.zig",
24
53
  "src/lib/gen1/helpers.zig",
25
54
  "src/lib/gen1/mechanics.zig",
55
+ "src/lib/gen2/calc.zig",
56
+ "src/lib/gen2/chance.zig",
57
+ "src/lib/gen2/data.zig",
26
58
  "src/lib/gen2/data/items.zig",
27
59
  "src/lib/gen2/data/moves.zig",
28
60
  "src/lib/gen2/data/species.zig",
29
61
  "src/lib/gen2/data/types.zig",
30
- "src/lib/gen2/data.zig",
62
+ "src/lib/gen2/generated.zig",
31
63
  "src/lib/gen2/helpers.zig",
32
64
  "src/lib/gen2/mechanics.zig",
33
65
  "src/lib/pkmn.zig",
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"
66
+ "src/test/display/pkmn.html.tmpl"
49
67
  ],
50
68
  "engines": {
51
69
  "node": ">=16.0.0"
52
70
  },
53
71
  "bin": {
54
- "install-pkmn-engine": "src/bin/install-pkmn-engine"
72
+ "install-pkmn-engine": "src/bin/install-pkmn-engine",
73
+ "pkmn-debug": "src/bin/pkmn-debug"
55
74
  },
56
75
  "publishConfig": {
57
76
  "access": "public"
58
77
  },
59
78
  "dependencies": {
60
- "@pkmn/data": "^0.7.35",
61
- "@pkmn/protocol": "^0.6.11"
79
+ "@pkmn/data": "^0.7.54",
80
+ "@pkmn/protocol": "^0.6.16"
62
81
  },
63
82
  "devDependencies": {
64
- "@pkmn/eslint-config": "^3.0.0",
65
- "@pkmn/img": "^0.2.8",
66
- "@pkmn/sets": "^5.0.4",
67
- "@pkmn/sim": "0.7.35",
68
- "@types/html-minifier": "^4.0.2",
69
- "@types/jest": "^29.5.0",
70
- "@types/minimist": "^1.2.2",
71
- "@types/mustache": "^4.2.2",
72
- "@types/node": "^18.15.11",
73
- "@vitest/coverage-c8": "^0.29.8",
74
- "binaryen": "^112.0.0",
75
- "eslint": "^8.37.0",
83
+ "@pkmn/eslint-config": "^5.3.0",
84
+ "@pkmn/img": "^0.2.18",
85
+ "@pkmn/sets": "^5.1.0",
86
+ "@pkmn/sim": "0.7.54",
87
+ "@types/html-minifier": "^4.0.4",
88
+ "@types/jest": "^29.5.6",
89
+ "@types/minimist": "^1.2.4",
90
+ "@types/mustache": "^4.2.4",
91
+ "@types/node": "^20.8.9",
92
+ "@vitest/coverage-c8": "^0.33.0",
93
+ "binaryen": "^116.0.0",
94
+ "eslint": "^8.52.0",
76
95
  "html-minifier": "^4.0.0",
77
96
  "json-stringify-pretty-compact": "3.0.0",
78
97
  "minimist": "^1.2.8",
79
98
  "mustache": "^4.2.0",
80
99
  "source-map-support": "^0.5.21",
100
+ "table": "^6.8.1",
81
101
  "trakr": "^0.2.0",
82
- "typescript": "^5.0.3",
83
- "vitest": "^0.29.8"
102
+ "typescript": "^5.2.2",
103
+ "vitest": "^0.34.6"
84
104
  },
85
105
  "scripts": {
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",
106
+ "lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
107
+ "fix": "eslint --fix src --ext ts,js && eslint --fix src/bin/*",
88
108
  "compile": "tsc -p .",
89
109
  "build": "npm run compile",
90
110
  "test": "vitest src/pkg",
91
111
  "test:integration": "vitest src/test",
112
+ "debug": "npm run compile && node build/tools/debug",
92
113
  "fuzz": "npm run compile && node build/test/fuzz",
93
114
  "generate": "npm run compile && node build/tools/generate",
94
115
  "release": "npm run compile && node build/tools/release",
@@ -101,7 +122,7 @@
101
122
  "ignorePatterns": [
102
123
  "dist/",
103
124
  "node_modules/",
104
- "src/examples/zig",
125
+ "examples/zig",
105
126
  "build/"
106
127
  ],
107
128
  "env": {
@@ -117,7 +138,7 @@
117
138
  "parserOptions": {
118
139
  "project": [
119
140
  "./tsconfig.json",
120
- "./src/examples/js/tsconfig.json"
141
+ "./examples/js/tsconfig.json"
121
142
  ]
122
143
  }
123
144
  },
@@ -130,7 +151,8 @@
130
151
  "rules": {
131
152
  "no-control-regex": "off",
132
153
  "@typescript-eslint/no-empty-interface": "off",
133
- "@typescript-eslint/no-shadow": "off"
154
+ "@typescript-eslint/no-shadow": "off",
155
+ "@typescript-eslint/no-unsafe-declaration-merging": "off"
134
156
  }
135
157
  },
136
158
  {
@@ -146,12 +168,23 @@
146
168
  "src/test/benchmark*.ts"
147
169
  ],
148
170
  "rules": {
149
- "@typescript-eslint/no-unused-vars": "off"
171
+ "@typescript-eslint/no-unused-vars": "off",
172
+ "@typescript-eslint/no-redundant-type-constituents": "off"
173
+ }
174
+ },
175
+ {
176
+ "files": [
177
+ "src/pkg/protocol.test.ts"
178
+ ],
179
+ "rules": {
180
+ "jest/no-standalone-expect": "off",
181
+ "jest/no-conditional-expect": "off"
150
182
  }
151
183
  },
152
184
  {
153
185
  "files": [
154
- "src/test/*.test.ts"
186
+ "src/test/*.test.ts",
187
+ "src/test/regression/*.test.ts"
155
188
  ],
156
189
  "rules": {
157
190
  "jest/no-standalone-expect": "off"
@@ -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: 2168};
13
+ const ZIG_VERSION = {major: 0, minor: 12, patch: 0, dev: 1396};
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';
@@ -336,14 +336,18 @@ const downloadImportLib = async () => {
336
336
  node = true;
337
337
  if (!options) {
338
338
  const addon = require(copy);
339
- if (addon.options.showdown) opts.push('-Dshowdown');
340
- if (addon.options.trace) opts.push('-Dtrace');
339
+ if (addon.engine.options.showdown) opts.push('-Dshowdown');
340
+ if (addon.engine.options.log) opts.push('-Dlog');
341
+ if (addon.engine.options.chance) opts.push('-Dchance');
342
+ if (addon.engine.options.calc) opts.push('-Dcalc');
341
343
  }
342
344
  } else if (!options) {
343
345
  const addon = await WebAssembly.instantiate(fs.readFileSync(copy));
344
346
  const values = new Uint8Array(addon.instance.exports.memory.buffer);
345
347
  if (values[addon.instance.exports.SHOWDOWN.value]) opts.push('-Dshowdown');
346
- if (values[addon.instance.exports.TRACE.value]) opts.push('-Dtrace');
348
+ if (values[addon.instance.exports.LOG.value]) opts.push('-Dlog');
349
+ if (values[addon.instance.exports.CHANCE.value]) opts.push('-Dchance');
350
+ if (values[addon.instance.exports.CALC.value]) opts.push('-Dcalc');
347
351
  }
348
352
  const key = `${type} ${opts.sort().join(' ')}`;
349
353
  if (!configs.has(key)) configs.set(key, {type, options: opts});
@@ -354,8 +358,9 @@ const downloadImportLib = async () => {
354
358
  // either the default options or whatever was passed in
355
359
  if (!configs.size) {
356
360
  node = true;
357
- configs.set('node', {type: 'node', options: options || ['-Dshowdown']});
358
- configs.set('wasm', {type: 'wasm', options: options || ['-Dshowdown']});
361
+ const DEFAULT = ['-Dshowdown'];
362
+ configs.set('node', {type: 'node', options: options || DEFAULT});
363
+ configs.set('wasm', {type: 'wasm', options: options || DEFAULT});
359
364
  }
360
365
 
361
366
  const headers = node ? await downloadHeaders() : undefined;