@altnovatrail/widgets 0.2.1 → 0.3.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/cores/vector.schema.json +22 -1
  3. package/kinds/cards/cards.handles.json +109 -0
  4. package/kinds/cards/cards.schema.json +483 -0
  5. package/kinds/cards/vectors/any.json +255 -0
  6. package/kinds/cards/vectors/box.json +325 -0
  7. package/kinds/cards/vectors/fork-taps.json +305 -0
  8. package/kinds/cards/vectors/fork.json +254 -0
  9. package/kinds/cards/vectors/invalid-goal.json +70 -0
  10. package/kinds/cards/vectors/invalid-ids.json +113 -0
  11. package/kinds/cards/vectors/invalid-schema.json +88 -0
  12. package/kinds/cards/vectors/invalid-taps.json +214 -0
  13. package/kinds/cards/vectors/key.json +264 -0
  14. package/kinds/cards/vectors/limit.json +274 -0
  15. package/kinds/cards/vectors/no-goal.json +205 -0
  16. package/kinds/cards/vectors/none.json +239 -0
  17. package/kinds/cards/vectors/recog.json +113 -0
  18. package/kinds/cards/vectors/riddle.json +397 -0
  19. package/kinds/cards/vectors/solo.json +218 -0
  20. package/kinds/cells/cells.schema.json +17 -2
  21. package/kinds/line/line.schema.json +17 -2
  22. package/lib/cores/kind.d.ts +21 -3
  23. package/lib/cores/search.d.ts +22 -6
  24. package/lib/cores/search.js +34 -6
  25. package/lib/kinds/cards/goal.d.ts +25 -0
  26. package/lib/kinds/cards/goal.js +72 -0
  27. package/lib/kinds/cards/index.d.ts +14 -0
  28. package/lib/kinds/cards/index.js +17 -0
  29. package/lib/kinds/cards/kind.d.ts +23 -0
  30. package/lib/kinds/cards/kind.js +101 -0
  31. package/lib/kinds/cards/parts.d.ts +36 -0
  32. package/lib/kinds/cards/parts.js +34 -0
  33. package/lib/kinds/cards/scene.d.ts +102 -0
  34. package/lib/kinds/cards/scene.js +356 -0
  35. package/lib/kinds/cards/schema.d.ts +10 -0
  36. package/lib/kinds/cards/schema.js +285 -0
  37. package/lib/kinds/cells/registry.js +1 -1
  38. package/lib/kinds/cells/schema.js +3 -1
  39. package/lib/kinds/line/registry.js +1 -1
  40. package/lib/kinds/line/schema.js +3 -1
  41. package/package.json +8 -3
  42. package/cores/handles.schema.json +0 -63
@@ -0,0 +1,218 @@
1
+ {
2
+ "description": "The task on one's own of the lesson on signs, the odd one out by every sign but colour: A and E share a hat, B and C spots, and D alone has three legs.",
3
+ "scene": {
4
+ "signs": [
5
+ {
6
+ "id": "colour",
7
+ "label": "colour",
8
+ "values": [
9
+ {
10
+ "id": "blue",
11
+ "label": "blue"
12
+ },
13
+ {
14
+ "id": "pink",
15
+ "label": "pink"
16
+ },
17
+ {
18
+ "id": "yellow",
19
+ "label": "yellow"
20
+ },
21
+ {
22
+ "id": "purple",
23
+ "label": "purple"
24
+ },
25
+ {
26
+ "id": "green",
27
+ "label": "green"
28
+ },
29
+ {
30
+ "id": "orange",
31
+ "label": "orange"
32
+ }
33
+ ]
34
+ },
35
+ {
36
+ "id": "pattern",
37
+ "label": "pattern",
38
+ "values": [
39
+ {
40
+ "id": "plain",
41
+ "label": "plain"
42
+ },
43
+ {
44
+ "id": "stripes",
45
+ "label": "stripes"
46
+ },
47
+ {
48
+ "id": "spots",
49
+ "label": "spots"
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ "id": "eyes",
55
+ "label": "eyes",
56
+ "values": [
57
+ {
58
+ "id": "1",
59
+ "label": "one eye"
60
+ },
61
+ {
62
+ "id": "2",
63
+ "label": "two eyes"
64
+ },
65
+ {
66
+ "id": "3",
67
+ "label": "three eyes"
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "id": "horns",
73
+ "label": "horns",
74
+ "values": [
75
+ {
76
+ "id": "no",
77
+ "label": "no horns"
78
+ },
79
+ {
80
+ "id": "yes",
81
+ "label": "horns"
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "id": "hat",
87
+ "label": "hat",
88
+ "values": [
89
+ {
90
+ "id": "no",
91
+ "label": "no hat"
92
+ },
93
+ {
94
+ "id": "yes",
95
+ "label": "a hat"
96
+ }
97
+ ]
98
+ },
99
+ {
100
+ "id": "legs",
101
+ "label": "legs",
102
+ "values": [
103
+ {
104
+ "id": "2",
105
+ "label": "two legs"
106
+ },
107
+ {
108
+ "id": "3",
109
+ "label": "three legs"
110
+ }
111
+ ]
112
+ }
113
+ ],
114
+ "groups": [
115
+ {
116
+ "id": "cards",
117
+ "cards": [
118
+ {
119
+ "id": "A",
120
+ "signs": {
121
+ "colour": "green",
122
+ "pattern": "plain",
123
+ "eyes": "2",
124
+ "horns": "no",
125
+ "hat": "yes",
126
+ "legs": "2"
127
+ }
128
+ },
129
+ {
130
+ "id": "B",
131
+ "signs": {
132
+ "colour": "blue",
133
+ "pattern": "spots",
134
+ "eyes": "2",
135
+ "horns": "no",
136
+ "hat": "no",
137
+ "legs": "2"
138
+ }
139
+ },
140
+ {
141
+ "id": "C",
142
+ "signs": {
143
+ "colour": "pink",
144
+ "pattern": "spots",
145
+ "eyes": "2",
146
+ "horns": "no",
147
+ "hat": "no",
148
+ "legs": "2"
149
+ }
150
+ },
151
+ {
152
+ "id": "D",
153
+ "signs": {
154
+ "colour": "yellow",
155
+ "pattern": "plain",
156
+ "eyes": "2",
157
+ "horns": "no",
158
+ "hat": "no",
159
+ "legs": "3"
160
+ }
161
+ },
162
+ {
163
+ "id": "E",
164
+ "signs": {
165
+ "colour": "purple",
166
+ "pattern": "plain",
167
+ "eyes": "2",
168
+ "horns": "no",
169
+ "hat": "yes",
170
+ "legs": "2"
171
+ }
172
+ }
173
+ ]
174
+ }
175
+ ],
176
+ "goal": {
177
+ "differs": ["pattern", "eyes", "horns", "hat", "legs"]
178
+ }
179
+ },
180
+ "seed": "0",
181
+ "start": {
182
+ "state": {
183
+ "chosen": []
184
+ },
185
+ "goal": false
186
+ },
187
+ "sequences": [],
188
+ "proof": {
189
+ "key": ["D"],
190
+ "asks": "parts",
191
+ "witness": {
192
+ "rule": {
193
+ "differs": ["pattern", "eyes", "horns", "hat", "legs"]
194
+ },
195
+ "rows": [
196
+ {
197
+ "card": "A",
198
+ "same": "E"
199
+ },
200
+ {
201
+ "card": "B",
202
+ "same": "C"
203
+ },
204
+ {
205
+ "card": "C",
206
+ "same": "B"
207
+ },
208
+ {
209
+ "card": "D"
210
+ },
211
+ {
212
+ "card": "E",
213
+ "same": "A"
214
+ }
215
+ ]
216
+ }
217
+ }
218
+ }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://altnovatrail.github.io/widgets/kinds/cells/3.1/cells.schema.json",
3
+ "$id": "https://altnovatrail.github.io/widgets/kinds/cells/3.2/cells.schema.json",
4
4
  "title": "A scene of the widget kind cells",
5
- "description": "A sheet of cells, the operations a learner may play on it with their parameters, and at most one goal a state may meet. Under $defs, a move and a state of the kind.",
5
+ "description": "A sheet of cells, the operations a learner may play on it with their parameters, and at most one goal a state may meet. Under $defs, a move and a state of the kind, and the form of a scene's key.",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "sheet": {
@@ -1236,6 +1236,21 @@
1236
1236
  "required": [
1237
1237
  "marks"
1238
1238
  ]
1239
+ },
1240
+ "key": {
1241
+ "description": "The key of a scene, the form of the kind solver's proof: a whole number, whatever the goal asks — the fewest moves, a count, a maximum or a minimum —, or unreachable, where no state meets the goal.",
1242
+ "oneOf": [
1243
+ {
1244
+ "description": "What the goal asks, a whole number.",
1245
+ "type": "integer",
1246
+ "minimum": 0,
1247
+ "maximum": 9007199254740991
1248
+ },
1249
+ {
1250
+ "description": "No state of the scene's state graph meets the goal.",
1251
+ "const": "unreachable"
1252
+ }
1253
+ ]
1239
1254
  }
1240
1255
  }
1241
1256
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://altnovatrail.github.io/widgets/kinds/line/1.2/line.schema.json",
3
+ "$id": "https://altnovatrail.github.io/widgets/kinds/line/1.3/line.schema.json",
4
4
  "title": "A scene of the widget kind line",
5
- "description": "A line of places, the operations a learner may play on it with their parameters, and at most one goal a state may meet. Under $defs, a move and a state of the kind.",
5
+ "description": "A line of places, the operations a learner may play on it with their parameters, and at most one goal a state may meet. Under $defs, a move and a state of the kind, and the form of a scene's key.",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "line": {
@@ -316,6 +316,21 @@
316
316
  "required": [
317
317
  "posts"
318
318
  ]
319
+ },
320
+ "key": {
321
+ "description": "The key of a scene, the form of the kind solver's proof: a whole number, whatever the goal asks — the fewest moves, a count, a maximum or a minimum —, or unreachable, where no state meets the goal.",
322
+ "oneOf": [
323
+ {
324
+ "description": "What the goal asks, a whole number.",
325
+ "type": "integer",
326
+ "minimum": 0,
327
+ "maximum": 9007199254740991
328
+ },
329
+ {
330
+ "description": "No state of the scene's state graph meets the goal.",
331
+ "const": "unreachable"
332
+ }
333
+ ]
319
334
  }
320
335
  }
321
336
  }
@@ -89,8 +89,13 @@ export interface Kind<Scene, State extends Json, Move extends Json> {
89
89
  * - paths — how many ways of the fewest moves lead to a state that meets it, two moves to one state
90
90
  * two ways; where every move leads one layer on, as moves right and down do, that is every way;
91
91
  * - max, min — the greatest or least measure of a state that meets it, a safe integer, since the
92
- * rules are exact.
93
- * Where no state meets the goal, the key is "unreachable", whatever the goal asks.
92
+ * rules are exact;
93
+ * - parts — which of the scene's parts meet the goal, by their IDs, none where none does, read off
94
+ * the scene with no search, and the witness that shows it, of the kind's own form: a kind whose
95
+ * answer is no number gives them, and its states meet the goal where they hold that answer. The
96
+ * proof's key gives each ID once, sorted by UTF-16 code units, whatever order the kind gives.
97
+ * Where no state meets the goal, the key is "unreachable", whatever the goal asks but parts, whose
98
+ * key is the parts whatever states the moves reach.
94
99
  */
95
100
  export type Ask<State> = {
96
101
  readonly key: "fewest";
@@ -102,6 +107,12 @@ export type Ask<State> = {
102
107
  } | {
103
108
  readonly key: "max" | "min";
104
109
  measure(state: State): number;
110
+ } | {
111
+ readonly key: "parts";
112
+ readonly parts: readonly string[];
113
+ readonly witness: {
114
+ readonly [member: string]: Json;
115
+ };
105
116
  };
106
117
  /**
107
118
  * Why a scene gives no proof: limit, its state graph passes the kind's limit of states or of
@@ -122,7 +133,8 @@ export type Undecided = {
122
133
  * of its layers. A number with no member asks is the fewest moves to the goal, a path of them its
123
134
  * witness; asks names any other key and its witness: count, a path to each state counted — one of
124
135
  * each class where the scene gives symmetries — in the graph's order; paths, the first of the
125
- * ways counted; max or min, the path to the first state of that measure. The ends are the states
136
+ * ways counted; max or min, the path to the first state of that measure; parts, the sorted IDs of
137
+ * the parts that meet the goal, with the kind's own witness and no ends. The ends are the states
126
138
  * the witness ends in, each meeting the goal. The member witness names its form, so that a core
127
139
  * whose witness is no path adds its own.
128
140
  */
@@ -146,6 +158,12 @@ export type ProofJson = {
146
158
  readonly path: readonly Json[];
147
159
  };
148
160
  readonly ends: readonly Json[];
161
+ } | {
162
+ readonly key: readonly string[];
163
+ readonly asks: "parts";
164
+ readonly witness: {
165
+ readonly [member: string]: Json;
166
+ };
149
167
  } | {
150
168
  readonly key: "unreachable";
151
169
  readonly witness: {
@@ -62,7 +62,8 @@ export type GraphResult<State, Move> = {
62
62
  }));
63
63
  /**
64
64
  * A scene's proof with its whole state graph: the key the goal asks with its witness — the path to
65
- * the state it ends in, or for a count a path to each state counted — and those states.
65
+ * the state it ends in, or for a count a path to each state counted — and those states; or the parts
66
+ * a kind reads off its scene, with its own witness.
66
67
  */
67
68
  export type Proof<State, Move> = {
68
69
  readonly key: number;
@@ -76,6 +77,13 @@ export type Proof<State, Move> = {
76
77
  readonly paths: readonly (readonly Move[])[];
77
78
  readonly ends: readonly State[];
78
79
  readonly graph: StateGraph<State, Move>;
80
+ } | {
81
+ readonly key: readonly string[];
82
+ readonly asks: "parts";
83
+ readonly witness: {
84
+ readonly [member: string]: Json;
85
+ };
86
+ readonly graph: StateGraph<State, Move>;
79
87
  } | {
80
88
  readonly key: "unreachable";
81
89
  readonly ends: readonly [];
@@ -96,12 +104,20 @@ export declare function stateGraph<Scene, State extends Json, Move extends Json>
96
104
  * it asks: the fewest moves to the goal, with the path of the first state in the graph's order that
97
105
  * meets it; how many states meet it, with a path to each, the first of each class where the scene
98
106
  * gives symmetries; how many ways of the fewest moves reach it, with the first; or the greatest or
99
- * least measure of a state that meets it, with the path to the first state of it. Where no state of
100
- * the graph meets the goal, the key is "unreachable", the whole graph its witness. The order of the
101
- * graph follows the kind's order of moves, so the same scene gives the same proof on every run. A
102
- * scene with no goal has nothing to prove once its graph is within the limit; past the limit it
103
- * does not decide, as any scene, nor where a count of ways passes what a key holds exactly.
107
+ * least measure of a state that meets it, with the path to the first state of it; or the parts the
108
+ * kind reads off its scene, with its own witness, whatever states the graph reaches. Where no state
109
+ * of the graph meets any other goal, the key is "unreachable", the whole graph its witness. The
110
+ * order of the graph follows the kind's order of moves, so the same scene gives the same proof on
111
+ * every run, and a key of parts gives each ID once, sorted by UTF-16 code units. A scene with no
112
+ * goal has nothing to prove once its graph is within the limit; past the limit it does not
113
+ * decide, as any scene, nor where a count of ways passes what a key holds exactly.
104
114
  */
105
115
  export declare function prove<Scene, State extends Json, Move extends Json>(kind: Kind<Scene, State, Move>, input: unknown, seed: string): Proof<State, Move>;
116
+ /**
117
+ * The form of a key this core proves, as the scene schema of a kind on it declares it under
118
+ * $defs/key: a module's build compares the key of the proof with a scene's key as they are, so the
119
+ * form is the proof's own, whatever the goal asks.
120
+ */
121
+ export declare const searchKeySchema: Json;
106
122
  /** A proof as JSON, as the scene vectors and a module's build take it. */
107
123
  export declare function proofJson<State extends Json, Move extends Json>(proof: Proof<State, Move>): ProofJson;
@@ -208,11 +208,13 @@ function pathTo(graph, end) {
208
208
  * it asks: the fewest moves to the goal, with the path of the first state in the graph's order that
209
209
  * meets it; how many states meet it, with a path to each, the first of each class where the scene
210
210
  * gives symmetries; how many ways of the fewest moves reach it, with the first; or the greatest or
211
- * least measure of a state that meets it, with the path to the first state of it. Where no state of
212
- * the graph meets the goal, the key is "unreachable", the whole graph its witness. The order of the
213
- * graph follows the kind's order of moves, so the same scene gives the same proof on every run. A
214
- * scene with no goal has nothing to prove once its graph is within the limit; past the limit it
215
- * does not decide, as any scene, nor where a count of ways passes what a key holds exactly.
211
+ * least measure of a state that meets it, with the path to the first state of it; or the parts the
212
+ * kind reads off its scene, with its own witness, whatever states the graph reaches. Where no state
213
+ * of the graph meets any other goal, the key is "unreachable", the whole graph its witness. The
214
+ * order of the graph follows the kind's order of moves, so the same scene gives the same proof on
215
+ * every run, and a key of parts gives each ID once, sorted by UTF-16 code units. A scene with no
216
+ * goal has nothing to prove once its graph is within the limit; past the limit it does not
217
+ * decide, as any scene, nor where a count of ways passes what a key holds exactly.
216
218
  */
217
219
  export function prove(kind, input, seed) {
218
220
  const read = kind.read(input);
@@ -227,11 +229,17 @@ export function prove(kind, input, seed) {
227
229
  return { undecided: "no-goal" };
228
230
  }
229
231
  const graph = result.graph;
232
+ const ask = asked(kind, read.scene);
233
+ if (ask.key === "parts") {
234
+ // The parts are read off the scene, whatever states its moves reach; a module's build compares
235
+ // keys as written, so the order is the proof's, not the kind's.
236
+ const key = [...new Set(ask.parts)].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
237
+ return { key, asks: "parts", witness: ask.witness, graph };
238
+ }
230
239
  const first = graph.nodes.find((node) => node.goal);
231
240
  if (first === undefined) {
232
241
  return { key: "unreachable", ends: [], graph };
233
242
  }
234
- const ask = asked(kind, read.scene);
235
243
  switch (ask.key) {
236
244
  case "count": {
237
245
  const ends = counted(graph, ask.images);
@@ -268,6 +276,23 @@ export function prove(kind, input, seed) {
268
276
  };
269
277
  }
270
278
  }
279
+ /**
280
+ * The form of a key this core proves, as the scene schema of a kind on it declares it under
281
+ * $defs/key: a module's build compares the key of the proof with a scene's key as they are, so the
282
+ * form is the proof's own, whatever the goal asks.
283
+ */
284
+ export const searchKeySchema = {
285
+ description: "The key of a scene, the form of the kind solver's proof: a whole number, whatever the goal asks — the fewest moves, a count, a maximum or a minimum —, or unreachable, where no state meets the goal.",
286
+ oneOf: [
287
+ {
288
+ description: "What the goal asks, a whole number.",
289
+ type: "integer",
290
+ minimum: 0,
291
+ maximum: Number.MAX_SAFE_INTEGER,
292
+ },
293
+ { description: "No state of the scene's state graph meets the goal.", const: "unreachable" },
294
+ ],
295
+ };
271
296
  /** A proof as JSON, as the scene vectors and a module's build take it. */
272
297
  export function proofJson(proof) {
273
298
  if ("undecided" in proof) {
@@ -280,6 +305,9 @@ export function proofJson(proof) {
280
305
  ends: [],
281
306
  };
282
307
  }
308
+ if (proof.asks === "parts") {
309
+ return { key: proof.key, asks: "parts", witness: proof.witness };
310
+ }
283
311
  if (proof.asks === "count") {
284
312
  return { key: proof.key, asks: "count", witness: { paths: proof.paths }, ends: proof.ends };
285
313
  }
@@ -0,0 +1,25 @@
1
+ import type { Json } from "../../cores/kind.js";
2
+ import { type Card, type Condition, type Literal, type Scene } from "./scene.js";
3
+ /** The cards a goal ranges over, in the scene's order. */
4
+ export declare function range(scene: Scene, among: readonly string[]): Card[];
5
+ /** Whether a card meets a literal: has the value it names, or any other. */
6
+ export declare function fits(card: Card, literal: Literal): boolean;
7
+ /** A condition's literals, depth first, in the order the witness gives a card's fits. */
8
+ export declare function literals(condition: Condition): Literal[];
9
+ /** The answer of a scene with a goal: the sorted IDs of the cards that meet it, and its witness. */
10
+ export interface Answer {
11
+ readonly parts: readonly string[];
12
+ readonly witness: {
13
+ readonly [member: string]: Json;
14
+ };
15
+ }
16
+ /**
17
+ * The cards of the goal's range that meet it, by their IDs sorted by UTF-16 code units, and the
18
+ * witness: the rule — the condition the goal names, the values the group shares as an all of them,
19
+ * or the signs a card must differ by — and a row for each card of the range in the scene's order,
20
+ * with whether it fits each literal of the rule, depth first, or the first other card it does not
21
+ * differ from, none for a card that differs from every other.
22
+ */
23
+ export declare function answer(scene: Scene): Answer | null;
24
+ /** A condition as the scene's JSON gives it. */
25
+ export declare function conditionJson(condition: Condition): Json;
@@ -0,0 +1,72 @@
1
+ import { shared, } from "./scene.js";
2
+ /** The cards a goal ranges over, in the scene's order. */
3
+ export function range(scene, among) {
4
+ return scene.groups.filter((group) => among.includes(group.id)).flatMap((group) => group.cards);
5
+ }
6
+ /** Whether a card meets a literal: has the value it names, or any other. */
7
+ export function fits(card, literal) {
8
+ const value = card.signs.get(literal.sign);
9
+ return "is" in literal ? value === literal.is : value !== literal.not;
10
+ }
11
+ function holds(card, condition) {
12
+ if ("all" in condition)
13
+ return condition.all.every((c) => holds(card, c));
14
+ if ("any" in condition)
15
+ return condition.any.some((c) => holds(card, c));
16
+ return fits(card, condition);
17
+ }
18
+ /** A condition's literals, depth first, in the order the witness gives a card's fits. */
19
+ export function literals(condition) {
20
+ if ("all" in condition)
21
+ return condition.all.flatMap(literals);
22
+ if ("any" in condition)
23
+ return condition.any.flatMap(literals);
24
+ return [condition];
25
+ }
26
+ /** Whether two cards give the same value to every sign named. */
27
+ const same = (a, b, signs) => signs.every((sign) => a.signs.get(sign) === b.signs.get(sign));
28
+ const byCodeUnits = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
29
+ /**
30
+ * The cards of the goal's range that meet it, by their IDs sorted by UTF-16 code units, and the
31
+ * witness: the rule — the condition the goal names, the values the group shares as an all of them,
32
+ * or the signs a card must differ by — and a row for each card of the range in the scene's order,
33
+ * with whether it fits each literal of the rule, depth first, or the first other card it does not
34
+ * differ from, none for a card that differs from every other.
35
+ */
36
+ export function answer(scene) {
37
+ const goal = scene.goal;
38
+ if (goal === null)
39
+ return null;
40
+ const cards = range(scene, goal.among);
41
+ if ("differs" in goal) {
42
+ const rows = cards.map((card) => {
43
+ const twin = cards.find((other) => other !== card && same(card, other, goal.differs));
44
+ return twin === undefined ? { card: card.id } : { card: card.id, same: twin.id };
45
+ });
46
+ const parts = cards
47
+ .filter((card) => !cards.some((other) => other !== card && same(card, other, goal.differs)))
48
+ .map((card) => card.id);
49
+ return {
50
+ parts: parts.sort(byCodeUnits),
51
+ witness: { rule: { differs: [...goal.differs] }, rows },
52
+ };
53
+ }
54
+ const condition = "signs" in goal
55
+ ? goal.signs
56
+ : // The reading takes only a group of the scene for the one a goal learns from.
57
+ { all: shared(scene.groups.find((group) => group.id === goal.like), scene.signs) };
58
+ const each = literals(condition);
59
+ const rows = cards.map((card) => ({ card: card.id, fits: each.map((literal) => fits(card, literal)) }));
60
+ const parts = cards.filter((card) => holds(card, condition)).map((card) => card.id);
61
+ return { parts: parts.sort(byCodeUnits), witness: { rule: conditionJson(condition), rows } };
62
+ }
63
+ /** A condition as the scene's JSON gives it. */
64
+ export function conditionJson(condition) {
65
+ if ("all" in condition)
66
+ return { all: condition.all.map(conditionJson) };
67
+ if ("any" in condition)
68
+ return { any: condition.any.map(conditionJson) };
69
+ return "is" in condition
70
+ ? { sign: condition.sign, is: condition.is }
71
+ : { sign: condition.sign, not: condition.not };
72
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The most states a scene's whole state graph may hold, at a build and on a device alike: the
3
+ * same as the kinds cells' and line's. A scene whose taps choose one card has a state for each
4
+ * card and option and one with none; one whose taps choose many has every set of them, so eleven
5
+ * cards and options to choose take 2,048 states, and twelve pass the limit.
6
+ */
7
+ export declare const limit = 3000;
8
+ /**
9
+ * The most work a scene's whole state graph may take, as the search core counts it: the same as
10
+ * the kinds cells' and line's. A state of cards is a short list of IDs, so a graph within the
11
+ * limit of states takes a small part of it.
12
+ */
13
+ export declare const workLimit = 6000000;
14
+ export declare const cards: import("../../cores/kind.js").Kind<import("./kind.js").Scene, import("./kind.js").State, import("./kind.js").Move>;
@@ -0,0 +1,17 @@
1
+ // The kind cards as a module's build and the widget take it, within the kind's one limit of states
2
+ // and one of work.
3
+ import { cardsKind } from "./kind.js";
4
+ /**
5
+ * The most states a scene's whole state graph may hold, at a build and on a device alike: the
6
+ * same as the kinds cells' and line's. A scene whose taps choose one card has a state for each
7
+ * card and option and one with none; one whose taps choose many has every set of them, so eleven
8
+ * cards and options to choose take 2,048 states, and twelve pass the limit.
9
+ */
10
+ export const limit = 3_000;
11
+ /**
12
+ * The most work a scene's whole state graph may take, as the search core counts it: the same as
13
+ * the kinds cells' and line's. A state of cards is a short list of IDs, so a graph within the
14
+ * limit of states takes a small part of it.
15
+ */
16
+ export const workLimit = 6_000_000;
17
+ export const cards = cardsKind(limit, workLimit);
@@ -0,0 +1,23 @@
1
+ import type { Kind } from "../../cores/kind.js";
2
+ import { type Answer } from "./goal.js";
3
+ import { type Scene as Given } from "./scene.js";
4
+ /** A scene as the kind plays it: as read, with what a tap may choose and the goal's answer. */
5
+ export interface Scene extends Given {
6
+ /** The IDs a tap chooses, in the scene's order: the cards of the groups chosen from, then the options. */
7
+ readonly choosable: readonly string[];
8
+ readonly answer: Answer | null;
9
+ }
10
+ /** What is chosen, by the IDs of the cards and options, sorted by UTF-16 code units. */
11
+ export type State = {
12
+ readonly chosen: readonly string[];
13
+ };
14
+ /** A tap on a card or an option, by its ID. */
15
+ export type Move = {
16
+ readonly choose: string;
17
+ };
18
+ /**
19
+ * The kind cards with its limits of states and of work. A move refuses what is no tap, not-a-move;
20
+ * an ID of no card and no option of the scene, no-part; and one the scene does not let a tap choose,
21
+ * not-choosable.
22
+ */
23
+ export declare function cardsKind(limit: number, workLimit: number): Kind<Scene, State, Move>;