@altnovatrail/widgets 0.1.2 → 0.1.3
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 +1 -1
- package/cores/vector.schema.json +82 -3
- package/kinds/cells/cells.handles.json +145 -0
- package/kinds/cells/cells.schema.json +652 -4
- package/kinds/cells/vectors/bishop-grid-56-d1-1.json +105 -4
- package/kinds/cells/vectors/counter-cases.json +123 -0
- package/kinds/cells/vectors/counter-div-56-d1-3.json +57 -0
- package/kinds/cells/vectors/counter-div-56-d2-1.json +773 -0
- package/kinds/cells/vectors/counter-div-56-d2-3.json +65 -0
- package/kinds/cells/vectors/counter-div-56-d4-1.json +57 -0
- package/kinds/cells/vectors/counter-div-56-d4-2.json +106 -0
- package/kinds/cells/vectors/cut-cases.json +163 -0
- package/kinds/cells/vectors/cut-gaps-56-d2-1.json +142 -0
- package/kinds/cells/vectors/cut-grid-56-d2-4.json +45 -0
- package/kinds/cells/vectors/cut-grid-56-d4-1.json +154 -0
- package/kinds/cells/vectors/cut-grid-56-d4-2.json +136 -0
- package/kinds/cells/vectors/cut-invalid.json +48 -0
- package/kinds/cells/vectors/domino-grid-56-d3-2.json +238 -0
- package/kinds/cells/vectors/domino-limit.json +60 -0
- package/kinds/cells/vectors/domino-par-56-d3-2.json +194 -0
- package/kinds/cells/vectors/domino-par-56-d4-3.json +127 -0
- package/kinds/cells/vectors/figure-apart.json +47 -0
- package/kinds/cells/vectors/fold-12x12.json +79 -0
- package/kinds/cells/vectors/fold-14x14.json +79 -0
- package/kinds/cells/vectors/fold-26x26.json +79 -0
- package/kinds/cells/vectors/garden-enum-56-d3-4.json +96 -6
- package/kinds/cells/vectors/goat-grid-56-d4-4.json +325 -5
- package/kinds/cells/vectors/mosaic-grid-56-d2-2.json +84 -0
- package/kinds/cells/vectors/nodes-gaps-56-d2-2.json +44 -0
- package/kinds/cells/vectors/nodes-gaps-56-d4-2.json +70 -0
- package/kinds/cells/vectors/number-div-56-d2-2.json +49 -0
- package/kinds/cells/vectors/numbers-div-56-d3-1.json +24 -0
- package/kinds/cells/vectors/numbers-invalid.json +56 -0
- package/kinds/cells/vectors/paper-26x26.json +743 -0
- package/kinds/cells/vectors/paper-cube-12-d2-1.json +43 -19
- package/kinds/cells/vectors/paper-cube-12-d5-1.json +47 -4
- package/kinds/cells/vectors/paper-cube-56-d4-1.json +56 -5
- package/kinds/cells/vectors/paper-drawn-lines.json +149 -0
- package/kinds/cells/vectors/paper-grid-56-d1-2.json +46 -5
- package/kinds/cells/vectors/paper-turn-invalid.json +4 -4
- package/kinds/cells/vectors/path-6x6.json +119 -0
- package/kinds/cells/vectors/path-beside.json +108 -0
- package/kinds/cells/vectors/path-enum-12-d3-5.json +187 -0
- package/kinds/cells/vectors/path-enum-34-d4-3.json +412 -0
- package/kinds/cells/vectors/path-enum-56-d3-3.json +411 -0
- package/kinds/cells/vectors/path-enum-56-d3-5.json +351 -0
- package/kinds/cells/vectors/path-invalid.json +37 -0
- package/kinds/cells/vectors/path-limit.json +58 -0
- package/kinds/cells/vectors/path-maze.json +297 -0
- package/kinds/cells/vectors/path-unreachable.json +76 -0
- package/kinds/cells/vectors/perimeter-grid-56-d2-1.json +86 -0
- package/kinds/cells/vectors/perimeter-grid-56-d3-1.json +102 -0
- package/kinds/cells/vectors/perimeter-grid-56-d3-3.json +112 -0
- package/kinds/cells/vectors/perimeter-grid-56-d4-3.json +289 -0
- package/kinds/cells/vectors/polyomino-cases.json +191 -0
- package/kinds/cells/vectors/polyomino-grid-56-d3-4.json +205 -0
- package/kinds/cells/vectors/polyomino-grid-56-d4-1.json +137 -0
- package/kinds/cells/vectors/polyomino-grid-56-d5-3.json +157 -0
- package/kinds/cells/vectors/polyomino-invalid.json +45 -0
- package/kinds/cells/vectors/route-par-56-d3-3.json +245 -0
- package/kinds/cells/vectors/sides-gaps-56-d3-2.json +44 -0
- package/kinds/cells/vectors/sieve-div-56-d3-2.json +140 -0
- package/kinds/cells/vectors/tear-gaps-56-d3-1.json +84 -0
- package/kinds/cells/vectors/tear-limit.json +56 -0
- package/lib/cores/enumerate.d.ts +33 -0
- package/lib/cores/enumerate.js +77 -0
- package/lib/cores/kind.d.ts +55 -5
- package/lib/cores/search.d.ts +27 -8
- package/lib/cores/search.js +85 -28
- package/lib/kinds/cells/bishop.d.ts +1 -1
- package/lib/kinds/cells/bishop.js +1 -1
- package/lib/kinds/cells/counter.d.ts +26 -0
- package/lib/kinds/cells/counter.js +249 -0
- package/lib/kinds/cells/cut.d.ts +46 -0
- package/lib/kinds/cells/cut.js +400 -0
- package/lib/kinds/cells/figure.d.ts +13 -0
- package/lib/kinds/cells/figure.js +114 -0
- package/lib/kinds/cells/holes.d.ts +6 -0
- package/lib/kinds/cells/holes.js +57 -0
- package/lib/kinds/cells/kind.js +4 -2
- package/lib/kinds/cells/number.d.ts +6 -0
- package/lib/kinds/cells/number.js +32 -0
- package/lib/kinds/cells/operation.d.ts +12 -6
- package/lib/kinds/cells/paper.d.ts +10 -2
- package/lib/kinds/cells/paper.js +90 -8
- package/lib/kinds/cells/path.d.ts +38 -0
- package/lib/kinds/cells/path.js +288 -0
- package/lib/kinds/cells/piece.d.ts +10 -1
- package/lib/kinds/cells/piece.js +87 -3
- package/lib/kinds/cells/polyomino.d.ts +45 -0
- package/lib/kinds/cells/polyomino.js +450 -0
- package/lib/kinds/cells/registry.js +35 -4
- package/lib/kinds/cells/schema.js +41 -3
- package/lib/kinds/cells/sheet.d.ts +20 -1
- package/lib/kinds/cells/sheet.js +84 -6
- package/lib/kinds/cells/side.d.ts +33 -0
- package/lib/kinds/cells/side.js +86 -0
- package/lib/kinds/cells/sieve.d.ts +26 -0
- package/lib/kinds/cells/sieve.js +208 -0
- package/lib/kinds/cells/step.d.ts +1 -1
- package/lib/kinds/cells/step.js +1 -1
- package/package.json +5 -1
package/lib/cores/search.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// The core of search over states: a scene's whole state graph by layers of moves, each state with
|
|
2
|
-
// whether it meets the goal and its distance to it, and from the graph the scene's proof
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// whether it meets the goal and its distance to it, and from the graph the scene's proof, a key the
|
|
3
|
+
// goal asks read off it by the core of enumeration where it is a count, a maximum or a minimum. It
|
|
4
|
+
// serves a kind whose moves draw nothing at random — one state for each move —; a kind where a draw
|
|
5
|
+
// or an adversary answers a move needs the core of games, whose witness is a strategy.
|
|
6
|
+
import { counted, extreme, ways } from "./enumerate.js";
|
|
5
7
|
import { canonicalKey } from "./key.js";
|
|
6
8
|
/**
|
|
7
9
|
* The whole state graph of a scene, read from its JSON by the kind's schema: every state the
|
|
8
10
|
* scene's moves reach, layer by layer, states that are equal by their canonical key merged. A
|
|
9
11
|
* graph with more states than the kind's limit is undecided, wherever its goal lies: the limit
|
|
10
|
-
* holds every state a learner can reach, not only the search from the scene to the goal.
|
|
12
|
+
* holds every state a learner can reach, not only the search from the scene to the goal. A
|
|
13
|
+
* measure the goal asks that is no safe integer throws, as a state that is no JSON of integers
|
|
14
|
+
* does: either is a fault of the kind, not of the scene.
|
|
11
15
|
*/
|
|
12
16
|
export function stateGraph(kind, input, seed) {
|
|
13
17
|
const read = kind.read(input);
|
|
@@ -74,7 +78,11 @@ function search(kind, scene, seed) {
|
|
|
74
78
|
}
|
|
75
79
|
current = found;
|
|
76
80
|
}
|
|
77
|
-
|
|
81
|
+
const ask = asked(kind, scene);
|
|
82
|
+
const targets = ask.key === "max" || ask.key === "min"
|
|
83
|
+
? (extreme(nodes, ask.key, ask.measure)?.at ?? [])
|
|
84
|
+
: nodes.filter((node) => node.goal).map((node) => node.index);
|
|
85
|
+
distances(nodes, targets);
|
|
78
86
|
const graph = {
|
|
79
87
|
nodes,
|
|
80
88
|
layers,
|
|
@@ -93,20 +101,21 @@ function search(kind, scene, seed) {
|
|
|
93
101
|
};
|
|
94
102
|
return { ok: true, graph };
|
|
95
103
|
}
|
|
96
|
-
|
|
97
|
-
function
|
|
104
|
+
/** What the scene's goal asks: the fewest moves where the kind does not say, or the scene has no goal. */
|
|
105
|
+
function asked(kind, scene) {
|
|
106
|
+
return (kind.hasGoal(scene) ? kind.asks?.(scene) : undefined) ?? { key: "fewest" };
|
|
107
|
+
}
|
|
108
|
+
// Each state's distance to the states the key aims at: a search by layers backwards from them.
|
|
109
|
+
function distances(nodes, targets) {
|
|
98
110
|
const before = nodes.map(() => []);
|
|
99
111
|
for (const node of nodes) {
|
|
100
112
|
for (const edge of node.next) {
|
|
101
113
|
before[edge.to].push(node.index);
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
|
-
let current = [];
|
|
105
|
-
for (const
|
|
106
|
-
|
|
107
|
-
node.distance = 0;
|
|
108
|
-
current.push(node.index);
|
|
109
|
-
}
|
|
116
|
+
let current = [...targets];
|
|
117
|
+
for (const index of current) {
|
|
118
|
+
nodes[index].distance = 0;
|
|
110
119
|
}
|
|
111
120
|
for (let distance = 1; current.length > 0; distance++) {
|
|
112
121
|
const found = [];
|
|
@@ -122,13 +131,25 @@ function distances(nodes) {
|
|
|
122
131
|
current = found;
|
|
123
132
|
}
|
|
124
133
|
}
|
|
134
|
+
// The moves by which the search first reached a state, from the scene: a path of the fewest moves.
|
|
135
|
+
function pathTo(graph, end) {
|
|
136
|
+
const path = [];
|
|
137
|
+
for (let node = end; node.parent !== null;) {
|
|
138
|
+
path.push(node.parent.move);
|
|
139
|
+
node = graph.nodes[node.parent.from];
|
|
140
|
+
}
|
|
141
|
+
return path.reverse();
|
|
142
|
+
}
|
|
125
143
|
/**
|
|
126
|
-
* The proof of a scene, read from its JSON by the kind's schema. For a scene with a goal
|
|
127
|
-
* the fewest moves to the goal, with the path of the first state in the graph's order that
|
|
128
|
-
* it;
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
144
|
+
* The proof of a scene, read from its JSON by the kind's schema. For a scene with a goal, the key
|
|
145
|
+
* it asks: the fewest moves to the goal, with the path of the first state in the graph's order that
|
|
146
|
+
* meets it; how many states meet it, with a path to each, the first of each class where the scene
|
|
147
|
+
* gives symmetries; how many ways of the fewest moves reach it, with the first; or the greatest or
|
|
148
|
+
* least measure of a state that meets it, with the path to the first state of it. Where no state of
|
|
149
|
+
* the graph meets the goal, the key is "unreachable", the whole graph its witness. The order of the
|
|
150
|
+
* graph follows the kind's order of moves, so the same scene gives the same proof on every run. A
|
|
151
|
+
* scene with no goal has nothing to prove once its graph is within the limit; past the limit it
|
|
152
|
+
* does not decide, as any scene, nor where a count of ways passes what a key holds exactly.
|
|
132
153
|
*/
|
|
133
154
|
export function prove(kind, input, seed) {
|
|
134
155
|
const read = kind.read(input);
|
|
@@ -143,17 +164,46 @@ export function prove(kind, input, seed) {
|
|
|
143
164
|
return { undecided: "no-goal" };
|
|
144
165
|
}
|
|
145
166
|
const graph = result.graph;
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
167
|
+
const first = graph.nodes.find((node) => node.goal);
|
|
168
|
+
if (first === undefined) {
|
|
148
169
|
return { key: "unreachable", ends: [], graph };
|
|
149
170
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
171
|
+
const ask = asked(kind, read.scene);
|
|
172
|
+
switch (ask.key) {
|
|
173
|
+
case "count": {
|
|
174
|
+
const ends = counted(graph, ask.images);
|
|
175
|
+
return {
|
|
176
|
+
key: ends.length,
|
|
177
|
+
asks: "count",
|
|
178
|
+
paths: ends.map((end) => pathTo(graph, end)),
|
|
179
|
+
ends: ends.map((end) => end.state),
|
|
180
|
+
graph,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
case "paths": {
|
|
184
|
+
const { count, ends } = ways(graph);
|
|
185
|
+
if (!Number.isSafeInteger(count)) {
|
|
186
|
+
return { undecided: "limit" };
|
|
187
|
+
}
|
|
188
|
+
const end = ends[0];
|
|
189
|
+
return { key: count, asks: "paths", path: pathTo(graph, end), ends: [end.state], graph };
|
|
190
|
+
}
|
|
191
|
+
case "max":
|
|
192
|
+
case "min": {
|
|
193
|
+
// The states of the extreme measure are the ones at distance 0.
|
|
194
|
+
const end = graph.nodes.find((node) => node.distance === 0);
|
|
195
|
+
const key = ask.measure(end.state);
|
|
196
|
+
return { key, asks: ask.key, path: pathTo(graph, end), ends: [end.state], graph };
|
|
197
|
+
}
|
|
198
|
+
default:
|
|
199
|
+
return {
|
|
200
|
+
key: first.layer,
|
|
201
|
+
asks: "fewest",
|
|
202
|
+
path: pathTo(graph, first),
|
|
203
|
+
ends: [first.state],
|
|
204
|
+
graph,
|
|
205
|
+
};
|
|
154
206
|
}
|
|
155
|
-
path.reverse();
|
|
156
|
-
return { key: end.layer, path, ends: [end.state], graph };
|
|
157
207
|
}
|
|
158
208
|
/** A proof as JSON, as the scene vectors and a module's build take it. */
|
|
159
209
|
export function proofJson(proof) {
|
|
@@ -167,5 +217,12 @@ export function proofJson(proof) {
|
|
|
167
217
|
ends: [],
|
|
168
218
|
};
|
|
169
219
|
}
|
|
170
|
-
|
|
220
|
+
if (proof.asks === "count") {
|
|
221
|
+
return { key: proof.key, asks: "count", witness: { paths: proof.paths }, ends: proof.ends };
|
|
222
|
+
}
|
|
223
|
+
if (proof.asks === "fewest") {
|
|
224
|
+
// A key with no member asks is read as the fewest moves, so vectors written so stand.
|
|
225
|
+
return { key: proof.key, witness: { path: proof.path }, ends: proof.ends };
|
|
226
|
+
}
|
|
227
|
+
return { key: proof.key, asks: proof.asks, witness: { path: proof.path }, ends: proof.ends };
|
|
171
228
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const bishop: import("./operation.js").Operation<number>, bishopOn: import("./operation.js").Goal<number>;
|
|
1
|
+
export declare const bishop: import("./operation.js").Operation<number>, bishopOn: import("./operation.js").Goal<number>, bishopReach: import("./operation.js").Goal<import("./piece.js").Reach>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// their corners and crosses no side, so a wall never stops it; a hole on its diagonal does, as
|
|
3
3
|
// nothing passes through a hole.
|
|
4
4
|
import { piece } from "./piece.js";
|
|
5
|
-
export const { operation: bishop, goal: bishopOn } = piece({
|
|
5
|
+
export const { operation: bishop, goal: bishopOn, reach: bishopReach, } = piece({
|
|
6
6
|
name: "bishop",
|
|
7
7
|
description: "A chess bishop: it goes any number of cells along a diagonal, past walls, but never onto or past a hole.",
|
|
8
8
|
refusal(sheet, from, to) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Goal, Operation } from "./operation.js";
|
|
2
|
+
export interface CounterOptions {
|
|
3
|
+
/** The cell the counter starts on, by its index. */
|
|
4
|
+
readonly cell: number;
|
|
5
|
+
/** The steps it counts by, each a whole number of cells, back where it is below 0. */
|
|
6
|
+
readonly steps: readonly number[];
|
|
7
|
+
}
|
|
8
|
+
export declare const counter: Operation<CounterOptions>;
|
|
9
|
+
export interface CounterInOptions {
|
|
10
|
+
readonly least: number;
|
|
11
|
+
readonly most: number;
|
|
12
|
+
}
|
|
13
|
+
/** The counter stands on a number from least to most; the key counts those cells. */
|
|
14
|
+
export declare const counterIn: Goal<CounterInOptions>;
|
|
15
|
+
export interface MissedOptions {
|
|
16
|
+
/** The cells the counter ever stands on from its start, by their indices. */
|
|
17
|
+
readonly reached: ReadonlySet<number>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The greatest number the counter never stands on, a sum its steps never make: a state meets the
|
|
21
|
+
* goal where the counter stands on the number right after such a number, which is its measure.
|
|
22
|
+
* The table has no hole, and the counter stands on its last number, so the number after the
|
|
23
|
+
* greatest one missed is one it stands on; that every number past the table is a sum too, a row of
|
|
24
|
+
* numbers reached whole at the width of the least step shows, as a statement's table does.
|
|
25
|
+
*/
|
|
26
|
+
export declare const counterMissed: Goal<MissedOptions>;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// The counter of a table of numbers: a piece that counts on or back along the table's numbers by a
|
|
2
|
+
// step the scene gives, so a step past a row's end goes on into the next row, as the numbers do.
|
|
3
|
+
// It lands on no hole and counts past one, as a number cut out is still counted. Its goals count
|
|
4
|
+
// the numbers of a range it stands on, and ask the greatest number it never stands on.
|
|
5
|
+
import { array, integer, object, pointer } from "../../cores/json.js";
|
|
6
|
+
import { cellAt, cellName, maxNumber, maxSide, readCell, readTable, } from "./sheet.js";
|
|
7
|
+
const member = "counter_at";
|
|
8
|
+
/** The longest step: from the first cell of the largest sheet to its last. */
|
|
9
|
+
const longest = maxSide * maxSide - 1;
|
|
10
|
+
function refuse(reason) {
|
|
11
|
+
return { ok: false, reason };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The cell a state puts the counter on, or undefined where its member is no cell of the sheet, or a
|
|
15
|
+
* hole: a state reported from outside the kind may hold one, and then the counter stands nowhere.
|
|
16
|
+
*/
|
|
17
|
+
function where(sheet, state) {
|
|
18
|
+
const value = state[member];
|
|
19
|
+
const cell = typeof value === "string" ? cellAt(sheet, value) : undefined;
|
|
20
|
+
return cell === undefined || sheet.holes.has(cell) ? undefined : cell;
|
|
21
|
+
}
|
|
22
|
+
/** The cells one step takes the counter to, in reading order: on the sheet, and no hole. */
|
|
23
|
+
function next(sheet, steps, from) {
|
|
24
|
+
const cells = new Set();
|
|
25
|
+
for (const step of steps) {
|
|
26
|
+
const to = from + step;
|
|
27
|
+
if (to >= 0 && to < sheet.rows * sheet.cols && !sheet.holes.has(to)) {
|
|
28
|
+
cells.add(to);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [...cells].sort((a, b) => a - b);
|
|
32
|
+
}
|
|
33
|
+
export const counter = {
|
|
34
|
+
name: "counter",
|
|
35
|
+
schema: {
|
|
36
|
+
options: {
|
|
37
|
+
description: "A counter on a table of numbers, which counts on or back along the numbers by the steps given, past a row's end into the next row; it lands on no hole and counts past one.",
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
cell: {
|
|
41
|
+
description: "The cell the counter stands on at the scene's start, not a hole.",
|
|
42
|
+
$ref: "#/$defs/cell",
|
|
43
|
+
},
|
|
44
|
+
steps: {
|
|
45
|
+
description: "The steps the counter counts by, each a count of numbers, on where it is above 0 and back where it is below; none given twice.",
|
|
46
|
+
type: "array",
|
|
47
|
+
items: {
|
|
48
|
+
description: "A step: a count of numbers, on or back.",
|
|
49
|
+
type: "integer",
|
|
50
|
+
minimum: -longest,
|
|
51
|
+
maximum: longest,
|
|
52
|
+
not: { const: 0 },
|
|
53
|
+
},
|
|
54
|
+
minItems: 1,
|
|
55
|
+
uniqueItems: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["cell", "steps"],
|
|
59
|
+
unevaluatedProperties: false,
|
|
60
|
+
},
|
|
61
|
+
move: {
|
|
62
|
+
description: "A move of the counter by one of its steps, to the cell it lands on.",
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: { to: { description: "The cell the counter goes to.", $ref: "#/$defs/cell" } },
|
|
65
|
+
required: ["to"],
|
|
66
|
+
unevaluatedProperties: false,
|
|
67
|
+
},
|
|
68
|
+
state: {
|
|
69
|
+
member,
|
|
70
|
+
schema: { description: "The cell the counter stands on.", $ref: "#/$defs/cell" },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
read(value, sheet, path, errors) {
|
|
74
|
+
const before = errors.length;
|
|
75
|
+
const o = object(value, path, errors, ["cell", "steps"]);
|
|
76
|
+
if (o === undefined) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
readTable(sheet, path, errors, "a counter counts along them");
|
|
80
|
+
const at = pointer(path, "cell");
|
|
81
|
+
const cell = readCell(sheet, o.cell, at, errors);
|
|
82
|
+
if (cell !== undefined && sheet.holes.has(cell)) {
|
|
83
|
+
errors.push({ path: at, message: "a hole: the counter stands on no hole" });
|
|
84
|
+
}
|
|
85
|
+
const stepsPath = pointer(path, "steps");
|
|
86
|
+
const steps = [];
|
|
87
|
+
array(o.steps, stepsPath, errors, 1)?.forEach((item, i) => {
|
|
88
|
+
const step = integer(item, pointer(stepsPath, i), errors, -longest, longest);
|
|
89
|
+
if (step === 0) {
|
|
90
|
+
errors.push({ path: pointer(stepsPath, i), message: "a step of no number moves nothing" });
|
|
91
|
+
}
|
|
92
|
+
else if (step !== undefined && steps.includes(step)) {
|
|
93
|
+
errors.push({ path: pointer(stepsPath, i), message: "a step given twice" });
|
|
94
|
+
}
|
|
95
|
+
else if (step !== undefined) {
|
|
96
|
+
steps.push(step);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return errors.length > before || cell === undefined ? undefined : { cell, steps };
|
|
100
|
+
},
|
|
101
|
+
start: (sheet, options) => cellName(sheet, options.cell),
|
|
102
|
+
play(sheet, options, state, move) {
|
|
103
|
+
const errors = [];
|
|
104
|
+
const o = object(move, "", errors, ["to"]);
|
|
105
|
+
const to = o === undefined ? undefined : readCell(sheet, o.to, "/to", errors);
|
|
106
|
+
// A member besides the cell is no move of the counter: object() names it and still gives the rest.
|
|
107
|
+
if (to === undefined || errors.length > 0) {
|
|
108
|
+
return refuse("no-cell");
|
|
109
|
+
}
|
|
110
|
+
const from = where(sheet, state);
|
|
111
|
+
if (from === undefined) {
|
|
112
|
+
return refuse("no-piece");
|
|
113
|
+
}
|
|
114
|
+
if (sheet.holes.has(to)) {
|
|
115
|
+
return refuse("hole");
|
|
116
|
+
}
|
|
117
|
+
return options.steps.includes(to - from)
|
|
118
|
+
? { ok: true, state: { ...state, [member]: cellName(sheet, to) } }
|
|
119
|
+
: refuse("not-its-move");
|
|
120
|
+
},
|
|
121
|
+
moves(sheet, options, state) {
|
|
122
|
+
const from = where(sheet, state);
|
|
123
|
+
return from === undefined
|
|
124
|
+
? []
|
|
125
|
+
: next(sheet, options.steps, from).map((to) => ({ to: cellName(sheet, to) }));
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* The counter's parameters as a goal of it reads them: refused where the scene allows no counter,
|
|
130
|
+
* or another operation beside it, since the goal's states are to be the counter's cells.
|
|
131
|
+
*/
|
|
132
|
+
function counterOf(path, errors, operations, what) {
|
|
133
|
+
if (!operations.has(counter.name)) {
|
|
134
|
+
errors.push({ path, message: `the scene allows no operation counter, so ${what}` });
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const options = operations.get(counter.name);
|
|
138
|
+
// Where the counter's own parameters, or another operation's, do not read, the scene is refused
|
|
139
|
+
// for them alone.
|
|
140
|
+
const others = [...operations]
|
|
141
|
+
.filter(([named, read]) => named !== counter.name && read !== undefined)
|
|
142
|
+
.map(([named]) => named);
|
|
143
|
+
if (options !== undefined && others.length > 0) {
|
|
144
|
+
errors.push({
|
|
145
|
+
path,
|
|
146
|
+
message: `the scene allows ${others.join(", ")} beside counter: the goal's states are to be the counter's cells`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return options;
|
|
150
|
+
}
|
|
151
|
+
const bound = (description) => ({
|
|
152
|
+
description,
|
|
153
|
+
type: "integer",
|
|
154
|
+
minimum: 0,
|
|
155
|
+
maximum: maxNumber,
|
|
156
|
+
});
|
|
157
|
+
/** The counter stands on a number from least to most; the key counts those cells. */
|
|
158
|
+
export const counterIn = {
|
|
159
|
+
name: "counter_in",
|
|
160
|
+
schema: {
|
|
161
|
+
description: "The counter stands on a number from least to most; the key counts the cells of those numbers it reaches. The scene allows the operation counter alone, so that its states are the counter's cells.",
|
|
162
|
+
type: "object",
|
|
163
|
+
properties: {
|
|
164
|
+
least: bound("The least number counted; the table's first by default."),
|
|
165
|
+
most: bound("The greatest number counted; the table's last by default."),
|
|
166
|
+
},
|
|
167
|
+
unevaluatedProperties: false,
|
|
168
|
+
},
|
|
169
|
+
read(value, _sheet, path, errors, operations) {
|
|
170
|
+
const before = errors.length;
|
|
171
|
+
const o = object(value, path, errors, [], ["least", "most"]);
|
|
172
|
+
const least = o?.least === undefined ? 0 : integer(o.least, pointer(path, "least"), errors, 0, maxNumber);
|
|
173
|
+
const most = o?.most === undefined
|
|
174
|
+
? maxNumber
|
|
175
|
+
: integer(o.most, pointer(path, "most"), errors, 0, maxNumber);
|
|
176
|
+
if (least !== undefined && most !== undefined && least > most) {
|
|
177
|
+
errors.push({ path: pointer(path, "least"), message: "no more than the greatest number" });
|
|
178
|
+
}
|
|
179
|
+
counterOf(path, errors, operations, "nothing stands on a number");
|
|
180
|
+
return errors.length > before || least === undefined || most === undefined
|
|
181
|
+
? undefined
|
|
182
|
+
: { least, most };
|
|
183
|
+
},
|
|
184
|
+
meets(sheet, goal, state) {
|
|
185
|
+
const cell = where(sheet, state);
|
|
186
|
+
const number = cell === undefined ? undefined : sheet.first + cell;
|
|
187
|
+
return number !== undefined && number >= goal.least && number <= goal.most;
|
|
188
|
+
},
|
|
189
|
+
asks: () => ({ key: "count" }),
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* The greatest number the counter never stands on, a sum its steps never make: a state meets the
|
|
193
|
+
* goal where the counter stands on the number right after such a number, which is its measure.
|
|
194
|
+
* The table has no hole, and the counter stands on its last number, so the number after the
|
|
195
|
+
* greatest one missed is one it stands on; that every number past the table is a sum too, a row of
|
|
196
|
+
* numbers reached whole at the width of the least step shows, as a statement's table does.
|
|
197
|
+
*/
|
|
198
|
+
export const counterMissed = {
|
|
199
|
+
name: "counter_missed",
|
|
200
|
+
schema: {
|
|
201
|
+
description: "The counter stands on the number right after one it never stands on from its start; the key is the greatest number it never stands on, read before a number it does. The scene allows the operation counter alone, on a table with no hole whose last number the counter stands on.",
|
|
202
|
+
type: "object",
|
|
203
|
+
unevaluatedProperties: false,
|
|
204
|
+
},
|
|
205
|
+
read(value, sheet, path, errors, operations) {
|
|
206
|
+
const before = errors.length;
|
|
207
|
+
object(value, path, errors, []);
|
|
208
|
+
const options = counterOf(path, errors, operations, "no number is missed");
|
|
209
|
+
if (sheet.holes.size > 0) {
|
|
210
|
+
errors.push({ path, message: "a table with holes: a number cut out is no sum missed" });
|
|
211
|
+
}
|
|
212
|
+
if (errors.length > before) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
// Where the counter's own parameters do not read, the scene is refused for them alone.
|
|
216
|
+
const start = options === undefined ? [] : [options.cell];
|
|
217
|
+
const reached = new Set(start);
|
|
218
|
+
for (let layer = start; options !== undefined && layer.length > 0;) {
|
|
219
|
+
const found = [];
|
|
220
|
+
for (const from of layer) {
|
|
221
|
+
for (const to of next(sheet, options.steps, from)) {
|
|
222
|
+
if (!reached.has(to)) {
|
|
223
|
+
reached.add(to);
|
|
224
|
+
found.push(to);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
layer = found;
|
|
229
|
+
}
|
|
230
|
+
// Where the counter stands on the table's last number, the number after the greatest one it
|
|
231
|
+
// misses is one it stands on, so a state meets the goal with that measure.
|
|
232
|
+
if (options !== undefined && !reached.has(sheet.rows * sheet.cols - 1)) {
|
|
233
|
+
errors.push({
|
|
234
|
+
path,
|
|
235
|
+
message: "the counter never stands on the table's last number: the greatest missed is past it",
|
|
236
|
+
});
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
return { reached };
|
|
240
|
+
},
|
|
241
|
+
meets(sheet, goal, state) {
|
|
242
|
+
const cell = where(sheet, state);
|
|
243
|
+
return cell !== undefined && cell > 0 && !goal.reached.has(cell - 1);
|
|
244
|
+
},
|
|
245
|
+
asks: (sheet) => ({
|
|
246
|
+
key: "max",
|
|
247
|
+
measure: (state) => sheet.first + where(sheet, state) - 1,
|
|
248
|
+
}),
|
|
249
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Goal, Operation } from "./operation.js";
|
|
2
|
+
import { type Sheet, type State } from "./sheet.js";
|
|
3
|
+
export declare const alongs: readonly ["side", "part", "line"];
|
|
4
|
+
export type Along = (typeof alongs)[number];
|
|
5
|
+
export interface CutOptions {
|
|
6
|
+
/** How far a cut runs from the side a move names. */
|
|
7
|
+
readonly along: Along;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The sides a state has cut, by their index among the sheet's sides between cells; undefined where
|
|
11
|
+
* its member "cut" is no list of sides a cut may part, each once, in the sheet's order of sides —
|
|
12
|
+
* a state reported from outside the kind may hold one, and then no cut is played from it and no
|
|
13
|
+
* goal is met.
|
|
14
|
+
*/
|
|
15
|
+
export declare function cutsOf(sheet: Sheet, state: State): ReadonlySet<number> | undefined;
|
|
16
|
+
/** The parts of a sheet: each cell's part, -1 for a hole, and the cells of each part. */
|
|
17
|
+
export interface Parts {
|
|
18
|
+
readonly of: readonly number[];
|
|
19
|
+
readonly sizes: readonly number[];
|
|
20
|
+
}
|
|
21
|
+
/** The parts the cuts and the sheet's walls and holes make of the sheet. */
|
|
22
|
+
export declare function partsOf(sheet: Sheet, cuts: ReadonlySet<number>): Parts;
|
|
23
|
+
export declare const cut: Operation<CutOptions>;
|
|
24
|
+
/** What a goal of the parts reads of the scene: whether it cuts, so that a state keeps cuts. */
|
|
25
|
+
interface Cuts {
|
|
26
|
+
readonly cuts: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The parts of the sheet; the key is the most there are. */
|
|
29
|
+
export declare const parts: Goal<Cuts>;
|
|
30
|
+
/** Every cell apart, a part of its own; the key is the fewest cuts. */
|
|
31
|
+
export declare const cellsApart: Goal<Cuts>;
|
|
32
|
+
export interface Ways {
|
|
33
|
+
/** How many parts the sheet is cut into, each of as many cells. */
|
|
34
|
+
readonly parts: number;
|
|
35
|
+
}
|
|
36
|
+
/** The sheet cut into parts of as many cells each; the key counts the ways. */
|
|
37
|
+
export declare const cutWays: Goal<Ways>;
|
|
38
|
+
export interface Count extends Cuts {
|
|
39
|
+
/** Only those on an edge: the sheet's, a hole's, a wall or a cut. */
|
|
40
|
+
readonly edge: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** The nodes of the grid, every one or those on an edge; the key is the most. */
|
|
43
|
+
export declare const nodes: Goal<Count>;
|
|
44
|
+
/** The sides of cells, every one or those on an edge; the key is the most. */
|
|
45
|
+
export declare const sides: Goal<Count>;
|
|
46
|
+
export {};
|