mons-rules 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -56
- package/dist/mons-rules.js +1 -1
- package/package.json +4 -3
- package/MIGRATION.md +0 -219
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mons-rules",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "TypeScript rules engine for Super Metal Mons",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"dist/api/types.d.ts",
|
|
19
19
|
"dist/api/winner.d.ts",
|
|
20
20
|
"LICENSE",
|
|
21
|
-
"README.md"
|
|
22
|
-
"MIGRATION.md"
|
|
21
|
+
"README.md"
|
|
23
22
|
],
|
|
24
23
|
"main": "./dist/mons-rules.js",
|
|
25
24
|
"types": "./dist/entrypoints/mons-rules.d.ts",
|
|
@@ -31,6 +30,8 @@
|
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
"scripts": {
|
|
33
|
+
"benchmark:browser": "node ./scripts/run-benchmarks.mjs --browser",
|
|
34
|
+
"benchmark:node": "node ./scripts/run-benchmarks.mjs --node",
|
|
34
35
|
"build": "npm run clean && tsc -p tsconfig.build.json && esbuild ./src/entrypoints/mons-rules.ts --bundle --format=esm --platform=browser --target=es2020 --minify --keep-names --legal-comments=none --outfile=./dist/mons-rules.js",
|
|
35
36
|
"bump": "npm version patch --no-git-tag-version",
|
|
36
37
|
"check": "npm run format:check && npm run lint && npm run typecheck && npm test && ./scripts/run-rules-tests.sh && npm run test:complete-games && npm run check:corpora && npm run build && node ./scripts/check-package.mjs .",
|
package/MIGRATION.md
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
# Migrating from 0.2 to 0.3
|
|
2
|
-
|
|
3
|
-
Version 0.3 intentionally removes the Rust/Wasm compatibility layer. The new
|
|
4
|
-
API uses ordinary TypeScript classes, plain readonly objects, string
|
|
5
|
-
discriminants, camelCase names, and structured results. There is no CommonJS
|
|
6
|
-
entrypoint or compatibility shim.
|
|
7
|
-
|
|
8
|
-
## Import and construct a game
|
|
9
|
-
|
|
10
|
-
0.2:
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
import { GameVariant, Location, MonsGameModel } from "mons-rules";
|
|
14
|
-
const game = MonsGameModel.new(GameVariant.Classic);
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
0.3:
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import {
|
|
21
|
-
AutomovePreference,
|
|
22
|
-
Game,
|
|
23
|
-
GameVariant,
|
|
24
|
-
Modifier,
|
|
25
|
-
resolveMatch,
|
|
26
|
-
} from "mons-rules";
|
|
27
|
-
const game = new Game({ variant: GameVariant.Classic });
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
`GameVariant`, `Color`, `MonKind`, `Consumable`, and `Modifier` are now frozen
|
|
31
|
-
string-valued const objects with matching union types. Persist their string
|
|
32
|
-
values, not the old numeric ordinals.
|
|
33
|
-
|
|
34
|
-
CommonJS consumers must migrate to ESM:
|
|
35
|
-
|
|
36
|
-
Removed:
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
const rules = require("mons-rules");
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
0.3:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
import * as rules from "mons-rules";
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Game method mapping
|
|
49
|
-
|
|
50
|
-
| 0.2 | 0.3 |
|
|
51
|
-
| ----------------------------------------- | ------------------------------------------------------------ |
|
|
52
|
-
| `MonsGameModel.new(variant)` | `new Game({ variant })` |
|
|
53
|
-
| `MonsGameModel.from_fen(fen)` | `Game.fromFen(fen)` |
|
|
54
|
-
| `game.fen()` | `game.toFen()` |
|
|
55
|
-
| `game.active_color()` | `game.activeColor` |
|
|
56
|
-
| `game.turn_number()` | `game.turnNumber` |
|
|
57
|
-
| `game.white_score()` | `game.scores[Color.White]` |
|
|
58
|
-
| `game.black_score()` | `game.scores[Color.Black]` |
|
|
59
|
-
| `game.winner_color()` | `game.winner` |
|
|
60
|
-
| `game.is_moves_verified()` | `game.historyVerified` |
|
|
61
|
-
| `game.takeback_fens()` | `game.takebackFens` |
|
|
62
|
-
| `game.verbose_tracking_entities()` | `game.trackingEntries` |
|
|
63
|
-
| `game.process_input_fen(fen)` | `game.previewFen(fen)` or `game.playFen(fen)` |
|
|
64
|
-
| `game.process_input(locations, modifier)` | `game.preview(inputs)` or `game.play(inputs)` |
|
|
65
|
-
| `game.item(location)` | `game.itemAt(position)` |
|
|
66
|
-
| `game.square(location)` | `game.squareAt(position)` |
|
|
67
|
-
| `game.locations_with_content()` | `game.contentPositions()` |
|
|
68
|
-
| `game.can_takeback(color)` | `game.canTakeback(color)` |
|
|
69
|
-
| `game.takeback()` | `game.takeback()` |
|
|
70
|
-
| `game.without_last_turn(fens)` | `game.previousTurn(fens)` |
|
|
71
|
-
| `game.verify_moves(white, black)` | `game.verifyHistory({ white, black })` |
|
|
72
|
-
| `game.is_later_than(otherFen)` | `game.isLaterThan(otherGame)` |
|
|
73
|
-
| `game.available_move_kinds()` | `game.availableMoveCounts()` |
|
|
74
|
-
| `game.smartAutomove(mode)` | `game.suggestMove(AutomovePreference.Fast \| Normal \| Pro)` |
|
|
75
|
-
| `game.automove()` | `game.suggestMove(AutomovePreference.Random)` |
|
|
76
|
-
| `game.clearTracking()` | `game.clearTracking()` |
|
|
77
|
-
|
|
78
|
-
Every `suggestMove` call is source-pure. In 0.2, `game.automove()` applied its
|
|
79
|
-
random move to the game; in 0.3, apply a returned suggestion explicitly:
|
|
80
|
-
|
|
81
|
-
```ts
|
|
82
|
-
const suggestion = game.suggestMove(AutomovePreference.Random);
|
|
83
|
-
if (suggestion !== undefined) {
|
|
84
|
-
game.play(suggestion.inputs);
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
`verifyHistory` takes arrays of per-turn input FEN strings. Convert the old
|
|
89
|
-
dash-separated arguments before calling it:
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
game.verifyHistory({
|
|
93
|
-
white: oldWhiteMoves === "" ? [] : oldWhiteMoves.split("-"),
|
|
94
|
-
black: oldBlackMoves === "" ? [] : oldBlackMoves.split("-"),
|
|
95
|
-
});
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
`isLaterThan` now requires a validated `Game` instead of silently accepting an
|
|
99
|
-
invalid FEN:
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
const other = Game.fromFen(otherFen);
|
|
103
|
-
const later = other === undefined ? undefined : game.isLaterThan(other);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Inputs and positions
|
|
107
|
-
|
|
108
|
-
`Location` and `Modifier` arguments are replaced by plain `Input` values:
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
// 0.2
|
|
112
|
-
game.process_input([new Location(10, 5), new Location(9, 4)]);
|
|
113
|
-
|
|
114
|
-
// 0.3
|
|
115
|
-
game.play([
|
|
116
|
-
{ kind: "position", position: { row: 10, column: 5 } },
|
|
117
|
-
{ kind: "position", position: { row: 9, column: 4 } },
|
|
118
|
-
]);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Coordinate fields changed from `i`/`j` to `row`/`column`. Potion and bomb
|
|
122
|
-
selection are explicit input values:
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
{ kind: "modifier", modifier: Modifier.SelectPotion }
|
|
126
|
-
{ kind: "modifier", modifier: Modifier.SelectBomb }
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
`Modifier.Cancel` has no replacement. Discard the partial input sequence in
|
|
130
|
-
the caller instead of sending a cancellation token.
|
|
131
|
-
|
|
132
|
-
`preview` and `previewFen` never mutate the game. `play` and `playFen` mutate
|
|
133
|
-
only when the complete sequence is legal; incomplete or invalid sequences
|
|
134
|
-
return `{ kind: "invalid", inputFen }`.
|
|
135
|
-
|
|
136
|
-
## Outputs, events, and board values
|
|
137
|
-
|
|
138
|
-
`OutputModel` and `OutputModelKind` are replaced by the `InputResolution`
|
|
139
|
-
discriminated union:
|
|
140
|
-
|
|
141
|
-
| 0.2 kind | 0.3 result |
|
|
142
|
-
| ---------------------- | ------------------------------------------------- |
|
|
143
|
-
| `InvalidInput` | `{ kind: "invalid", inputFen }` |
|
|
144
|
-
| `LocationsToStartFrom` | `{ kind: "awaiting-start", inputFen, positions }` |
|
|
145
|
-
| `NextInputOptions` | `{ kind: "awaiting-input", inputFen, options }` |
|
|
146
|
-
| `Events` | `{ kind: "complete", inputFen, events }` |
|
|
147
|
-
|
|
148
|
-
Narrow on `kind` instead of calling wrapper accessors:
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
const resolution = game.previewFen("l10,5");
|
|
152
|
-
if (resolution.kind === "awaiting-input") {
|
|
153
|
-
for (const option of resolution.options) {
|
|
154
|
-
console.log(option.input, option.action);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
`EventModel`, `ItemModel`, `ManaModel`, `Mon`, `SquareModel`,
|
|
160
|
-
`NextInputModel`, and `VerboseTrackingEntityModel` are now plain readonly
|
|
161
|
-
objects. Their numeric `*Kind` enums were replaced by string `kind`
|
|
162
|
-
discriminants such as `"mon-move"`, `"regular"`, `"mon"`, and
|
|
163
|
-
`"next-turn"`. Event coordinates use descriptive fields including `from`,
|
|
164
|
-
`to`, `at`, and `by`.
|
|
165
|
-
|
|
166
|
-
Wasm lifecycle methods such as `free()` and mutable wrapper setters no longer
|
|
167
|
-
exist. Construct application values as object literals and treat values
|
|
168
|
-
returned by the engine as readonly.
|
|
169
|
-
|
|
170
|
-
## Removed engine-only operations
|
|
171
|
-
|
|
172
|
-
The following compatibility methods exposed mutable engine internals and have
|
|
173
|
-
no public replacement:
|
|
174
|
-
|
|
175
|
-
- `remove_item`
|
|
176
|
-
- `setVerboseTracking`
|
|
177
|
-
- `newForSimulation`
|
|
178
|
-
- `fromFenForSimulation`
|
|
179
|
-
|
|
180
|
-
Use `preview` for non-mutating simulation. `inactive_player_items_counters()`
|
|
181
|
-
is replaced by the color-keyed `game.potions` property; select the inactive
|
|
182
|
-
color explicitly.
|
|
183
|
-
|
|
184
|
-
## Match resolution
|
|
185
|
-
|
|
186
|
-
The positional `winner` function and its `""`, `"w"`, `"b"`, and `"x"`
|
|
187
|
-
return codes are replaced by `resolveMatch`:
|
|
188
|
-
|
|
189
|
-
```ts
|
|
190
|
-
const resolution = resolveMatch({
|
|
191
|
-
white: { fen: whiteFen, moves: whiteMoves },
|
|
192
|
-
black: { fen: blackFen, moves: blackMoves },
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
switch (resolution.kind) {
|
|
196
|
-
case "ongoing":
|
|
197
|
-
break;
|
|
198
|
-
case "winner":
|
|
199
|
-
console.log(resolution.winner);
|
|
200
|
-
break;
|
|
201
|
-
case "invalid":
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
Move histories are arrays rather than dash-separated strings.
|
|
207
|
-
|
|
208
|
-
## Validation differences
|
|
209
|
-
|
|
210
|
-
The 0.2 compatibility layer emulated Wasm coercions, including numeric enum
|
|
211
|
-
coercion, integer wrapping, permissive string normalization, and no-op
|
|
212
|
-
`free()` methods. Version 0.3 validates the TypeScript domain directly:
|
|
213
|
-
|
|
214
|
-
- invalid FEN and input FEN return `undefined` or an `"invalid"` result;
|
|
215
|
-
- unsupported variants, colors, and automove preferences throw `TypeError`;
|
|
216
|
-
- positions must use in-bounds integer `row` and `column` values;
|
|
217
|
-
- non-ASCII or non-canonical wire values are rejected rather than normalized.
|
|
218
|
-
|
|
219
|
-
Update callers to validate external data before constructing typed values.
|