@pkmn/engine 0.1.0-dev.d716e940 → 0.1.0-dev.d73cd76c
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 +114 -69
- package/build/pkg/addon/browser.d.ts +3 -0
- package/build/pkg/addon/browser.js +47 -0
- package/build/pkg/addon/browser.js.map +1 -0
- package/build/pkg/addon/node.d.ts +3 -0
- package/build/pkg/addon/node.js +110 -0
- package/build/pkg/addon/node.js.map +1 -0
- package/build/pkg/addon/wasm.d.ts +2 -0
- package/build/pkg/addon/wasm.js +53 -0
- package/build/pkg/addon/wasm.js.map +1 -0
- package/build/pkg/addon.d.ts +26 -4
- package/build/pkg/addon.js +39 -70
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +39 -4
- package/build/pkg/data/protocol.json +84 -13
- package/build/pkg/data.d.ts +27 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +15 -18
- package/build/pkg/gen1.js +43 -37
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +42 -91
- package/build/pkg/index.js +23 -70
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +29 -1
- package/build/pkg/protocol.js +123 -102
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +84 -73
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/debug.jsx +66 -0
- package/build/tools/display/debug.jsx.map +1 -0
- package/build/tools/display/index.js +152 -0
- package/build/tools/display/index.js.map +1 -0
- package/build/tools/display/ui.jsx +360 -0
- package/build/tools/display/ui.jsx.map +1 -0
- package/build/tools/display/util.js +157 -0
- package/build/tools/display/util.js.map +1 -0
- package/build.zig +428 -176
- package/package.json +72 -122
- package/src/bin/install-pkmn-engine +56 -25
- package/src/bin/pkmn-debug +1 -1
- package/src/lib/bindings/c.zig +201 -0
- package/src/lib/bindings/node.zig +117 -0
- package/src/lib/bindings/wasm.zig +51 -0
- package/src/lib/common/array.zig +70 -0
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +19 -31
- package/src/lib/common/debug.zig +58 -33
- package/src/lib/common/js.zig +114 -0
- package/src/lib/common/optional.zig +71 -0
- package/src/lib/common/options.zig +15 -0
- package/src/lib/common/protocol.zig +1037 -462
- package/src/lib/common/rational.zig +440 -0
- package/src/lib/common/rng.zig +31 -24
- package/src/lib/common/util.zig +64 -0
- package/src/lib/gen1/calc.zig +975 -0
- package/src/lib/gen1/chance.zig +1246 -0
- package/src/lib/gen1/data/moves.zig +203 -193
- package/src/lib/gen1/data/species.zig +6 -8
- package/src/lib/gen1/data/types.zig +12 -13
- package/src/lib/gen1/data.zig +98 -89
- package/src/lib/gen1/helpers.zig +159 -51
- package/src/lib/gen1/mechanics.zig +1211 -846
- package/src/lib/gen2/calc.zig +150 -0
- package/src/lib/gen2/chance.zig +914 -0
- package/src/lib/gen2/data/items.zig +15 -23
- package/src/lib/gen2/data/moves.zig +665 -573
- package/src/lib/gen2/data/species.zig +3 -5
- package/src/lib/gen2/data/types.zig +141 -36
- package/src/lib/gen2/data.zig +136 -100
- package/src/lib/gen2/generated.zig +801 -0
- package/src/lib/gen2/helpers.zig +81 -58
- package/src/lib/gen2/mechanics.zig +3582 -30
- package/src/lib/napi.h +2 -0
- package/src/lib/node.zig +14 -0
- package/src/lib/pkmn.zig +172 -17
- package/src/lib/wasm.zig +13 -0
- package/src/tools/display/dom.ts +108 -0
- package/src/tools/display/ui.css +354 -0
- package/build/test/display.js +0 -400
- package/build/test/display.js.map +0 -1
- package/src/lib/binding/node.zig +0 -229
- package/src/lib/binding/wasm.zig +0 -10
- package/src/lib/gen1/README.md +0 -812
- package/src/lib/gen2/README.md +0 -309
- package/src/test/display/pkmn.html.tmpl +0 -368
package/LICENSE
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021-2023 pkmn contributors
|
|
1
|
+
Copyright (c) 2021-2026 pkmn contributors
|
|
4
2
|
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
4
|
this software and associated documentation files (the "Software"), to deal in
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<br />
|
|
4
4
|
<br />
|
|
5
5
|
<a href="https://github.com/pkmn/engine/actions/workflows/test.yml">
|
|
6
|
-
<img alt="Test Status" src="https://github.com/pkmn/engine/workflows/
|
|
6
|
+
<img alt="Test Status" src="https://github.com/pkmn/engine/actions/workflows/test.yml/badge.svg" />
|
|
7
7
|
</a>
|
|
8
8
|
<a href="#status">
|
|
9
9
|
<img alt="WIP" src="https://img.shields.io/badge/status-WIP-red.svg" />
|
|
@@ -12,13 +12,19 @@
|
|
|
12
12
|
<img alt="License" src="https://img.shields.io/badge/License-MIT-blue.svg" />
|
|
13
13
|
</a>
|
|
14
14
|
</p>
|
|
15
|
+
|
|
16
|
+
> [!WARNING]
|
|
17
|
+
> **This project is under heavy development** and currently the `main` branch contains numerous breaking
|
|
18
|
+
> changes which may not work and which are not fully documented. Please **wait for the forthcoming
|
|
19
|
+
> initial v0.1 release** before depending on this project.
|
|
20
|
+
|
|
15
21
|
<hr />
|
|
16
22
|
|
|
17
23
|
A minimal, complete, Pokémon battle simulation engine optimized for performance and
|
|
18
24
|
[designed](docs/DESIGN.md) for tooling, embedded systems, and [artificial
|
|
19
25
|
intelligence](https://github.com/pkmn/0-ERROR) use cases. This engine aims to be a frame-accurate and
|
|
20
26
|
[bug-for-bug compatible](http://www.catb.org/jargon/html/B/bug-for-bug-compatible.html)
|
|
21
|
-
implementation of both Pokémon battles as defined by the original game code
|
|
27
|
+
implementation of both Pokémon battles as defined by the original game code and the [Pokémon
|
|
22
28
|
Showdown](https://pokemonshowdown.com/)[^1] simulator which represents Pokémon battling as practically
|
|
23
29
|
interpreted online.
|
|
24
30
|
|
|
@@ -49,9 +55,9 @@ $ zig build --prefix /usr/local -Doptimize=ReleaseFast
|
|
|
49
55
|
```
|
|
50
56
|
|
|
51
57
|
The Zig website has [installation instructions](https://ziglang.org/learn/getting-started/) which
|
|
52
|
-
walk through how to install Zig on each platform - the engine code should work on Zig v0.
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
walk through how to install Zig on each platform - the engine code should work on Zig v0.16.0,
|
|
59
|
+
though tracks Zig's master branch so this may change in the future if breaking language changes are
|
|
60
|
+
introduced.
|
|
55
61
|
|
|
56
62
|
`libpkmn` can be built with `-Dshowdown` to instead produce the Pokémon Showdown compatible
|
|
57
63
|
`libpkmn-showdown` library. Furthermore, protocol message logging can be enabled through `-Dlog`.
|
|
@@ -67,40 +73,67 @@ $ npm install @pkmn/engine
|
|
|
67
73
|
```
|
|
68
74
|
|
|
69
75
|
The driver depends on being able to find compiled Node/WASM addons in
|
|
70
|
-
`node_modules/@pkmn/engine/build/lib`
|
|
71
|
-
|
|
72
|
-
[`install-pkmn-engine`](src/bin/install-pkmn-engine) which
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
`node_modules/@pkmn/engine/build/lib` to be useful. When you install the package a [`postinstall`
|
|
77
|
+
lifecycle script](https://docs.npmjs.com/cli/v8/using-npm/scripts) runs
|
|
78
|
+
[`install-pkmn-engine`](src/bin/install-pkmn-engine) which checks for a compatible `zig` compiler
|
|
79
|
+
(see earlier regarding minimum version) and download one to `node_module/@pkmn/engine/build/bin` if
|
|
80
|
+
it can't find one, as well as looking for (and downloading, if necessary) the required Node headers
|
|
81
|
+
needed to successfully build the addons natively.
|
|
82
|
+
|
|
83
|
+
> [!IMPORTANT]
|
|
84
|
+
> If you have configured `npm` to `--ignore-scripts` (or are using [npm v12+ and have not
|
|
85
|
+
> approved](https://github.blog/changelog/2026-06-09-upcoming-breaking-changes-for-npm-v12/)
|
|
86
|
+
> `@pkmn/engine` via `npm approve-scripts @pkmn/engine`) **you must either run `npx install-pkmn-engine`
|
|
87
|
+
> directly or build the addons manually and place the artifacts in the expected paths.**
|
|
79
88
|
|
|
80
89
|
### `pkmn`
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
To include `pkmn`, add it as a dependency in your project's
|
|
92
|
+
[`build.zig.zon`](https://github.com/ziglang/zig/blob/master/doc/build.zig.zon.md) using [Zig's
|
|
93
|
+
Package Management
|
|
94
|
+
system](https://ziglang.org/download/0.11.0/release-notes.html#Package-Management):
|
|
95
|
+
|
|
96
|
+
```zig
|
|
97
|
+
.dependencies = .{
|
|
98
|
+
.pkmn = .{
|
|
99
|
+
.url = "https://github.com/pkmn/engine/archive/RELEASE.tar.gz",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Replace `RELEASE` with the tag for the [release](https://github.com/pkmn/engine/releases) you wish
|
|
105
|
+
to use (e.g. `0.1.0` or `nightly`) or the specific hash of any commit. Next, run `zig build` and
|
|
106
|
+
copy the expected hash from the error message into your `build.zig.zon` alongside the `.url`:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
$ zig build
|
|
110
|
+
error: dependency is missing hash field
|
|
111
|
+
.url = "https://github.com/pkmn/engine/archive/nightly.tar.gz",
|
|
112
|
+
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
113
|
+
note: expected .hash = "122056b93b403033cb7d9bed96a02c2eb8cc1275515976167726ada6eb4207e8ef8a",
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Note that this hash is **not** going to be the same as the commit hash. After adding the hash to
|
|
117
|
+
your `build.zig.zon` you will be able to import the `pkmn` package's build helpers into your
|
|
118
|
+
`build.zig`:
|
|
86
119
|
|
|
87
120
|
```zig
|
|
88
121
|
const std = @import("std");
|
|
89
|
-
const pkmn = @import("lib/pkmn/build.zig");
|
|
90
122
|
|
|
91
|
-
pub fn build(b: *std.
|
|
123
|
+
pub fn build(b: *std.Build) void {
|
|
92
124
|
...
|
|
93
|
-
|
|
125
|
+
const pkmn = b.dependency("pkmn", .{ .showdown = true, .log = true });
|
|
126
|
+
exe.root_module.addImport("pkmn", pkmn.module("pkmn"));
|
|
94
127
|
...
|
|
95
128
|
}
|
|
96
129
|
```
|
|
97
130
|
|
|
98
|
-
The
|
|
99
|
-
|
|
100
|
-
|
|
131
|
+
The `pkmn` package can be configured with various options such as whether or not Pokémon Showdown
|
|
132
|
+
compatibility mode or protocol message logging should be enabled. Alternatively, you may set options
|
|
133
|
+
via a `pkmn_options` [root source file
|
|
101
134
|
declaration](https://ziglang.org/documentation/master/#Root-Source-File). There are several
|
|
102
135
|
undocumented internal options that can be tweaked as well via build or root options, though these
|
|
103
|
-
options
|
|
136
|
+
options aren't officially supported, affect correctness, and may change meaning or behavior without
|
|
104
137
|
warning. Use at your own risk.
|
|
105
138
|
|
|
106
139
|
```zig
|
|
@@ -112,11 +145,11 @@ pub const pkmn_options = .{ .showdown = true, .log = true };
|
|
|
112
145
|
For each Pokémon generation, the engine provides a battle structure with two functions - a function
|
|
113
146
|
to `update` the battle's state based on both players' choices and a function that defines which
|
|
114
147
|
`choices` are valid at that decision point (at the beginning of a battle both player's must "pass"
|
|
115
|
-
as their first choice
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
148
|
+
as their first choice to switch in the first member of their party). If `-Dlog` protocol logging is
|
|
149
|
+
enabled each update produces logs which can be decoded into a buffer (`LOGS_SIZE` constants are
|
|
150
|
+
provided to make it easy to allocate a buffer of the correct size). Each `update` returns a result
|
|
151
|
+
to indicate either that the battle has terminated or which types of choices are available for each
|
|
152
|
+
player.
|
|
120
153
|
|
|
121
154
|
Unlike [Pokémon Showdown's
|
|
122
155
|
SIM-PROTOCOL](https://github.com/smogon/pokemon-showdown/blob/master/sim/SIM-PROTOCOL.md#choice-requests)
|
|
@@ -128,83 +161,87 @@ state or cause the engine to crash.**
|
|
|
128
161
|
|
|
129
162
|
Battles may be played out from any point but to freshly initialize a battle which is yet to start
|
|
130
163
|
the turn count and active Pokémon should be zeroed out (driver code should handle this for you).
|
|
131
|
-
Most driver code should also provide helpers to make
|
|
164
|
+
Most driver code should also provide helpers to make initializing battle convenient - check the
|
|
132
165
|
respective documentation and examples for the bindings being used. The engine's [protocol
|
|
133
166
|
documentation](docs/PROTOCOL.md) goes into greater detail on the specifics of updates and the
|
|
134
167
|
potential logs that may result.
|
|
135
168
|
|
|
136
169
|
*The snippets below are meant to merely illustrate in broad strokes how the pkmn engine can be used
|
|
137
|
-
\- the [`examples`](
|
|
170
|
+
\- the [`examples`](examples) directory contains fully commented and runnable code.*
|
|
138
171
|
|
|
139
172
|
### C
|
|
140
173
|
|
|
141
174
|
[`pkmn.h`](src/include/pkmn.h) exports the C API for `libpkmn`. Symbols are all prefixed with
|
|
142
175
|
`pkmn_` to avoid name collisions. If `-Dlog` is enabled and logging throws an error then the error
|
|
143
|
-
|
|
176
|
+
is encoded in the `pkmn_result` and can be checked with `pkmn_error`.
|
|
144
177
|
|
|
145
178
|
```c
|
|
146
179
|
#include <pkmn.h>
|
|
147
180
|
|
|
181
|
+
pkmn_battle_options options;
|
|
182
|
+
pkmn_gen1_battle_options_set(&options, ...);
|
|
148
183
|
pkmn_battle battle = ...;
|
|
149
|
-
|
|
184
|
+
|
|
150
185
|
pkmn_result result;
|
|
151
186
|
pkmn_choice c1 = 0, c2 = 0;
|
|
152
|
-
while (!pkmn_result_type(result = pkmn_battle_update(&battle, c1, c2,
|
|
187
|
+
while (!pkmn_result_type(result = pkmn_battle_update(&battle, c1, c2, &options))) {
|
|
153
188
|
c1 = choose(PKMN_PLAYER_P1, pkmn_result_p1(result));
|
|
154
189
|
c2 = choose(PKMN_PLAYER_P2, pkmn_result_p2(result));
|
|
190
|
+
pkmn_gen1_battle_options_set(&options, ...);
|
|
155
191
|
}
|
|
156
192
|
if (pkmn_error(result)) exit(1);
|
|
157
193
|
```
|
|
158
194
|
|
|
159
|
-
[(full code)](
|
|
195
|
+
[(full code)](examples/c/example.c)
|
|
160
196
|
|
|
161
|
-
The C API
|
|
197
|
+
The C API doesn't export any helpers for creating or accessing the opaque battle objects - it's
|
|
162
198
|
instead intended to be used as the foundation for more ergonomic bindings in [other
|
|
163
199
|
languages](#other) (the lack of namespaces and bit fields having an implementation-defined layout in
|
|
164
200
|
C are the main contributing factors to the sparseness of what `libpkmn` chooses to expose).
|
|
165
201
|
|
|
166
202
|
### JavaScript / TypeScript
|
|
167
203
|
|
|
168
|
-
`@pkmn/engine` depends on the [`@pkmn/data`](https://www.npmjs.com/package/@pkmn/data) which
|
|
204
|
+
`@pkmn/engine` depends on the [`@pkmn/data`](https://www.npmjs.com/package/@pkmn/data) package which
|
|
169
205
|
requires a `Dex` implementation to be provided as well. The `Battle.create` function can be used to
|
|
170
206
|
initialize a `Battle` from the beginning, or `Battle.restore` can be used to re-instantiate a battle
|
|
171
|
-
which is in
|
|
207
|
+
which is already in progress. If logging is enabled the output can be turned into Pokémon Showdown
|
|
172
208
|
protocol via `Log.parse`.
|
|
173
209
|
|
|
174
210
|
```ts
|
|
175
211
|
import {Dex} from '@pkmn/dex';
|
|
176
212
|
import {Generations} from '@pkmn/data';
|
|
177
|
-
import {Battle} from '@pkmn/engine';
|
|
213
|
+
import {Battle, Choice} from '@pkmn/engine';
|
|
178
214
|
|
|
179
215
|
const gens = new Generations(Dex);
|
|
180
216
|
const battle = Battle.create(...);
|
|
181
217
|
|
|
182
|
-
const choose = (
|
|
218
|
+
const choose = (choices: Choice[]) =>
|
|
219
|
+
choices[Math.floor(Math.random() * choices.length)];
|
|
183
220
|
|
|
184
221
|
let result: Result;
|
|
185
222
|
let c1: Choice, c2: Choice;
|
|
186
223
|
while (!(result = battle.update(c1, c2)).type) {
|
|
187
|
-
c1 = battle.
|
|
188
|
-
c2 = battle.
|
|
224
|
+
c1 = choose(battle.choices('p1', result));
|
|
225
|
+
c2 = choose(battle.choices('p2', result));
|
|
189
226
|
}
|
|
190
227
|
|
|
191
228
|
console.log(result);
|
|
192
229
|
```
|
|
193
230
|
|
|
194
|
-
[(full code)](
|
|
231
|
+
[(full code)](examples/js/example.ts)
|
|
195
232
|
|
|
196
|
-
By default, the `@pkmn/engine` package
|
|
233
|
+
By default, the `@pkmn/engine` package compiles the engine with `-Dshowdown`, though by running
|
|
197
234
|
`install-pkmn-engine` directly and passing in `--options` you can override this default and build
|
|
198
235
|
different configurations of the extension for the driver to use. The driver can support
|
|
199
236
|
configurations both with and without Pokémon Showdown compatibility simultaneously if present. On
|
|
200
|
-
update, the post-install script
|
|
237
|
+
update, the post-install script attempts to rebuild whichever extensions it finds with the same
|
|
201
238
|
configuration parameters that were originally used meaning updating to the newest version of the
|
|
202
239
|
library should be seamless.
|
|
203
240
|
|
|
204
241
|
Despite relying on the native engine code, the `@pkmn/engine` code is designed to also work in
|
|
205
242
|
browsers which support [WebAssembly](https://webassembly.org/). Running `npm run start:web` from the
|
|
206
|
-
[`examples`](
|
|
207
|
-
|
|
243
|
+
[`examples`](examples/js) directory starts a server that can be used to demonstrate the engine
|
|
244
|
+
running in the browser.
|
|
208
245
|
|
|
209
246
|
### Zig
|
|
210
247
|
|
|
@@ -215,17 +252,18 @@ be used when logging is enabled to allow for easily printing e.g. to standard ou
|
|
|
215
252
|
const std = @import("std");
|
|
216
253
|
const pkmn = @import("pkmn");
|
|
217
254
|
|
|
218
|
-
var
|
|
255
|
+
var prng: std.Random.DefaultPrng = .init(seed);
|
|
256
|
+
var random = prng.random();
|
|
219
257
|
var choices: [pkmn.CHOICES_SIZE]pkmn.Choice = undefined;
|
|
220
258
|
|
|
221
259
|
var battle = ...
|
|
222
|
-
var
|
|
260
|
+
var options = pkmn.battle.options(...);
|
|
223
261
|
|
|
224
|
-
var c1 =
|
|
225
|
-
var c2 =
|
|
262
|
+
var c1: pkmn.Choice = .{};
|
|
263
|
+
var c2: pkmn.Choice = .{};
|
|
226
264
|
|
|
227
|
-
var result = try battle.update(c1, c2,
|
|
228
|
-
while (result.type == .None) : (result = try battle.update(c1, c2,
|
|
265
|
+
var result = try battle.update(c1, c2, &options);
|
|
266
|
+
while (result.type == .None) : (result = try battle.update(c1, c2, &options)) {
|
|
229
267
|
c1 = choices[random.uintLessThan(u8, battle.choices(.P1, result.p1, &choices))];
|
|
230
268
|
c2 = choices[random.uintLessThan(u8, battle.choices(.P2, result.p2, &choices))];
|
|
231
269
|
}
|
|
@@ -233,11 +271,11 @@ while (result.type == .None) : (result = try battle.update(c1, c2, log)) {
|
|
|
233
271
|
std.debug.print("{}\n", .{result.type});
|
|
234
272
|
```
|
|
235
273
|
|
|
236
|
-
[(full code)](
|
|
274
|
+
[(full code)](examples/zig/example.zig)
|
|
237
275
|
|
|
238
276
|
The Zig package also supports some APIs which are difficult to expose elsewhere such as the
|
|
239
277
|
`FixedRNG` which allows you to fully specify the exact RNG frames (which can be useful for ensuring
|
|
240
|
-
certain outcomes/effects always occur) for a battle, though doing so
|
|
278
|
+
certain outcomes/effects always occur) for a battle, though doing so changes the size of the
|
|
241
279
|
`Battle` object.
|
|
242
280
|
|
|
243
281
|
### Other
|
|
@@ -248,7 +286,7 @@ simplify the process even further [`src/data`](src/data) contains JSON dumps of
|
|
|
248
286
|
data, structure sizes and offsets, and protocol information used by the reference driver code. The
|
|
249
287
|
following is a list of known `libpkmn` bindings written by developers outside of the [pkmn
|
|
250
288
|
organization](https://github.com/pkmn) that may be helpful (though note that these projects may not
|
|
251
|
-
necessarily be up-to-date/complete/correct - inclusion in this list
|
|
289
|
+
necessarily be up-to-date/complete/correct - inclusion in this list doesn't imply endorsement):
|
|
252
290
|
|
|
253
291
|
| Language | License | URL |
|
|
254
292
|
| ---------- | --------- | ------------------------------------ |
|
|
@@ -276,13 +314,20 @@ By default, `pkmn-debug` expects to read [binary debug protocol](docs/PROTOCOL.m
|
|
|
276
314
|
$ <cmd> | pkmn-debug > index.html
|
|
277
315
|
```
|
|
278
316
|
|
|
279
|
-
Alternatively, if a single filename argument is passed to the `pkmn-debug` it
|
|
317
|
+
Alternatively, if a single filename argument is passed to the `pkmn-debug` it reads from that
|
|
280
318
|
instead:
|
|
281
319
|
|
|
282
320
|
```sh
|
|
283
321
|
$ pkmn-debug <file> > index.html
|
|
284
322
|
```
|
|
285
323
|
|
|
324
|
+
Finally, `pkmn-debug` also supports a `--json` flag which causes the decoded data to be dumped as
|
|
325
|
+
JSON instead of HTML:
|
|
326
|
+
|
|
327
|
+
```sh
|
|
328
|
+
$ pkmn-debug --json <file> > index.json
|
|
329
|
+
```
|
|
330
|
+
|
|
286
331
|
## Status
|
|
287
332
|
|
|
288
333
|
The engine is currently expected to be developed over multiple stages:
|
|
@@ -295,17 +340,17 @@ The engine is currently expected to be developed over multiple stages:
|
|
|
295
340
|
| ***3*** | *modern generations* |
|
|
296
341
|
|
|
297
342
|
Currently, most of the foundational work from stage 0 is done:
|
|
298
|
-
|
|
343
|
+
|
|
299
344
|
- [benchmark and integration testing](src/test) infrastructure
|
|
300
345
|
- [documentation](docs) about design, research, methodology, etc
|
|
301
|
-
- definition and implementation of the [protocol](docs/PROTOCOL.md) that
|
|
346
|
+
- definition and implementation of the [protocol](docs/PROTOCOL.md) that's used by the engine
|
|
302
347
|
|
|
303
|
-
**Stage 1 is currently in progress** and
|
|
348
|
+
**Stage 1 is currently in progress** and involves the implementation of the actual Generation I & II
|
|
304
349
|
battle engines, followed by Generation III & IV in stage 2. The implementation of further Pokémon
|
|
305
|
-
generations is in scope for the project but
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
350
|
+
generations is in scope for the project but shouldn't be considered part of the immediate roadmap
|
|
351
|
+
(i.e. exploring the options for broadening support for old generation APIs is given higher priority
|
|
352
|
+
than implementing more modern generations). Furthermore, implementation of modern generations is
|
|
353
|
+
soft-blocked on the [availability of high quality
|
|
309
354
|
decompilations](https://github.com/orgs/pret/repositories) of the original games in question.
|
|
310
355
|
|
|
311
356
|
Certain features will always be deemed **out of scope**:
|
|
@@ -323,10 +368,10 @@ The pkmn engine is distributed under the terms of the [MIT License](LICENSE).
|
|
|
323
368
|
[^1]: In the case of Pokémon Showdown, only bugs which stem from a misimplementation of specific
|
|
324
369
|
effects are reproduced in the engine, bugs which are the result of a misunderstanding of the
|
|
325
370
|
fundamental mechanics of Pokémon or which simply arise due to specific Pokémon Showdown
|
|
326
|
-
implementation details that
|
|
327
|
-
choices
|
|
371
|
+
implementation details that aren't replicable without making the same (incorrect) architectural
|
|
372
|
+
choices aren't. Furthermore, the "Pokémon Showdown" code referenced by this project includes
|
|
328
373
|
several [patches](docs/TESTING.md#patches) to improve accuracy and smooth over some of the more
|
|
329
374
|
egregious implementation issues. In practical terms, the vast majority of games played out in the
|
|
330
|
-
pkmn engine's compatibility mode and on this patched Pokémon Showdown simulator
|
|
331
|
-
it
|
|
375
|
+
pkmn engine's compatibility mode and on this patched Pokémon Showdown simulator are the same,
|
|
376
|
+
it's only in a well defined and documented set of circumstances where the two implementations
|
|
332
377
|
diverge.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.load = load;
|
|
4
|
+
exports.loadSync = loadSync;
|
|
5
|
+
const wasm_1 = require("./wasm");
|
|
6
|
+
async function load(showdown, addon) {
|
|
7
|
+
if (typeof addon === 'string' && addon !== 'wasm') {
|
|
8
|
+
throw new Error('Unable to load native addons in the browser!');
|
|
9
|
+
}
|
|
10
|
+
let wasm;
|
|
11
|
+
if (addon instanceof WebAssembly.Instance) {
|
|
12
|
+
wasm = addon;
|
|
13
|
+
}
|
|
14
|
+
else if (addon instanceof WebAssembly.Module) {
|
|
15
|
+
try {
|
|
16
|
+
wasm = (await WebAssembly.instantiate(addon));
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (!(err instanceof Error))
|
|
20
|
+
throw err;
|
|
21
|
+
throw new Error(`Could not instantiate WASM module!\n${err.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const name = `pkmn${showdown ? '-showdown' : ''}.wasm`;
|
|
26
|
+
try {
|
|
27
|
+
const response = !addon || addon === 'wasm' ? fetch(name)
|
|
28
|
+
: addon instanceof URL ? fetch(addon) : addon;
|
|
29
|
+
wasm = (await WebAssembly.instantiateStreaming(response)).instance;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (!(err instanceof Error))
|
|
33
|
+
throw err;
|
|
34
|
+
const message = !addon || addon === 'wasm'
|
|
35
|
+
? `Could not find ${name} - did you run \`npx install-pkmn-engine\`?`
|
|
36
|
+
: addon instanceof URL
|
|
37
|
+
? `Could not fetch WASM module from '${addon.href}'!`
|
|
38
|
+
: 'Could not instantiate WASM module!';
|
|
39
|
+
throw new Error(`${message}\n${err.message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return (0, wasm_1.toBindings)(wasm.exports);
|
|
43
|
+
}
|
|
44
|
+
function loadSync() {
|
|
45
|
+
throw new Error('You must `initialize` the WASM addon before using the engine!');
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../src/pkg/addon/browser.ts"],"names":[],"mappings":";;AAKA,oBAiCC;AAED,4BAEC;AAvCD,iCAAkC;AAE3B,KAAK,UAAU,IAAI,CAAC,QAAiB,EAAE,KAAgB;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,IAA0B,CAAC;IAC/B,IAAI,KAAK,YAAY,WAAW,CAAC,QAAQ,EAAE,CAAC;QAC1C,IAAI,GAAG,KAAK,CAAC;IACf,CAAC;SAAM,IAAI,KAAK,YAAY,WAAW,CAAC,MAAM,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AC,IAAI,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,QAAQ;IACtB,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.load = load;
|
|
37
|
+
exports.loadSync = loadSync;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const wasm_1 = require("./wasm");
|
|
41
|
+
const ROOT = path.join(__dirname, '..', '..', '..');
|
|
42
|
+
const LIB = path.join(ROOT, 'build', 'lib');
|
|
43
|
+
const NODE = [path.join(LIB, 'pkmn.node'), path.join(LIB, 'pkmn-showdown.node')];
|
|
44
|
+
const WASM = [path.join(LIB, 'pkmn.wasm'), path.join(LIB, 'pkmn-showdown.wasm')];
|
|
45
|
+
async function load(showdown, addon) {
|
|
46
|
+
if (addon === undefined || typeof addon === 'string' && addon !== 'wasm') {
|
|
47
|
+
try {
|
|
48
|
+
return require(!addon || addon === 'node' ? NODE[+showdown] : addon).engine;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (!(err instanceof Error))
|
|
52
|
+
return err;
|
|
53
|
+
if (addon && addon !== 'node') {
|
|
54
|
+
throw new Error(`Unable to load native addon: '${addon}'\n${err.message}`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw error(NODE[+showdown], err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let wasm;
|
|
62
|
+
if (addon === 'wasm') {
|
|
63
|
+
try {
|
|
64
|
+
wasm = (await WebAssembly.instantiate(fs.readFileSync(WASM[+showdown]))).instance;
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
throw error(WASM[+showdown], err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (addon instanceof WebAssembly.Instance) {
|
|
71
|
+
wasm = addon;
|
|
72
|
+
}
|
|
73
|
+
else if (addon instanceof WebAssembly.Module) {
|
|
74
|
+
try {
|
|
75
|
+
wasm = (await WebAssembly.instantiate(addon));
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (!(err instanceof Error))
|
|
79
|
+
throw err;
|
|
80
|
+
throw new Error(`Could not instantiate WASM module!\n${err.message}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
try {
|
|
85
|
+
const response = addon instanceof Promise ? addon : fetch(addon);
|
|
86
|
+
wasm = (await WebAssembly.instantiateStreaming(response)).instance;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (!(err instanceof Error))
|
|
90
|
+
throw err;
|
|
91
|
+
throw new Error(`Could not instantiate WASM module!\n${err.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return (0, wasm_1.toBindings)(wasm.exports);
|
|
95
|
+
}
|
|
96
|
+
function loadSync(showdown) {
|
|
97
|
+
try {
|
|
98
|
+
return require(NODE[+showdown]).engine;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function error(file, err) {
|
|
105
|
+
if (!(err instanceof Error))
|
|
106
|
+
return err;
|
|
107
|
+
const message = `Could not find ${path.basename(file)} addon`;
|
|
108
|
+
return new Error(`${message} - did you run \`npx install-pkmn-engine\`?\n${err.message}`);
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/pkg/addon/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,oBAyCC;AAED,4BAMC;AA9DD,uCAAyB;AACzB,2CAA6B;AAI7B,iCAAkC;AAElC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACpD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK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AI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,IAAY,EAAE,GAAY;IACvC,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IACxC,MAAM,OAAO,GAAG,kBAAkB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC9D,OAAO,IAAI,KAAK,CAAC,GAAG,OAAO,gDAAgD,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AAC5F,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBindings = toBindings;
|
|
4
|
+
const data_1 = require("../data");
|
|
5
|
+
function toBindings(w) {
|
|
6
|
+
const memory = new Uint8Array(w.memory.buffer);
|
|
7
|
+
return {
|
|
8
|
+
options: {
|
|
9
|
+
showdown: !!memory[w.SHOWDOWN.valueOf()],
|
|
10
|
+
log: !!memory[w.LOG.valueOf()],
|
|
11
|
+
chance: !!memory[w.CHANCE.valueOf()],
|
|
12
|
+
calc: !!memory[w.CALC.valueOf()],
|
|
13
|
+
},
|
|
14
|
+
bindings: [toBinding(1, w)],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function toBinding(gen, w) {
|
|
18
|
+
const prefix = `GEN${gen}`;
|
|
19
|
+
const buf = w.memory.buffer;
|
|
20
|
+
const constants = new Uint32Array(buf);
|
|
21
|
+
const CHOICES_SIZE = constants[w[`${prefix}_CHOICES_SIZE`].valueOf() / 4];
|
|
22
|
+
const LOGS_SIZE = constants[w[`${prefix}_LOGS_SIZE`].valueOf() / 4];
|
|
23
|
+
const size = data_1.LAYOUT[gen - 1].sizes.Battle;
|
|
24
|
+
const update = w[`${prefix}_update`];
|
|
25
|
+
const choices = w[`${prefix}_choices`];
|
|
26
|
+
const memory = new Uint8Array(buf);
|
|
27
|
+
return {
|
|
28
|
+
CHOICES_SIZE,
|
|
29
|
+
LOGS_SIZE,
|
|
30
|
+
update(battle, c1, c2, log) {
|
|
31
|
+
const bytes = new Uint8Array(battle);
|
|
32
|
+
memory.set(bytes, 0);
|
|
33
|
+
let result;
|
|
34
|
+
if (log) {
|
|
35
|
+
result = update(0, c1, c2, size);
|
|
36
|
+
new Uint8Array(log).set(memory.subarray(size, size + LOGS_SIZE));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
result = update(0, c1, c2, 0);
|
|
40
|
+
}
|
|
41
|
+
bytes.set(memory.subarray(0, size));
|
|
42
|
+
return result;
|
|
43
|
+
},
|
|
44
|
+
choices(battle, player, request, options) {
|
|
45
|
+
const opts = new Uint8Array(options);
|
|
46
|
+
memory.set(new Uint8Array(battle));
|
|
47
|
+
const n = choices(0, player, request, size);
|
|
48
|
+
opts.set(memory.subarray(size, size + n));
|
|
49
|
+
return n;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=wasm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.js","sourceRoot":"","sources":["../../../src/pkg/addon/wasm.ts"],"names":[],"mappings":";;AAGA,gCAWC;AAbD,kCAA+B;AAE/B,SAAgB,UAAU,CAAoB,CAAsB;IAClE,MAAM,MAAM,GAAG,IAAI,UAAU,CAAE,CAAC,CAAC,MAA6B,CAAC,MAAM,CAAC,CAAC;IACvE,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAM;YAC7C,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CA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