@datamoc/mw_games 0.25.0 → 0.27.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/CHANGELOG.md +192 -0
- package/README.md +15 -0
- package/api-surface.json +14942 -0
- package/dist/actors/StatBlock.d.ts +2 -4
- package/dist/actors/StatBlock.d.ts.map +1 -1
- package/dist/actors/StatBlock.js +2 -4
- package/dist/actors/StatBlock.js.map +1 -1
- package/dist/ai/Heuristics.d.ts +1 -1
- package/dist/ai/Heuristics.js +1 -1
- package/dist/ai/Suggest.d.ts +54 -0
- package/dist/ai/Suggest.d.ts.map +1 -0
- package/dist/ai/Suggest.js +48 -0
- package/dist/ai/Suggest.js.map +1 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +1 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/assets/index.d.ts +1 -0
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js.map +1 -1
- package/dist/core/Blob.d.ts.map +1 -1
- package/dist/core/Blob.js +2 -8
- package/dist/core/Blob.js.map +1 -1
- package/dist/core/Grid.d.ts +115 -0
- package/dist/core/Grid.d.ts.map +1 -1
- package/dist/core/Grid.js +125 -0
- package/dist/core/Grid.js.map +1 -1
- package/dist/core/HttpTransport.d.ts +14 -0
- package/dist/core/HttpTransport.d.ts.map +1 -1
- package/dist/core/HttpTransport.js +14 -0
- package/dist/core/HttpTransport.js.map +1 -1
- package/dist/core/Random.d.ts +63 -13
- package/dist/core/Random.d.ts.map +1 -1
- package/dist/core/Random.js +28 -25
- package/dist/core/Random.js.map +1 -1
- package/dist/core/Replay.d.ts +28 -4
- package/dist/core/Replay.d.ts.map +1 -1
- package/dist/core/Replay.js +38 -9
- package/dist/core/Replay.js.map +1 -1
- package/dist/core/ReplayFile.d.ts +197 -0
- package/dist/core/ReplayFile.d.ts.map +1 -0
- package/dist/core/ReplayFile.js +257 -0
- package/dist/core/ReplayFile.js.map +1 -0
- package/dist/core/index.d.ts +9 -5
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -2
- package/dist/core/index.js.map +1 -1
- package/dist/headless/index.d.ts +87 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +87 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/mw_games.global.js +113 -113
- package/dist/mwl/index.d.ts +1 -1
- package/dist/mwl/index.d.ts.map +1 -1
- package/dist/mwl/index.js.map +1 -1
- package/dist/roguelike/Level.d.ts +1 -1
- package/dist/roguelike/Level.d.ts.map +1 -1
- package/dist/roguelike/Level.js +3 -21
- package/dist/roguelike/Level.js.map +1 -1
- package/dist/roguelike/Targeting.d.ts.map +1 -1
- package/dist/roguelike/Targeting.js +2 -1
- package/dist/roguelike/Targeting.js.map +1 -1
- package/dist/rpg/index.d.ts +1 -1
- package/dist/rpg/index.d.ts.map +1 -1
- package/dist/simulation/Training.d.ts +77 -0
- package/dist/simulation/Training.d.ts.map +1 -1
- package/dist/simulation/Training.js +87 -0
- package/dist/simulation/Training.js.map +1 -1
- package/dist/simulation/index.d.ts +2 -2
- package/dist/simulation/index.d.ts.map +1 -1
- package/dist/simulation/index.js +1 -1
- package/dist/simulation/index.js.map +1 -1
- package/dist/two-d/pixi-interop.d.ts +24 -1
- package/dist/two-d/pixi-interop.d.ts.map +1 -1
- package/dist/two-d/pixi-interop.js +23 -1
- package/dist/two-d/pixi-interop.js.map +1 -1
- package/dist/two-d/render/Beam.d.ts +93 -0
- package/dist/two-d/render/Beam.d.ts.map +1 -0
- package/dist/two-d/render/Beam.js +154 -0
- package/dist/two-d/render/Beam.js.map +1 -0
- package/dist/two-d/render/Flights.d.ts +79 -0
- package/dist/two-d/render/Flights.d.ts.map +1 -0
- package/dist/two-d/render/Flights.js +120 -0
- package/dist/two-d/render/Flights.js.map +1 -0
- package/dist/two-d/render/Particles.d.ts +48 -0
- package/dist/two-d/render/Particles.d.ts.map +1 -1
- package/dist/two-d/render/Particles.js +59 -1
- package/dist/two-d/render/Particles.js.map +1 -1
- package/dist/two-d/render/index.d.ts +6 -2
- package/dist/two-d/render/index.d.ts.map +1 -1
- package/dist/two-d/render/index.js +2 -0
- package/dist/two-d/render/index.js.map +1 -1
- package/dist/two-d/ui/MessageLog.d.ts +28 -0
- package/dist/two-d/ui/MessageLog.d.ts.map +1 -1
- package/dist/two-d/ui/MessageLog.js +23 -6
- package/dist/two-d/ui/MessageLog.js.map +1 -1
- package/dist/two-d/ui/TextPrompt.d.ts +115 -0
- package/dist/two-d/ui/TextPrompt.d.ts.map +1 -0
- package/dist/two-d/ui/TextPrompt.js +227 -0
- package/dist/two-d/ui/TextPrompt.js.map +1 -0
- package/dist/two-d/ui/index.d.ts +4 -2
- package/dist/two-d/ui/index.d.ts.map +1 -1
- package/dist/two-d/ui/index.js +2 -1
- package/dist/two-d/ui/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +16 -3
- package/sbom.cdx.json +6 -6
- package/tools/audit-adoptions.d.mts +65 -0
- package/tools/audit-adoptions.mjs +252 -0
- package/tools/browser-driver.d.mts +78 -0
- package/tools/browser-driver.mjs +642 -0
|
@@ -32,15 +32,13 @@ export interface StatBlockOptions {
|
|
|
32
32
|
derived?: DerivedStat[];
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Resolves one stat's modifiers into a single number
|
|
35
|
+
* Resolves one stat's modifiers into a single number, in the framework's
|
|
36
|
+
* canonical add, multiply, then set composition.
|
|
36
37
|
*
|
|
37
38
|
* Every `add` modifier applies first (summed together), then every `multiply` (each
|
|
38
39
|
* scaling the running total), then every `set` (the last one wins) - a stated, fixed order,
|
|
39
40
|
* so a +10% ring and a cursed -2 sword combine the same way regardless of equip order, and
|
|
40
41
|
* a `set` modifier (a polymorph, a stat drained to exactly zero) always wins over the rest.
|
|
41
|
-
*/
|
|
42
|
-
/**
|
|
43
|
-
* Apply the framework's canonical add, multiply, then set composition.
|
|
44
42
|
*
|
|
45
43
|
* @example
|
|
46
44
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatBlock.d.ts","sourceRoot":"","sources":["../../src/actors/StatBlock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE3C,0DAA0D;AAC1D,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,KAAK,CAAC;AAEpD,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,2FAA2F;IAC3F,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC;CACzC;AAED,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB;AAED
|
|
1
|
+
{"version":3,"file":"StatBlock.d.ts","sourceRoot":"","sources":["../../src/actors/StatBlock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE3C,0DAA0D;AAC1D,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,KAAK,CAAC;AAEpD,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAA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AI,EAAE;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,GAAG,SAAS,CAO3E;CACD"}
|
package/dist/actors/StatBlock.js
CHANGED
|
@@ -8,15 +8,13 @@
|
|
|
8
8
|
* modifiers are active, in a stated order, and keeps it correct as either side changes.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
* Resolves one stat's modifiers into a single number
|
|
11
|
+
* Resolves one stat's modifiers into a single number, in the framework's
|
|
12
|
+
* canonical add, multiply, then set composition.
|
|
12
13
|
*
|
|
13
14
|
* Every `add` modifier applies first (summed together), then every `multiply` (each
|
|
14
15
|
* scaling the running total), then every `set` (the last one wins) - a stated, fixed order,
|
|
15
16
|
* so a +10% ring and a cursed -2 sword combine the same way regardless of equip order, and
|
|
16
17
|
* a `set` modifier (a polymorph, a stat drained to exactly zero) always wins over the rest.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Apply the framework's canonical add, multiply, then set composition.
|
|
20
18
|
*
|
|
21
19
|
* @example
|
|
22
20
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatBlock.js","sourceRoot":"","sources":["../../src/actors/StatBlock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiCH
|
|
1
|
+
{"version":3,"file":"StatBlock.js","sourceRoot":"","sources":["../../src/actors/StatBlock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiCH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,SAA8B;IAC5E,MAAM,IAAI,GAAG,CAAC,EAAc,EAAE,EAAE,CAC/B,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,C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E,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM;QACL,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAAyB,EAAE,IAAqB;QAC/D,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;QACrC,qFAAqF;QACrF,uDAAuD;QACvD,KAAK,CAAC,UAAU,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACrD,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACnB,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
|
package/dist/ai/Heuristics.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface AspectValues {
|
|
|
10
10
|
* wants, and a difficulty level overrides a few of them.
|
|
11
11
|
*
|
|
12
12
|
* Typed readers give a stage a usable number without every caller casting: a missing aspect reads
|
|
13
|
-
* as the fallback (`1` for a weight,
|
|
13
|
+
* as the fallback the caller passes (`1` for a neutral weight, `0` where an unset aspect should zero the score).
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
package/dist/ai/Heuristics.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* wants, and a difficulty level overrides a few of them.
|
|
6
6
|
*
|
|
7
7
|
* Typed readers give a stage a usable number without every caller casting: a missing aspect reads
|
|
8
|
-
* as the fallback (`1` for a weight,
|
|
8
|
+
* as the fallback the caller passes (`1` for a neutral weight, `0` where an unset aspect should zero the score).
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AIDecision, AIDecisionInput } from './index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The suggestion mode: the game's own decider, run on the live state, with the result shown
|
|
4
|
+
* to the player instead of dispatched. The framework runs decisions as data by design
|
|
5
|
+
* (`AIModule.decide` returns an `AIDecision`; the game applies it), so suggesting is the
|
|
6
|
+
* same call pointed at a UI instead of at the world - but a hint that recomputed on every
|
|
7
|
+
* frame would tax the frame budget for something the player reads once, so this owns the
|
|
8
|
+
* throttle: a frame-count budget, never wall clock, the same rule the rest of the runner
|
|
9
|
+
* follows (a throttled background tab must not change what is suggested).
|
|
10
|
+
*
|
|
11
|
+
* The decider must not mutate game state to compute a suggestion; what the player does with
|
|
12
|
+
* one (accept, ignore, watch) is the game's to decide.
|
|
13
|
+
*/
|
|
14
|
+
export interface SuggesterOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Recompute only every Nth `update` call, keeping the previous suggestion in between.
|
|
17
|
+
* 1 (the default) recomputes on every update; 30 recomputes about twice a second at
|
|
18
|
+
* 60 fps. The first update always recomputes, so a hint appears immediately.
|
|
19
|
+
*/
|
|
20
|
+
every?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Wraps a decision function as a throttled, non-mutating hint source.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { Suggester } from '@datamoc/mw_games/ai';
|
|
28
|
+
* import type { AIDecision, AIDecisionInput } from '@datamoc/mw_games/ai';
|
|
29
|
+
*
|
|
30
|
+
* declare const module: { decide(agent: string, input: AIDecisionInput): AIDecision };
|
|
31
|
+
* declare const input: AIDecisionInput;
|
|
32
|
+
* const hints = new Suggester((perception) => module.decide('player', perception), { every: 30 });
|
|
33
|
+
* const fresh = hints.update(input); // null on the 29 throttled frames between hints
|
|
34
|
+
* const current = hints.latest; // never null between updates
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class Suggester {
|
|
38
|
+
private readonly decide;
|
|
39
|
+
private readonly every;
|
|
40
|
+
private since;
|
|
41
|
+
private latestDecision;
|
|
42
|
+
constructor(decide: (input: AIDecisionInput) => AIDecision, options?: SuggesterOptions);
|
|
43
|
+
/**
|
|
44
|
+
* Runs the decider on its turn and returns the fresh suggestion; null on the throttled
|
|
45
|
+
* calls between, where `latest` keeps the previous suggestion. A decision with status
|
|
46
|
+
* `idle` (nothing to suggest) is still a suggestion: the UI reads `decision.action`.
|
|
47
|
+
*/
|
|
48
|
+
update(input: AIDecisionInput): AIDecision | null;
|
|
49
|
+
/** The most recent suggestion, held across the throttled calls. */
|
|
50
|
+
get latest(): AIDecision | null;
|
|
51
|
+
/** Drops the held suggestion: a scene change, a menu opened, a turn ended. */
|
|
52
|
+
clear(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=Suggest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Suggest.d.ts","sourceRoot":"","sources":["../../src/ai/Suggest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,gBAAgB;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,cAAc,CAA2B;IAEjD,YAAY,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,UAAU,EAAE,OAAO,GAAE,gBAAqB,EAOzF;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,UAAU,GAAG,IAAI,CAMhD;IAED,mEAAmE;IACnE,IAAI,MAAM,IAAI,UAAU,GAAG,IAAI,CAE9B;IAED,8EAA8E;IAC9E,KAAK,IAAI,IAAI,CAEZ;CACD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a decision function as a throttled, non-mutating hint source.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Suggester } from '@datamoc/mw_games/ai';
|
|
7
|
+
* import type { AIDecision, AIDecisionInput } from '@datamoc/mw_games/ai';
|
|
8
|
+
*
|
|
9
|
+
* declare const module: { decide(agent: string, input: AIDecisionInput): AIDecision };
|
|
10
|
+
* declare const input: AIDecisionInput;
|
|
11
|
+
* const hints = new Suggester((perception) => module.decide('player', perception), { every: 30 });
|
|
12
|
+
* const fresh = hints.update(input); // null on the 29 throttled frames between hints
|
|
13
|
+
* const current = hints.latest; // never null between updates
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class Suggester {
|
|
17
|
+
constructor(decide, options = {}) {
|
|
18
|
+
this.latestDecision = null;
|
|
19
|
+
this.decide = decide;
|
|
20
|
+
this.every = options.every ?? 1;
|
|
21
|
+
if (!Number.isInteger(this.every) || this.every < 1 || this.every > 1_000_000)
|
|
22
|
+
throw new RangeError('a suggestion budget must be a frame count in 1..1000000');
|
|
23
|
+
//the first update recomputes; the budget applies from the second on
|
|
24
|
+
this.since = this.every - 1;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Runs the decider on its turn and returns the fresh suggestion; null on the throttled
|
|
28
|
+
* calls between, where `latest` keeps the previous suggestion. A decision with status
|
|
29
|
+
* `idle` (nothing to suggest) is still a suggestion: the UI reads `decision.action`.
|
|
30
|
+
*/
|
|
31
|
+
update(input) {
|
|
32
|
+
this.since++;
|
|
33
|
+
if (this.since < this.every)
|
|
34
|
+
return null;
|
|
35
|
+
this.since = 0;
|
|
36
|
+
this.latestDecision = this.decide(input);
|
|
37
|
+
return this.latestDecision;
|
|
38
|
+
}
|
|
39
|
+
/** The most recent suggestion, held across the throttled calls. */
|
|
40
|
+
get latest() {
|
|
41
|
+
return this.latestDecision;
|
|
42
|
+
}
|
|
43
|
+
/** Drops the held suggestion: a scene change, a menu opened, a turn ended. */
|
|
44
|
+
clear() {
|
|
45
|
+
this.latestDecision = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=Suggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Suggest.js","sourceRoot":"","sources":["../../src/ai/Suggest.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,SAAS;IAMrB,YAAY,MAA8C,EAAE,OAAO,GAAqB,EAAE;QAFlF,mBAAc,GAAsB,IAAI,CAAC;QAGhD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,SAAS;YAC5E,MAAM,IAAI,UAAU,CAAC,yDAAyD,CAAC,CAAC;QACjF,oEAAoE;QACpE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAsB;QAC5B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;IAED,mEAAmE;IACnE,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;IAED,8EAA8E;IAC9E,KAAK;QACJ,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC5B,CAAC;CACD"}
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AlphaBetaGame, AlphaBetaOptions, AlphaBetaResult } from './search.ts';
|
|
2
2
|
export { NeuralPolicy } from './Neural.ts';
|
|
3
3
|
export type { DenseLayer, NeuralModel, NeuralObservation } from './Neural.ts';
|
|
4
|
+
export { Suggester } from './Suggest.ts';
|
|
5
|
+
export type { SuggesterOptions } from './Suggest.ts';
|
|
4
6
|
export { alphaBetaSearch, firstWins, rootSplits } from './search.ts';
|
|
5
7
|
export type { AlphaBetaGame, AlphaBetaOptions, AlphaBetaResult, LuaAlphaBetaFunctions, LuaSearchValueAdapter, RootSplit, } from './search.ts';
|
|
6
8
|
export { personalScoreView, scoreWith, sideScoreView, subjectsWhere } from './score.ts';
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD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8B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAE9C,YAAY,OAAO,GAAE,mBAAwB,EAI5C;IAED,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAWvC;IAED,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,UAAU,CA8D1D;IAED,oFAAoF;IACpF,MAAM,CAAC,KAAK,EAAE,IAAI,EACjB,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,EAChC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACvB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAE9B;IAED,WAAW,IAAI,eAAe,CAK7B;IAED,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAM3C;IAED,OAAO,IAAI,IAAI,CAGd;CACD;AAED,gFAAgF;AAChF,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,cAGC;CACD;AAED,mFAAmF;AACnF,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,cAGC;CACD"}
|
package/dist/ai/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { alphaBetaSearch } from './search.js';
|
|
2
2
|
export { NeuralPolicy } from './Neural.js';
|
|
3
|
+
export { Suggester } from './Suggest.js';
|
|
3
4
|
export { alphaBetaSearch, firstWins, rootSplits } from './search.js';
|
|
4
5
|
export { personalScoreView, scoreWith, sideScoreView, subjectsWhere } from './score.js';
|
|
5
6
|
export { Aspects, Difficulty, Goals, HeuristicAI, RecruitmentPattern, defaultWeigh, goalScore, keepAwayScore, } from './Heuristics.js';
|
package/dist/ai/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EAAE,YAAY,EAAE,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,CAAC;IAC9B,CAAC,CAAC;AACH,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAE,IAAY;IAC3D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,6BAA6B,CAAC,CAAC;AACvG,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAa,EAAE,IAAY;IAC7D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,gCAAgC,CAAC,CAAC;AACzG,CAAC;AAED,SAAS,cAAc;IACtB,OAAO,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;AAC5E,CAAC"}
|
package/dist/assets/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
export { setBase, setAssetMap, isCompiled, paths, has, resolve } from './paths.ts';
|
|
14
14
|
export type { AssetProgress } from './paths.ts';
|
|
15
15
|
export { load, texture, get, isLoaded, release } from './loader.ts';
|
|
16
|
+
export type { LoadAssetsOptions } from './loader.ts';
|
|
16
17
|
export { loadBinary, getBinary, isBinaryLoaded, releaseBinary } from './binary.ts';
|
|
17
18
|
export type { LoadBinaryOptions } from './binary.ts';
|
|
18
19
|
export { AssetStream } from './Streaming.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/assets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACnF,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/assets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACnF,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACpE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACnF,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/assets/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/assets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGnF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/assets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGnF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGnF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/core/Blob.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Blob.d.ts","sourceRoot":"","sources":["../../src/core/Blob.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Blob.d.ts","sourceRoot":"","sources":["../../src/core/Blob.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,qBAAa,IAAI;IAChB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,MAAM,CAAe;IAE7B,YAAY,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAIxC;IAED,mEAAmE;IACnE,OAAO,CAAC,KAAK;IAKb,4DAA4D;IAC5D,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGrC;IAED,iFAAiF;IACjF,KAAK,IAAI,MAAM,CAId;IAED,2EAA2E;IAC3E,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAG/C;IAED,yFAAyF;IACzF,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAGhC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,EAAE,MAAM,SAAO,EAAE,KAAK,SAAM,GAAG,KAAK,CAAC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAsC3G;IAED,qFAAqF;IACrF,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAS3E;IAED,MAAM,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAE5D;IAED,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAI/E;CACD"}
|
package/dist/core/Blob.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NEIGHBOURS4 } from './Grid.js';
|
|
1
2
|
/**
|
|
2
3
|
* A spreading volume field over a grid: a number per cell that creeps into its open
|
|
3
4
|
* neighbours and thins out over time. Fire, gas, caustic ooze, flood water - anything
|
|
@@ -29,13 +30,6 @@
|
|
|
29
30
|
* fire.clear(5, 5); // someone douses that one tile
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
/** the four axial neighbours of a cell, same order as `roguelike`'s square topology */
|
|
33
|
-
const OFFSET_4 = [
|
|
34
|
-
[0, -1],
|
|
35
|
-
[1, 0],
|
|
36
|
-
[0, 1],
|
|
37
|
-
[-1, 0],
|
|
38
|
-
];
|
|
39
33
|
export class Blob {
|
|
40
34
|
constructor(width, height) {
|
|
41
35
|
this.width = width;
|
|
@@ -92,7 +86,7 @@ export class Blob {
|
|
|
92
86
|
if (amount <= 0)
|
|
93
87
|
continue;
|
|
94
88
|
const neighbours = [];
|
|
95
|
-
for (const [dx, dy] of
|
|
89
|
+
for (const [dx, dy] of NEIGHBOURS4) {
|
|
96
90
|
const nx = x + dx;
|
|
97
91
|
const ny = y + dy;
|
|
98
92
|
const i = this.index(nx, ny);
|
package/dist/core/Blob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Blob.js","sourceRoot":"","sources":["../../src/core/Blob.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Blob.js","sourceRoot":"","sources":["../../src/core/Blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,OAAO,IAAI;IAMhB,YAAY,KAAa,EAAE,MAAc;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,mEAAmE;IAC3D,KAAK,CAAC,CAAS,EAAE,CAAS;QACjC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,CAAC,CAAC;QACrE,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,4DAA4D;IAC5D,QAAQ,CAAC,CAAS,EAAE,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AM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7E,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAyD;QACxE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
package/dist/core/Grid.d.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
18
|
* import { cellInside, cellIndex, cellX, cellY, cellKey, cellFromKey } from '@datamoc/mw_games/core';
|
|
19
|
+
* import { NEIGHBOURS4, NEIGHBOURS8, CIRCLE8, euclidean } from '@datamoc/mw_games/core';
|
|
19
20
|
*
|
|
20
21
|
* // a 4x3 board, row-major: y * width + x
|
|
21
22
|
* cellInside(4, 3, 3, 2); // true, the far corner
|
|
@@ -26,6 +27,11 @@
|
|
|
26
27
|
*
|
|
27
28
|
* const seen = new Set([cellKey(2, 1)]); // '2,1', for a Map or a Set
|
|
28
29
|
* cellFromKey('2,1'); // { x: 2, y: 1 }
|
|
30
|
+
*
|
|
31
|
+
* NEIGHBOURS8.length; // 8, the surrounding cells in row-major order
|
|
32
|
+
* CIRCLE8[0]; // [0, -1], the same ring clockwise from north
|
|
33
|
+
* NEIGHBOURS4.length; // 4, north/east/south/west
|
|
34
|
+
* euclidean({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5
|
|
29
35
|
* ```
|
|
30
36
|
*/
|
|
31
37
|
/**
|
|
@@ -61,4 +67,113 @@ export declare function cellFromKey(key: string): {
|
|
|
61
67
|
x: number;
|
|
62
68
|
y: number;
|
|
63
69
|
} | null;
|
|
70
|
+
/**
|
|
71
|
+
* The four axial neighbours of a cell: north, east, south, west, in that order.
|
|
72
|
+
*
|
|
73
|
+
* One frozen table shared by every square-grid algorithm, so a flood fill and a
|
|
74
|
+
* diffusion field visit neighbours in the same sequence without each keeping its
|
|
75
|
+
* own copy: `roguelike`'s `neighbourOffsets(4)` returns this same table.
|
|
76
|
+
*/
|
|
77
|
+
export declare const NEIGHBOURS4: ReadonlyArray<readonly [number, number]>;
|
|
78
|
+
/**
|
|
79
|
+
* The eight cells surrounding a cell, in row-major (reading) order, centre skipped.
|
|
80
|
+
*
|
|
81
|
+
* The same eight cells `CIRCLE8` carries, only the visit order differs: reading order
|
|
82
|
+
* suits first-found-wins scans, the ring suits directional work like knockback cursors.
|
|
83
|
+
*/
|
|
84
|
+
export declare const NEIGHBOURS8: ReadonlyArray<readonly [number, number]>;
|
|
85
|
+
/**
|
|
86
|
+
* The eight cells surrounding a cell as a clockwise ring starting north.
|
|
87
|
+
*
|
|
88
|
+
* The same sequence `roguelike`'s `neighbourOffsets(8)` has always returned, now shared
|
|
89
|
+
* from here instead of copied there.
|
|
90
|
+
*/
|
|
91
|
+
export declare const CIRCLE8: ReadonlyArray<readonly [number, number]>;
|
|
92
|
+
/**
|
|
93
|
+
* Euclidean ruler distance between two cells.
|
|
94
|
+
*
|
|
95
|
+
* The counterpart to `roguelike`'s `chebyshevDistance`, which charges a diagonal the
|
|
96
|
+
* same as a step: use this one when the true straight-line distance matters (blast
|
|
97
|
+
* falloff, census radius) and that one for roguelike range and movement.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { euclidean } from '@datamoc/mw_games/core';
|
|
102
|
+
*
|
|
103
|
+
* euclidean({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function euclidean(a: {
|
|
107
|
+
readonly x: number;
|
|
108
|
+
readonly y: number;
|
|
109
|
+
}, b: {
|
|
110
|
+
readonly x: number;
|
|
111
|
+
readonly y: number;
|
|
112
|
+
}): number;
|
|
113
|
+
/**
|
|
114
|
+
* Chebyshev ruler distance between two cells: the king-move count, a diagonal costing one step.
|
|
115
|
+
*
|
|
116
|
+
* The counterpart to `euclidean` above for grid movement and range, where a diagonal is a
|
|
117
|
+
* single step rather than 1.41 cells; `roguelike`
|
|
118
|
+
* `chebyshevDistance` is this same arithmetic through its own `Step` type.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { chebyshev } from '@datamoc/mw_games/core';
|
|
123
|
+
*
|
|
124
|
+
* chebyshev({ x: 0, y: 0 }, { x: 3, y: 4 }); // 4
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function chebyshev(a: {
|
|
128
|
+
readonly x: number;
|
|
129
|
+
readonly y: number;
|
|
130
|
+
}, b: {
|
|
131
|
+
readonly x: number;
|
|
132
|
+
readonly y: number;
|
|
133
|
+
}): number;
|
|
134
|
+
/**
|
|
135
|
+
* Manhattan ruler distance between two cells: the orthogonal-step count, no diagonals.
|
|
136
|
+
*
|
|
137
|
+
* The counterpart to `euclidean` and `chebyshev` for four-way movement and range, where
|
|
138
|
+
* every step is axis-aligned.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { manhattan } from '@datamoc/mw_games/core';
|
|
143
|
+
*
|
|
144
|
+
* manhattan({ x: 0, y: 0 }, { x: 3, y: 4 }); // 7
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function manhattan(a: {
|
|
148
|
+
readonly x: number;
|
|
149
|
+
readonly y: number;
|
|
150
|
+
}, b: {
|
|
151
|
+
readonly x: number;
|
|
152
|
+
readonly y: number;
|
|
153
|
+
}): number;
|
|
154
|
+
/**
|
|
155
|
+
* The ruler a rule measures with, chosen by name where the choice itself is data: a
|
|
156
|
+
* movement rule walks `chebyshev`, a blast falls off with `euclidean`, a four-way maze
|
|
157
|
+
* counts `manhattan`.
|
|
158
|
+
*/
|
|
159
|
+
export type DistanceMetric = 'euclidean' | 'manhattan' | 'chebyshev';
|
|
160
|
+
/**
|
|
161
|
+
* Measures `a` to `b` with the named ruler, so a rule authored as data (a table row, a
|
|
162
|
+
* authored profile) can pick its geometry without importing each ruler by name.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { distance } from '@datamoc/mw_games/core';
|
|
167
|
+
*
|
|
168
|
+
* distance('chebyshev', { x: 0, y: 0 }, { x: 3, y: 4 }); // 4
|
|
169
|
+
* distance('euclidean', { x: 0, y: 0 }, { x: 3, y: 4 }); // 5
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function distance(metric: DistanceMetric, a: {
|
|
173
|
+
readonly x: number;
|
|
174
|
+
readonly y: number;
|
|
175
|
+
}, b: {
|
|
176
|
+
readonly x: number;
|
|
177
|
+
readonly y: number;
|
|
178
|
+
}): number;
|
|
64
179
|
//# sourceMappingURL=Grid.d.ts.map
|
package/dist/core/Grid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../src/core/Grid.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../src/core/Grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GA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,EAC7C,CAAC,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,MAAM,CAER;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CACxB,CAAC,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7C,CAAC,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,MAAM,CAER;AAED;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACvB,MAAM,EAAE,cAAc,EACtB,CAAC,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7C,CAAC,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,MAAM,CAWR"}
|
package/dist/core/Grid.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
18
|
* import { cellInside, cellIndex, cellX, cellY, cellKey, cellFromKey } from '@datamoc/mw_games/core';
|
|
19
|
+
* import { NEIGHBOURS4, NEIGHBOURS8, CIRCLE8, euclidean } from '@datamoc/mw_games/core';
|
|
19
20
|
*
|
|
20
21
|
* // a 4x3 board, row-major: y * width + x
|
|
21
22
|
* cellInside(4, 3, 3, 2); // true, the far corner
|
|
@@ -26,6 +27,11 @@
|
|
|
26
27
|
*
|
|
27
28
|
* const seen = new Set([cellKey(2, 1)]); // '2,1', for a Map or a Set
|
|
28
29
|
* cellFromKey('2,1'); // { x: 2, y: 1 }
|
|
30
|
+
*
|
|
31
|
+
* NEIGHBOURS8.length; // 8, the surrounding cells in row-major order
|
|
32
|
+
* CIRCLE8[0]; // [0, -1], the same ring clockwise from north
|
|
33
|
+
* NEIGHBOURS4.length; // 4, north/east/south/west
|
|
34
|
+
* euclidean({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5
|
|
29
35
|
* ```
|
|
30
36
|
*/
|
|
31
37
|
/**
|
|
@@ -73,4 +79,123 @@ export function cellFromKey(key) {
|
|
|
73
79
|
return null;
|
|
74
80
|
return { x: Number(match[1]), y: Number(match[2]) };
|
|
75
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The four axial neighbours of a cell: north, east, south, west, in that order.
|
|
84
|
+
*
|
|
85
|
+
* One frozen table shared by every square-grid algorithm, so a flood fill and a
|
|
86
|
+
* diffusion field visit neighbours in the same sequence without each keeping its
|
|
87
|
+
* own copy: `roguelike`'s `neighbourOffsets(4)` returns this same table.
|
|
88
|
+
*/
|
|
89
|
+
export const NEIGHBOURS4 = [
|
|
90
|
+
[0, -1],
|
|
91
|
+
[1, 0],
|
|
92
|
+
[0, 1],
|
|
93
|
+
[-1, 0],
|
|
94
|
+
];
|
|
95
|
+
/**
|
|
96
|
+
* The eight cells surrounding a cell, in row-major (reading) order, centre skipped.
|
|
97
|
+
*
|
|
98
|
+
* The same eight cells `CIRCLE8` carries, only the visit order differs: reading order
|
|
99
|
+
* suits first-found-wins scans, the ring suits directional work like knockback cursors.
|
|
100
|
+
*/
|
|
101
|
+
export const NEIGHBOURS8 = [
|
|
102
|
+
[-1, -1],
|
|
103
|
+
[0, -1],
|
|
104
|
+
[1, -1],
|
|
105
|
+
[-1, 0],
|
|
106
|
+
[1, 0],
|
|
107
|
+
[-1, 1],
|
|
108
|
+
[0, 1],
|
|
109
|
+
[1, 1],
|
|
110
|
+
];
|
|
111
|
+
/**
|
|
112
|
+
* The eight cells surrounding a cell as a clockwise ring starting north.
|
|
113
|
+
*
|
|
114
|
+
* The same sequence `roguelike`'s `neighbourOffsets(8)` has always returned, now shared
|
|
115
|
+
* from here instead of copied there.
|
|
116
|
+
*/
|
|
117
|
+
export const CIRCLE8 = [
|
|
118
|
+
[0, -1],
|
|
119
|
+
[1, -1],
|
|
120
|
+
[1, 0],
|
|
121
|
+
[1, 1],
|
|
122
|
+
[0, 1],
|
|
123
|
+
[-1, 1],
|
|
124
|
+
[-1, 0],
|
|
125
|
+
[-1, -1],
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* Euclidean ruler distance between two cells.
|
|
129
|
+
*
|
|
130
|
+
* The counterpart to `roguelike`'s `chebyshevDistance`, which charges a diagonal the
|
|
131
|
+
* same as a step: use this one when the true straight-line distance matters (blast
|
|
132
|
+
* falloff, census radius) and that one for roguelike range and movement.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { euclidean } from '@datamoc/mw_games/core';
|
|
137
|
+
*
|
|
138
|
+
* euclidean({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export function euclidean(a, b) {
|
|
142
|
+
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Chebyshev ruler distance between two cells: the king-move count, a diagonal costing one step.
|
|
146
|
+
*
|
|
147
|
+
* The counterpart to `euclidean` above for grid movement and range, where a diagonal is a
|
|
148
|
+
* single step rather than 1.41 cells; `roguelike`
|
|
149
|
+
* `chebyshevDistance` is this same arithmetic through its own `Step` type.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { chebyshev } from '@datamoc/mw_games/core';
|
|
154
|
+
*
|
|
155
|
+
* chebyshev({ x: 0, y: 0 }, { x: 3, y: 4 }); // 4
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function chebyshev(a, b) {
|
|
159
|
+
return Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Manhattan ruler distance between two cells: the orthogonal-step count, no diagonals.
|
|
163
|
+
*
|
|
164
|
+
* The counterpart to `euclidean` and `chebyshev` for four-way movement and range, where
|
|
165
|
+
* every step is axis-aligned.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { manhattan } from '@datamoc/mw_games/core';
|
|
170
|
+
*
|
|
171
|
+
* manhattan({ x: 0, y: 0 }, { x: 3, y: 4 }); // 7
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export function manhattan(a, b) {
|
|
175
|
+
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Measures `a` to `b` with the named ruler, so a rule authored as data (a table row, a
|
|
179
|
+
* authored profile) can pick its geometry without importing each ruler by name.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* import { distance } from '@datamoc/mw_games/core';
|
|
184
|
+
*
|
|
185
|
+
* distance('chebyshev', { x: 0, y: 0 }, { x: 3, y: 4 }); // 4
|
|
186
|
+
* distance('euclidean', { x: 0, y: 0 }, { x: 3, y: 4 }); // 5
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export function distance(metric, a, b) {
|
|
190
|
+
switch (metric) {
|
|
191
|
+
case 'euclidean':
|
|
192
|
+
return euclidean(a, b);
|
|
193
|
+
case 'manhattan':
|
|
194
|
+
return manhattan(a, b);
|
|
195
|
+
case 'chebyshev':
|
|
196
|
+
return chebyshev(a, b);
|
|
197
|
+
default:
|
|
198
|
+
throw new RangeError(`unknown distance metric: ${metric}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
76
201
|
//# sourceMappingURL=Grid.js.map
|