@pkmn/engine 0.1.0-dev.83de29ee → 0.1.0-dev.886adbe3
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 +97 -59
- package/build/pkg/addon.js +9 -9
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +26 -4
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/data.d.ts +4 -4
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +23 -18
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +5 -8
- package/build/pkg/index.js +2 -5
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +4 -2
- package/build/pkg/protocol.js +65 -44
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +10 -6
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +5 -4
- package/build/tools/debug.js.map +1 -1
- package/build.zig +286 -131
- package/package.json +56 -24
- package/src/bin/install-pkmn-engine +39 -24
- package/src/lib/common/array.zig +77 -0
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +19 -31
- package/src/lib/common/debug.zig +22 -13
- package/src/lib/common/js.zig +120 -0
- package/src/lib/common/optional.zig +71 -0
- package/src/lib/common/options.zig +11 -0
- package/src/lib/common/protocol.zig +911 -367
- package/src/lib/common/rational.zig +447 -0
- package/src/lib/common/rng.zig +31 -22
- package/src/lib/common/util.zig +61 -0
- package/src/lib/gen1/calc.zig +804 -0
- package/src/lib/gen1/chance.zig +1167 -0
- package/src/lib/gen1/data/moves.zig +202 -190
- package/src/lib/gen1/data/species.zig +5 -5
- package/src/lib/gen1/data/types.zig +10 -10
- package/src/lib/gen1/data.zig +94 -81
- package/src/lib/gen1/helpers.zig +143 -39
- package/src/lib/gen1/mechanics.zig +1134 -786
- package/src/lib/gen2/calc.zig +161 -0
- package/src/lib/gen2/chance.zig +902 -0
- package/src/lib/gen2/data/items.zig +14 -20
- package/src/lib/gen2/data/moves.zig +664 -570
- package/src/lib/gen2/data/species.zig +2 -2
- package/src/lib/gen2/data/types.zig +137 -34
- package/src/lib/gen2/data.zig +125 -86
- package/src/lib/gen2/generated.zig +806 -0
- package/src/lib/gen2/helpers.zig +54 -32
- package/src/lib/gen2/mechanics.zig +3564 -15
- package/src/lib/node.zig +131 -0
- package/src/lib/pkmn.zig +81 -5
- package/src/lib/wasm.zig +13 -0
- package/src/test/display/pkmn.html.tmpl +5 -5
- package/src/lib/binding/node.zig +0 -229
- package/src/lib/binding/wasm.zig +0 -10
- package/src/lib/gen1/README.md +0 -808
- package/src/lib/gen2/README.md +0 -309
package/LICENSE
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021-2023 pkmn contributors
|
|
1
|
+
Copyright (c) 2021-2024 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,21 @@
|
|
|
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 (code from the
|
|
20
|
+
> [`old`](https://github.com/pkmn/engine/releases/tag/old) tag can also be used to experiment with a
|
|
21
|
+
> more stable version of the codebase).
|
|
22
|
+
|
|
15
23
|
<hr />
|
|
16
24
|
|
|
17
25
|
A minimal, complete, Pokémon battle simulation engine optimized for performance and
|
|
18
26
|
[designed](docs/DESIGN.md) for tooling, embedded systems, and [artificial
|
|
19
27
|
intelligence](https://github.com/pkmn/0-ERROR) use cases. This engine aims to be a frame-accurate and
|
|
20
28
|
[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
|
|
29
|
+
implementation of both Pokémon battles as defined by the original game code and the [Pokémon
|
|
22
30
|
Showdown](https://pokemonshowdown.com/)[^1] simulator which represents Pokémon battling as practically
|
|
23
31
|
interpreted online.
|
|
24
32
|
|
|
@@ -49,9 +57,11 @@ $ zig build --prefix /usr/local -Doptimize=ReleaseFast
|
|
|
49
57
|
```
|
|
50
58
|
|
|
51
59
|
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.11.0
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
walk through how to install Zig on each platform - the engine code should work on Zig v0.11.0,
|
|
61
|
+
though tracks Zig's master branch so this may change in the future if breaking language changes are
|
|
62
|
+
introduced. Note that **due to a [bug in the Zig
|
|
63
|
+
compiler](https://github.com/ziglang/zig/issues/17768), compiling with a version of Zig before
|
|
64
|
+
`0.12.0-dev.876+aaf46187a` is recommended for performance**.
|
|
55
65
|
|
|
56
66
|
`libpkmn` can be built with `-Dshowdown` to instead produce the Pokémon Showdown compatible
|
|
57
67
|
`libpkmn-showdown` library. Furthermore, protocol message logging can be enabled through `-Dlog`.
|
|
@@ -67,40 +77,65 @@ $ npm install @pkmn/engine
|
|
|
67
77
|
```
|
|
68
78
|
|
|
69
79
|
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
|
-
|
|
80
|
+
`node_modules/@pkmn/engine/build/lib` to be useful. When you install the package a [`postinstall`
|
|
81
|
+
lifecycle script](https://docs.npmjs.com/cli/v8/using-npm/scripts) runs
|
|
82
|
+
[`install-pkmn-engine`](src/bin/install-pkmn-engine) which checks for a compatible `zig` compiler
|
|
83
|
+
(see earlier regarding minimum version) and download one to `node_module/@pkmn/engine/build/bin` if
|
|
84
|
+
it can't find one, as well as looking for (and downloading, if necessary) the required Node headers
|
|
85
|
+
needed to successfully build the addons natively.
|
|
76
86
|
|
|
77
87
|
**If you have configured `npm` to `--ignore-scripts` you must either run `npx install-pkmn-engine`
|
|
78
88
|
directly or build the addons manually and place the artifacts in the expected paths.**
|
|
79
89
|
|
|
80
90
|
### `pkmn`
|
|
81
91
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
To include `pkmn`, add it as a dependency in your project's
|
|
93
|
+
[`build.zig.zon`](https://github.com/ziglang/zig/blob/master/doc/build.zig.zon.md) using [Zig's
|
|
94
|
+
Package Management
|
|
95
|
+
system](https://ziglang.org/download/0.11.0/release-notes.html#Package-Management):
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
```zig
|
|
99
|
+
.dependencies = .{
|
|
100
|
+
.pkmn = .{
|
|
101
|
+
.url = "https://github.com/pkmn/engine/archive/RELEASE.tar.gz",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Replace `RELEASE` with the tag for the [release](https://github.com/pkmn/engine/releases) you wish
|
|
107
|
+
to use (e.g. `0.1.0` or `nightly`) or the specific hash of any commit. Next, run `zig build` and
|
|
108
|
+
copy the expected hash from the error message into your `build.zig.zon` alongside the `.url`:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
$ zig build
|
|
112
|
+
error: dependency is missing hash field
|
|
113
|
+
.url = "https://github.com/pkmn/engine/archive/nightly.tar.gz",
|
|
114
|
+
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
115
|
+
note: expected .hash = "122056b93b403033cb7d9bed96a02c2eb8cc1275515976167726ada6eb4207e8ef8a",
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Note that this hash is **not** going to be the same as the commit hash. After adding the hash to
|
|
119
|
+
your `build.zig.zon` you will be able to import the `pkmn` package's build helpers into your
|
|
120
|
+
`build.zig`:
|
|
86
121
|
|
|
87
122
|
```zig
|
|
88
123
|
const std = @import("std");
|
|
89
|
-
const pkmn = @import("lib/pkmn/build.zig");
|
|
90
124
|
|
|
91
|
-
pub fn build(b: *std.
|
|
125
|
+
pub fn build(b: *std.Build) void {
|
|
92
126
|
...
|
|
93
|
-
|
|
127
|
+
const pkmn = b.dependency("pkmn", .{ .showdown = true, .log = true });
|
|
128
|
+
exe.root_module.addImport("pkmn", pkmn.module("pkmn"));
|
|
94
129
|
...
|
|
95
130
|
}
|
|
96
131
|
```
|
|
97
132
|
|
|
98
|
-
The
|
|
99
|
-
|
|
100
|
-
|
|
133
|
+
The `pkmn` package can be configured with various options such as whether or not Pokémon Showdown
|
|
134
|
+
compatibility mode or protocol message logging should be enabled. Alternatively, you may set options
|
|
135
|
+
via a `pkmn_options` [root source file
|
|
101
136
|
declaration](https://ziglang.org/documentation/master/#Root-Source-File). There are several
|
|
102
137
|
undocumented internal options that can be tweaked as well via build or root options, though these
|
|
103
|
-
options
|
|
138
|
+
options aren't officially supported, affect correctness, and may change meaning or behavior without
|
|
104
139
|
warning. Use at your own risk.
|
|
105
140
|
|
|
106
141
|
```zig
|
|
@@ -112,11 +147,11 @@ pub const pkmn_options = .{ .showdown = true, .log = true };
|
|
|
112
147
|
For each Pokémon generation, the engine provides a battle structure with two functions - a function
|
|
113
148
|
to `update` the battle's state based on both players' choices and a function that defines which
|
|
114
149
|
`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
|
-
|
|
150
|
+
as their first choice to switch in the first member of their party). If `-Dlog` protocol logging is
|
|
151
|
+
enabled each update produces logs which can be decoded into a buffer (`LOGS_SIZE` constants are
|
|
152
|
+
provided to make it easy to allocate a buffer of the correct size). Each `update` returns a result
|
|
153
|
+
to indicate either that the battle has terminated or which types of choices are available for each
|
|
154
|
+
player.
|
|
120
155
|
|
|
121
156
|
Unlike [Pokémon Showdown's
|
|
122
157
|
SIM-PROTOCOL](https://github.com/smogon/pokemon-showdown/blob/master/sim/SIM-PROTOCOL.md#choice-requests)
|
|
@@ -128,47 +163,50 @@ state or cause the engine to crash.**
|
|
|
128
163
|
|
|
129
164
|
Battles may be played out from any point but to freshly initialize a battle which is yet to start
|
|
130
165
|
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
|
|
166
|
+
Most driver code should also provide helpers to make initializing battle convenient - check the
|
|
132
167
|
respective documentation and examples for the bindings being used. The engine's [protocol
|
|
133
168
|
documentation](docs/PROTOCOL.md) goes into greater detail on the specifics of updates and the
|
|
134
169
|
potential logs that may result.
|
|
135
170
|
|
|
136
171
|
*The snippets below are meant to merely illustrate in broad strokes how the pkmn engine can be used
|
|
137
|
-
\- the [`examples`](
|
|
172
|
+
\- the [`examples`](examples) directory contains fully commented and runnable code.*
|
|
138
173
|
|
|
139
174
|
### C
|
|
140
175
|
|
|
141
176
|
[`pkmn.h`](src/include/pkmn.h) exports the C API for `libpkmn`. Symbols are all prefixed with
|
|
142
177
|
`pkmn_` to avoid name collisions. If `-Dlog` is enabled and logging throws an error then the error
|
|
143
|
-
|
|
178
|
+
is encoded in the `pkmn_result` and can be checked with `pkmn_error`.
|
|
144
179
|
|
|
145
180
|
```c
|
|
146
181
|
#include <pkmn.h>
|
|
147
182
|
|
|
183
|
+
pkmn_battle_options options;
|
|
184
|
+
pkmn_gen1_battle_options_set(&options, ...);
|
|
148
185
|
pkmn_battle battle = ...;
|
|
149
|
-
|
|
186
|
+
|
|
150
187
|
pkmn_result result;
|
|
151
188
|
pkmn_choice c1 = 0, c2 = 0;
|
|
152
|
-
while (!pkmn_result_type(result = pkmn_battle_update(&battle, c1, c2,
|
|
189
|
+
while (!pkmn_result_type(result = pkmn_battle_update(&battle, c1, c2, &options))) {
|
|
153
190
|
c1 = choose(PKMN_PLAYER_P1, pkmn_result_p1(result));
|
|
154
191
|
c2 = choose(PKMN_PLAYER_P2, pkmn_result_p2(result));
|
|
192
|
+
pkmn_gen1_battle_options_set(&options, ...);
|
|
155
193
|
}
|
|
156
194
|
if (pkmn_error(result)) exit(1);
|
|
157
195
|
```
|
|
158
196
|
|
|
159
|
-
[(full code)](
|
|
197
|
+
[(full code)](examples/c/example.c)
|
|
160
198
|
|
|
161
|
-
The C API
|
|
199
|
+
The C API doesn't export any helpers for creating or accessing the opaque battle objects - it's
|
|
162
200
|
instead intended to be used as the foundation for more ergonomic bindings in [other
|
|
163
201
|
languages](#other) (the lack of namespaces and bit fields having an implementation-defined layout in
|
|
164
202
|
C are the main contributing factors to the sparseness of what `libpkmn` chooses to expose).
|
|
165
203
|
|
|
166
204
|
### JavaScript / TypeScript
|
|
167
205
|
|
|
168
|
-
`@pkmn/engine` depends on the [`@pkmn/data`](https://www.npmjs.com/package/@pkmn/data) which
|
|
206
|
+
`@pkmn/engine` depends on the [`@pkmn/data`](https://www.npmjs.com/package/@pkmn/data) package which
|
|
169
207
|
requires a `Dex` implementation to be provided as well. The `Battle.create` function can be used to
|
|
170
208
|
initialize a `Battle` from the beginning, or `Battle.restore` can be used to re-instantiate a battle
|
|
171
|
-
which is in
|
|
209
|
+
which is already in progress. If logging is enabled the output can be turned into Pokémon Showdown
|
|
172
210
|
protocol via `Log.parse`.
|
|
173
211
|
|
|
174
212
|
```ts
|
|
@@ -191,20 +229,20 @@ while (!(result = battle.update(c1, c2)).type) {
|
|
|
191
229
|
console.log(result);
|
|
192
230
|
```
|
|
193
231
|
|
|
194
|
-
[(full code)](
|
|
232
|
+
[(full code)](examples/js/example.ts)
|
|
195
233
|
|
|
196
|
-
By default, the `@pkmn/engine` package
|
|
234
|
+
By default, the `@pkmn/engine` package compiles the engine with `-Dshowdown`, though by running
|
|
197
235
|
`install-pkmn-engine` directly and passing in `--options` you can override this default and build
|
|
198
236
|
different configurations of the extension for the driver to use. The driver can support
|
|
199
237
|
configurations both with and without Pokémon Showdown compatibility simultaneously if present. On
|
|
200
|
-
update, the post-install script
|
|
238
|
+
update, the post-install script attempts to rebuild whichever extensions it finds with the same
|
|
201
239
|
configuration parameters that were originally used meaning updating to the newest version of the
|
|
202
240
|
library should be seamless.
|
|
203
241
|
|
|
204
242
|
Despite relying on the native engine code, the `@pkmn/engine` code is designed to also work in
|
|
205
243
|
browsers which support [WebAssembly](https://webassembly.org/). Running `npm run start:web` from the
|
|
206
|
-
[`examples`](
|
|
207
|
-
|
|
244
|
+
[`examples`](examples/js) directory starts a server that can be used to demonstrate the engine
|
|
245
|
+
running in the browser.
|
|
208
246
|
|
|
209
247
|
### Zig
|
|
210
248
|
|
|
@@ -215,17 +253,17 @@ be used when logging is enabled to allow for easily printing e.g. to standard ou
|
|
|
215
253
|
const std = @import("std");
|
|
216
254
|
const pkmn = @import("pkmn");
|
|
217
255
|
|
|
218
|
-
var random = std.
|
|
256
|
+
var random = std.Random.DefaultPrng.init(seed).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
262
|
var c1 = pkmn.Choice{};
|
|
225
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,7 +314,7 @@ 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
|
|
@@ -298,14 +336,14 @@ Currently, most of the foundational work from stage 0 is done:
|
|
|
298
336
|
|
|
299
337
|
- [benchmark and integration testing](src/test) infrastructure
|
|
300
338
|
- [documentation](docs) about design, research, methodology, etc
|
|
301
|
-
- definition and implementation of the [protocol](docs/PROTOCOL.md) that
|
|
339
|
+
- definition and implementation of the [protocol](docs/PROTOCOL.md) that's used by the engine
|
|
302
340
|
|
|
303
|
-
**Stage 1 is currently in progress** and
|
|
341
|
+
**Stage 1 is currently in progress** and involves the implementation of the actual Generation I & II
|
|
304
342
|
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
|
-
|
|
343
|
+
generations is in scope for the project but shouldn't be considered part of the immediate roadmap
|
|
344
|
+
(i.e. exploring the options for broadening support for old generation APIs is given higher priority
|
|
345
|
+
than implementing more modern generations). Furthermore, implementation of modern generations is
|
|
346
|
+
soft-blocked on the [availability of high quality
|
|
309
347
|
decompilations](https://github.com/orgs/pret/repositories) of the original games in question.
|
|
310
348
|
|
|
311
349
|
Certain features will always be deemed **out of scope**:
|
|
@@ -323,10 +361,10 @@ The pkmn engine is distributed under the terms of the [MIT License](LICENSE).
|
|
|
323
361
|
[^1]: In the case of Pokémon Showdown, only bugs which stem from a misimplementation of specific
|
|
324
362
|
effects are reproduced in the engine, bugs which are the result of a misunderstanding of the
|
|
325
363
|
fundamental mechanics of Pokémon or which simply arise due to specific Pokémon Showdown
|
|
326
|
-
implementation details that
|
|
327
|
-
choices
|
|
364
|
+
implementation details that aren't replicable without making the same (incorrect) architectural
|
|
365
|
+
choices aren't. Furthermore, the "Pokémon Showdown" code referenced by this project includes
|
|
328
366
|
several [patches](docs/TESTING.md#patches) to improve accuracy and smooth over some of the more
|
|
329
367
|
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
|
|
368
|
+
pkmn engine's compatibility mode and on this patched Pokémon Showdown simulator are the same,
|
|
369
|
+
it's only in a well defined and documented set of circumstances where the two implementations
|
|
332
370
|
diverge.
|
package/build/pkg/addon.js
CHANGED
|
@@ -23,7 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.check = check;
|
|
27
|
+
exports.supports = supports;
|
|
28
|
+
exports.update = update;
|
|
29
|
+
exports.choices = choices;
|
|
30
|
+
exports.choose = choose;
|
|
31
|
+
exports.size = size;
|
|
27
32
|
const path = __importStar(require("path"));
|
|
28
33
|
const _1 = require(".");
|
|
29
34
|
const ROOT = path.join(__dirname, '..', '..');
|
|
@@ -34,11 +39,12 @@ function load() {
|
|
|
34
39
|
let pkmn = undefined;
|
|
35
40
|
let showdown = undefined;
|
|
36
41
|
try {
|
|
37
|
-
pkmn = require(path.join(ROOT, 'build', 'lib', 'pkmn.node'));
|
|
42
|
+
pkmn = require(path.join(ROOT, 'build', 'lib', 'pkmn.node')).engine;
|
|
38
43
|
}
|
|
39
44
|
catch { }
|
|
40
45
|
try {
|
|
41
|
-
showdown =
|
|
46
|
+
showdown =
|
|
47
|
+
require(path.join(ROOT, 'build', 'lib', 'pkmn-showdown.node')).engine;
|
|
42
48
|
}
|
|
43
49
|
catch { }
|
|
44
50
|
if (!pkmn && !showdown) {
|
|
@@ -55,7 +61,6 @@ function check(showdown) {
|
|
|
55
61
|
`\n(running \`npx install-pkmn-engine --options='${opts.join(' ')}'\` can fix this issue).`);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
|
-
exports.check = check;
|
|
59
64
|
function supports(showdown, log) {
|
|
60
65
|
if (!load()[+showdown])
|
|
61
66
|
return false;
|
|
@@ -63,12 +68,10 @@ function supports(showdown, log) {
|
|
|
63
68
|
return true;
|
|
64
69
|
return ADDON[+showdown].options.log === log;
|
|
65
70
|
}
|
|
66
|
-
exports.supports = supports;
|
|
67
71
|
function update(index, showdown, battle, c1, c2, log) {
|
|
68
72
|
return _1.Result.decode(ADDON[+showdown].bindings[index]
|
|
69
73
|
.update(battle, _1.Choice.encode(c1), _1.Choice.encode(c2), log));
|
|
70
74
|
}
|
|
71
|
-
exports.update = update;
|
|
72
75
|
function choices(index, showdown, battle, player, choice, buf) {
|
|
73
76
|
const request = choice[0] === 'p' ? 0 : choice[0] === 'm' ? 1 : 2;
|
|
74
77
|
const n = ADDON[+showdown].bindings[index].choices(battle, +(player !== 'p1'), request, buf);
|
|
@@ -95,17 +98,14 @@ function choices(index, showdown, battle, player, choice, buf) {
|
|
|
95
98
|
options[i] = _1.Choice.decode(data[i]);
|
|
96
99
|
return options;
|
|
97
100
|
}
|
|
98
|
-
exports.choices = choices;
|
|
99
101
|
function choose(index, showdown, battle, player, choice, buf, fn) {
|
|
100
102
|
const request = choice[0] === 'p' ? 0 : choice[0] === 'm' ? 1 : 2;
|
|
101
103
|
const n = ADDON[+showdown].bindings[index].choices(battle, +(player !== 'p1'), request, buf);
|
|
102
104
|
const data = new Uint8Array(buf);
|
|
103
105
|
return _1.Choice.decode(data[fn(n)]);
|
|
104
106
|
}
|
|
105
|
-
exports.choose = choose;
|
|
106
107
|
function size(index, type) {
|
|
107
108
|
const bindings = (ADDON[1] ?? ADDON[0]).bindings[index];
|
|
108
109
|
return type[0] === 'c' ? bindings.CHOICES_SIZE : bindings.LOGS_SIZE;
|
|
109
110
|
}
|
|
110
|
-
exports.size = size;
|
|
111
111
|
//# sourceMappingURL=addon.js.map
|
package/build/pkg/addon.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addon.js","sourceRoot":"","sources":["../../src/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AC,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,SAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,IAAI,CAAC,KAAa,EAAE,IAAuB;IACzD,MAAM,QAAQ,GAAG,CAAC,KAAM,CAAC,CAAC,CAAC,IAAI,KAAM,CAAC,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;AACtE,CAAC"}
|
package/build/pkg/data/ids.json
CHANGED
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
"types": [
|
|
23
|
+
"Ground",
|
|
24
|
+
"Rock",
|
|
25
|
+
"Steel",
|
|
23
26
|
"Normal",
|
|
24
27
|
"Fighting",
|
|
25
28
|
"Flying",
|
|
26
29
|
"Poison",
|
|
27
|
-
"Ground",
|
|
28
|
-
"Rock",
|
|
29
30
|
"Bug",
|
|
30
31
|
"Ghost",
|
|
31
|
-
"Steel",
|
|
32
32
|
"???",
|
|
33
33
|
"Fire",
|
|
34
34
|
"Water",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"Dark"
|
|
41
41
|
],
|
|
42
42
|
"items": [
|
|
43
|
+
"softsand",
|
|
44
|
+
"hardstone",
|
|
45
|
+
"metalcoat",
|
|
43
46
|
"pinkbow",
|
|
44
47
|
"blackbelt",
|
|
45
48
|
"sharpbeak",
|
|
46
49
|
"poisonbarb",
|
|
47
|
-
"softsand",
|
|
48
|
-
"hardstone",
|
|
49
50
|
"silverpowder",
|
|
50
51
|
"spelltag",
|
|
51
|
-
"metalcoat",
|
|
52
52
|
"polkadotbow",
|
|
53
53
|
"charcoal",
|
|
54
54
|
"mysticwater",
|
|
@@ -65,21 +65,21 @@
|
|
|
65
65
|
"stick",
|
|
66
66
|
"thickclub",
|
|
67
67
|
"focusband",
|
|
68
|
-
"berryjuice",
|
|
69
68
|
"scopelens",
|
|
70
69
|
"leftovers",
|
|
71
70
|
"berserkgene",
|
|
72
71
|
"lightball",
|
|
72
|
+
"berry",
|
|
73
|
+
"berryjuice",
|
|
74
|
+
"goldberry",
|
|
75
|
+
"mintberry",
|
|
73
76
|
"psncureberry",
|
|
74
77
|
"przcureberry",
|
|
75
|
-
"burntberry",
|
|
76
78
|
"iceberry",
|
|
77
|
-
"
|
|
78
|
-
"mintberry",
|
|
79
|
+
"burntberry",
|
|
79
80
|
"miracleberry",
|
|
81
|
+
"bitterberry",
|
|
80
82
|
"mysteryberry",
|
|
81
|
-
"berry",
|
|
82
|
-
"goldberry",
|
|
83
83
|
"masterball",
|
|
84
84
|
"ultraball",
|
|
85
85
|
"greatball",
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
"Battle": 384,
|
|
5
5
|
"Side": 184,
|
|
6
6
|
"Pokemon": 24,
|
|
7
|
-
"ActivePokemon": 32
|
|
7
|
+
"ActivePokemon": 32,
|
|
8
|
+
"Actions": 16,
|
|
9
|
+
"Summaries": 12
|
|
8
10
|
},
|
|
9
11
|
"offsets": {
|
|
10
12
|
"Battle": {
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
"turn": 368,
|
|
13
15
|
"last_damage": 370,
|
|
14
16
|
"last_moves": 372,
|
|
15
|
-
"rng":
|
|
17
|
+
"rng": 374
|
|
16
18
|
},
|
|
17
19
|
"Side": {
|
|
18
20
|
"pokemon": 0,
|
|
@@ -77,9 +79,29 @@
|
|
|
77
79
|
"state": 24,
|
|
78
80
|
"substitute": 40,
|
|
79
81
|
"transform": 48,
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
+
"disable_duration": 52,
|
|
83
|
+
"disable_move": 56,
|
|
82
84
|
"toxic": 59
|
|
85
|
+
},
|
|
86
|
+
"Action": {
|
|
87
|
+
"damage": 0,
|
|
88
|
+
"hit": 8,
|
|
89
|
+
"critical_hit": 10,
|
|
90
|
+
"secondary_chance": 12,
|
|
91
|
+
"speed_tie": 14,
|
|
92
|
+
"confused": 16,
|
|
93
|
+
"paralyzed": 18,
|
|
94
|
+
"duration": 20,
|
|
95
|
+
"durations": 24,
|
|
96
|
+
"move_slot": 40,
|
|
97
|
+
"multi_hit": 44,
|
|
98
|
+
"psywave": 48,
|
|
99
|
+
"metronome": 56
|
|
100
|
+
},
|
|
101
|
+
"Damage": {
|
|
102
|
+
"base": 0,
|
|
103
|
+
"final": 2,
|
|
104
|
+
"capped": 4
|
|
83
105
|
}
|
|
84
106
|
}
|
|
85
107
|
}
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
"Burst",
|
|
71
71
|
"ClearPositiveBoost",
|
|
72
72
|
"CanDynamax",
|
|
73
|
-
"SwapSideConditions"
|
|
73
|
+
"SwapSideConditions",
|
|
74
|
+
"Terastallize"
|
|
74
75
|
],
|
|
75
76
|
"Move": [
|
|
76
77
|
"None",
|
|
@@ -84,12 +85,14 @@
|
|
|
84
85
|
"Flinch",
|
|
85
86
|
"Disable",
|
|
86
87
|
"Recharge",
|
|
87
|
-
"PP"
|
|
88
|
+
"PP",
|
|
89
|
+
"Attract"
|
|
88
90
|
],
|
|
89
91
|
"Heal": [
|
|
90
92
|
"None",
|
|
91
93
|
"Silent",
|
|
92
|
-
"Drain"
|
|
94
|
+
"Drain",
|
|
95
|
+
"Leftovers"
|
|
93
96
|
],
|
|
94
97
|
"Damage": [
|
|
95
98
|
"None",
|
|
@@ -97,7 +100,13 @@
|
|
|
97
100
|
"Burn",
|
|
98
101
|
"Confusion",
|
|
99
102
|
"LeechSeed",
|
|
100
|
-
"RecoilOf"
|
|
103
|
+
"RecoilOf",
|
|
104
|
+
"Bind",
|
|
105
|
+
"Wrap",
|
|
106
|
+
"FireSpin",
|
|
107
|
+
"Clamp",
|
|
108
|
+
"Whirlpool",
|
|
109
|
+
"Spikes"
|
|
101
110
|
],
|
|
102
111
|
"Status": [
|
|
103
112
|
"None",
|
|
@@ -136,7 +145,15 @@
|
|
|
136
145
|
"Mist",
|
|
137
146
|
"Struggle",
|
|
138
147
|
"Substitute",
|
|
139
|
-
"Splash"
|
|
148
|
+
"Splash",
|
|
149
|
+
"Attract",
|
|
150
|
+
"LockOn",
|
|
151
|
+
"Bind",
|
|
152
|
+
"Wrap",
|
|
153
|
+
"FireSpin",
|
|
154
|
+
"Clamp",
|
|
155
|
+
"Whirlpool",
|
|
156
|
+
"BeatUp"
|
|
140
157
|
],
|
|
141
158
|
"Start": [
|
|
142
159
|
"Bide",
|
|
@@ -150,24 +167,64 @@
|
|
|
150
167
|
"Substitute",
|
|
151
168
|
"TypeChange",
|
|
152
169
|
"Disable",
|
|
153
|
-
"Mimic"
|
|
170
|
+
"Mimic",
|
|
171
|
+
"Nightmare",
|
|
172
|
+
"Curse",
|
|
173
|
+
"Foresight",
|
|
174
|
+
"Encore",
|
|
175
|
+
"FutureSight",
|
|
176
|
+
"PerishSong3Silent",
|
|
177
|
+
"PerishSong3",
|
|
178
|
+
"PerishSong2",
|
|
179
|
+
"PerishSong1",
|
|
180
|
+
"PerishSong0"
|
|
154
181
|
],
|
|
155
182
|
"End": [
|
|
156
183
|
"Disable",
|
|
157
184
|
"Confusion",
|
|
158
185
|
"Bide",
|
|
159
186
|
"Substitute",
|
|
187
|
+
"Nightmare",
|
|
188
|
+
"Curse",
|
|
189
|
+
"Foresight",
|
|
190
|
+
"Encore",
|
|
191
|
+
"FutureSight",
|
|
192
|
+
"LeechSeed",
|
|
193
|
+
"Bind",
|
|
194
|
+
"Wrap",
|
|
195
|
+
"FireSpin",
|
|
196
|
+
"Clamp",
|
|
197
|
+
"Whirlpool",
|
|
160
198
|
"DisableSilent",
|
|
161
199
|
"ConfusionSilent",
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
200
|
+
"MistSilent",
|
|
201
|
+
"FocusEnergySilent",
|
|
202
|
+
"LeechSeedSilent",
|
|
203
|
+
"ToxicSilent",
|
|
204
|
+
"LightScreenSilent",
|
|
205
|
+
"ReflectSilent",
|
|
206
|
+
"BideSilent"
|
|
168
207
|
],
|
|
169
208
|
"Immune": [
|
|
170
209
|
"None",
|
|
171
210
|
"OHKO"
|
|
211
|
+
],
|
|
212
|
+
"EndItem": [
|
|
213
|
+
"None",
|
|
214
|
+
"Eat"
|
|
215
|
+
],
|
|
216
|
+
"SetHP": [
|
|
217
|
+
"None",
|
|
218
|
+
"Silent"
|
|
219
|
+
],
|
|
220
|
+
"Side": [
|
|
221
|
+
"Safeguard",
|
|
222
|
+
"Reflect",
|
|
223
|
+
"LightScreen",
|
|
224
|
+
"Spikes"
|
|
225
|
+
],
|
|
226
|
+
"Weather": [
|
|
227
|
+
"None",
|
|
228
|
+
"Upkeep"
|
|
172
229
|
]
|
|
173
230
|
}
|