mons-rules 0.3.4 → 0.4.0

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 CHANGED
@@ -1,8 +1,7 @@
1
1
  # Mons rules engine
2
2
 
3
- `mons-rules` is the dependency-free TypeScript rules engine for Super Metal
4
- Mons. It is an ESM-only package for browsers, Web Workers, Node.js, and Firebase
5
- Cloud Functions.
3
+ Dependency-free TypeScript rules for Super Metal Mons. The ESM-only package
4
+ runs in browsers, Web Workers, Node.js, and Firebase Cloud Functions.
6
5
 
7
6
  ## Install
8
7
 
@@ -13,7 +12,7 @@ npm install mons-rules
13
12
  ## Use
14
13
 
15
14
  ```ts
16
- import { AutomovePreference, Game, GameVariant, type Input } from "mons-rules";
15
+ import { Game, GameVariant, type Input } from "mons-rules";
17
16
 
18
17
  const game = new Game({ variant: GameVariant.Classic });
19
18
  const inputs: Input[] = [
@@ -21,12 +20,12 @@ const inputs: Input[] = [
21
20
  { kind: "position", position: { row: 9, column: 4 } },
22
21
  ];
23
22
  const result = game.play(inputs);
24
- const suggestion = game.suggestMove(AutomovePreference.Pro);
23
+ const suggestion = game.suggestMove("pro");
25
24
  ```
26
25
 
27
- Use `preview` or `previewFen` to inspect inputs without mutating the game. Use
28
- `play` or `playFen` to apply a complete legal move. Serialize games with
29
- `toFen` and restore them with `Game.fromFen`.
26
+ Use `preview` to inspect typed inputs without mutation. Use `play` or `playFen`
27
+ to apply a complete legal move. Serialize with `toFen` and restore with
28
+ `Game.fromFen`.
30
29
 
31
30
  Published JavaScript targets ES2020 and uses Web-standard `performance` and
32
31
  `crypto` globals. Node.js 22.13 through 22.x, or Node.js 24 or newer, is
@@ -1,8 +1,9 @@
1
- import { type AvailableMoveCounts, type AutomovePreference as AutomovePreferenceValue, type BoardItem, type Color as ColorValue, type GameVariant as GameVariantValue, type Input, type InputResolution, type MoveSuggestion, type MoveUsage, type PlayResult, type Position, type Square, type TrackingEntry } from "./types.js";
2
- export type GameOptions = {
1
+ import { type AvailableMoveCounts, type BoardItem, type Color as ColorValue, type GameVariant as GameVariantValue, type Input, type InputResolution, type MoveSuggestion, type PlayResult, type Position, type Square, type TrackingEntry } from "./types.js";
2
+ type StrategicPreference = "fast" | "normal" | "pro";
3
+ type GameOptions = {
3
4
  readonly variant?: GameVariantValue;
4
5
  };
5
- export type MoveHistory = {
6
+ type MoveHistory = {
6
7
  readonly white: readonly string[];
7
8
  readonly black: readonly string[];
8
9
  };
@@ -15,14 +16,12 @@ export declare class Game {
15
16
  get turnNumber(): number;
16
17
  get scores(): Readonly<Record<ColorValue, number>>;
17
18
  get potions(): Readonly<Record<ColorValue, number>>;
18
- get moveUsage(): MoveUsage;
19
19
  get winner(): ColorValue | undefined;
20
20
  get historyVerified(): boolean;
21
21
  get takebackFens(): readonly string[];
22
22
  get trackingEntries(): readonly TrackingEntry[];
23
23
  toFen(): string;
24
24
  preview(inputs: readonly Input[]): InputResolution;
25
- previewFen(inputFen: string): InputResolution;
26
25
  play(inputs: readonly Input[]): PlayResult;
27
26
  playFen(inputFen: string): PlayResult;
28
27
  itemAt(position: Position): BoardItem | undefined;
@@ -34,6 +33,6 @@ export declare class Game {
34
33
  verifyHistory(history: MoveHistory): boolean;
35
34
  isLaterThan(other: Game): boolean;
36
35
  availableMoveCounts(): AvailableMoveCounts;
37
- suggestMove(preference: AutomovePreferenceValue): MoveSuggestion | undefined;
38
- clearTracking(): void;
36
+ suggestMove(preference: StrategicPreference): MoveSuggestion | undefined;
39
37
  }
38
+ export {};
@@ -37,13 +37,6 @@ export declare const Modifier: Readonly<{
37
37
  readonly SelectBomb: "select-bomb";
38
38
  }>;
39
39
  export type Modifier = (typeof Modifier)[keyof typeof Modifier];
40
- export declare const AutomovePreference: Readonly<{
41
- readonly Random: "random";
42
- readonly Fast: "fast";
43
- readonly Normal: "normal";
44
- readonly Pro: "pro";
45
- }>;
46
- export type AutomovePreference = (typeof AutomovePreference)[keyof typeof AutomovePreference];
47
40
  export type Position = {
48
41
  readonly row: number;
49
42
  readonly column: number;
@@ -59,7 +52,7 @@ export type Mana = {
59
52
  } | {
60
53
  readonly kind: "supermana";
61
54
  };
62
- export type Carryable = {
55
+ type Carryable = {
63
56
  readonly kind: "mana";
64
57
  readonly mana: Mana;
65
58
  } | {
@@ -200,11 +193,11 @@ export type GameEvent = {
200
193
  } | {
201
194
  readonly kind: "takeback";
202
195
  };
203
- export type InvalidInputResolution = {
196
+ type InvalidInputResolution = {
204
197
  readonly kind: "invalid";
205
198
  readonly inputFen: string;
206
199
  };
207
- export type CompleteInputResolution = {
200
+ type CompleteInputResolution = {
208
201
  readonly kind: "complete";
209
202
  readonly inputFen: string;
210
203
  readonly events: readonly GameEvent[];
@@ -219,12 +212,10 @@ export type InputResolution = InvalidInputResolution | {
219
212
  readonly options: readonly InputOption[];
220
213
  } | CompleteInputResolution;
221
214
  export type PlayResult = InvalidInputResolution | CompleteInputResolution;
222
- export type MoveUsage = {
215
+ export type AvailableMoveCounts = {
223
216
  readonly monMoves: number;
224
217
  readonly manaMoves: number;
225
218
  readonly actions: number;
226
- };
227
- export type AvailableMoveCounts = MoveUsage & {
228
219
  readonly potions: number;
229
220
  };
230
221
  export type TrackingEntry = {
@@ -238,7 +229,7 @@ export type MoveSuggestion = {
238
229
  readonly inputFen: string;
239
230
  readonly events: readonly GameEvent[];
240
231
  };
241
- export type PlayerSubmission = {
232
+ type PlayerSubmission = {
242
233
  readonly fen: string;
243
234
  readonly moves: readonly string[];
244
235
  };
@@ -1,5 +1,4 @@
1
1
  export { Game } from "../api/game.js";
2
- export type { GameOptions, MoveHistory } from "../api/game.js";
3
2
  export { resolveMatch } from "../api/winner.js";
4
- export { AutomovePreference, Color, Consumable, GameVariant, Modifier, MonKind, } from "../api/types.js";
5
- export type { AvailableMoveCounts, BoardItem, Carryable, CompleteInputResolution, GameEvent, Input, InputAction, InputOption, InputResolution, InvalidInputResolution, Mana, MatchResolution, MatchSubmission, Mon, MoveSuggestion, MoveUsage, PlayerSubmission, PlayResult, Position, Square, TrackingEntry, } from "../api/types.js";
3
+ export { Color, Consumable, GameVariant, Modifier, MonKind, } from "../api/types.js";
4
+ export type { AvailableMoveCounts, BoardItem, GameEvent, Input, InputResolution, Mana, Mon, Position, Square, } from "../api/types.js";