@altnovatrail/widgets 0.1.2 → 0.2.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 (110) hide show
  1. package/README.md +1 -1
  2. package/cores/vector.schema.json +82 -3
  3. package/kinds/cells/cells.handles.json +148 -3
  4. package/kinds/cells/cells.schema.json +716 -8
  5. package/kinds/cells/vectors/bishop-grid-56-d1-1.json +105 -4
  6. package/kinds/cells/vectors/counter-cases.json +123 -0
  7. package/kinds/cells/vectors/counter-div-56-d1-3.json +57 -0
  8. package/kinds/cells/vectors/counter-div-56-d2-1.json +773 -0
  9. package/kinds/cells/vectors/counter-div-56-d2-3.json +65 -0
  10. package/kinds/cells/vectors/counter-div-56-d4-1.json +57 -0
  11. package/kinds/cells/vectors/counter-div-56-d4-2.json +106 -0
  12. package/kinds/cells/vectors/cut-cases.json +163 -0
  13. package/kinds/cells/vectors/cut-gaps-56-d2-1.json +142 -0
  14. package/kinds/cells/vectors/cut-grid-56-d2-4.json +45 -0
  15. package/kinds/cells/vectors/cut-grid-56-d4-1.json +154 -0
  16. package/kinds/cells/vectors/cut-grid-56-d4-2.json +136 -0
  17. package/kinds/cells/vectors/cut-invalid.json +48 -0
  18. package/kinds/cells/vectors/domino-grid-56-d3-2.json +238 -0
  19. package/kinds/cells/vectors/domino-limit.json +60 -0
  20. package/kinds/cells/vectors/domino-par-56-d3-2.json +194 -0
  21. package/kinds/cells/vectors/domino-par-56-d4-3.json +127 -0
  22. package/kinds/cells/vectors/figure-apart.json +47 -0
  23. package/kinds/cells/vectors/fold-12x12.json +79 -0
  24. package/kinds/cells/vectors/fold-14x14.json +79 -0
  25. package/kinds/cells/vectors/fold-26x26.json +79 -0
  26. package/kinds/cells/vectors/garden-enum-56-d3-4.json +96 -6
  27. package/kinds/cells/vectors/goat-grid-56-d4-4.json +325 -5
  28. package/kinds/cells/vectors/knight-after-no-parity.json +31 -0
  29. package/kinds/cells/vectors/knight-par-56-d2-2.json +61 -6
  30. package/kinds/cells/vectors/mosaic-grid-56-d2-2.json +84 -0
  31. package/kinds/cells/vectors/nodes-gaps-56-d2-2.json +44 -0
  32. package/kinds/cells/vectors/nodes-gaps-56-d4-2.json +70 -0
  33. package/kinds/cells/vectors/number-div-56-d2-2.json +49 -0
  34. package/kinds/cells/vectors/numbers-div-56-d3-1.json +24 -0
  35. package/kinds/cells/vectors/numbers-invalid.json +56 -0
  36. package/kinds/cells/vectors/paper-26x26.json +743 -0
  37. package/kinds/cells/vectors/paper-cube-12-d2-1.json +43 -19
  38. package/kinds/cells/vectors/paper-cube-12-d5-1.json +47 -4
  39. package/kinds/cells/vectors/paper-cube-56-d4-1.json +56 -5
  40. package/kinds/cells/vectors/paper-drawn-lines.json +184 -0
  41. package/kinds/cells/vectors/paper-grid-56-d1-2.json +46 -5
  42. package/kinds/cells/vectors/paper-turn-invalid.json +4 -4
  43. package/kinds/cells/vectors/path-6x6.json +119 -0
  44. package/kinds/cells/vectors/path-beside.json +108 -0
  45. package/kinds/cells/vectors/path-enum-12-d3-5.json +187 -0
  46. package/kinds/cells/vectors/path-enum-34-d4-3.json +412 -0
  47. package/kinds/cells/vectors/path-enum-56-d3-3.json +411 -0
  48. package/kinds/cells/vectors/path-enum-56-d3-5.json +351 -0
  49. package/kinds/cells/vectors/path-invalid.json +37 -0
  50. package/kinds/cells/vectors/path-limit.json +58 -0
  51. package/kinds/cells/vectors/path-maze.json +297 -0
  52. package/kinds/cells/vectors/path-unreachable.json +76 -0
  53. package/kinds/cells/vectors/perimeter-grid-56-d2-1.json +86 -0
  54. package/kinds/cells/vectors/perimeter-grid-56-d3-1.json +102 -0
  55. package/kinds/cells/vectors/perimeter-grid-56-d3-3.json +112 -0
  56. package/kinds/cells/vectors/perimeter-grid-56-d4-3.json +289 -0
  57. package/kinds/cells/vectors/polyomino-cases.json +191 -0
  58. package/kinds/cells/vectors/polyomino-grid-56-d3-4.json +205 -0
  59. package/kinds/cells/vectors/polyomino-grid-56-d4-1.json +137 -0
  60. package/kinds/cells/vectors/polyomino-grid-56-d5-3.json +157 -0
  61. package/kinds/cells/vectors/polyomino-invalid.json +45 -0
  62. package/kinds/cells/vectors/polyomino-one-pieces.json +28 -0
  63. package/kinds/cells/vectors/route-par-56-d3-3.json +245 -0
  64. package/kinds/cells/vectors/sides-gaps-56-d3-2.json +44 -0
  65. package/kinds/cells/vectors/sieve-div-56-d3-2.json +140 -0
  66. package/kinds/cells/vectors/tear-gaps-56-d3-1.json +84 -0
  67. package/kinds/cells/vectors/tear-limit.json +56 -0
  68. package/lib/cores/enumerate.d.ts +33 -0
  69. package/lib/cores/enumerate.js +77 -0
  70. package/lib/cores/kind.d.ts +70 -5
  71. package/lib/cores/kind.js +2 -2
  72. package/lib/cores/search.d.ts +47 -10
  73. package/lib/cores/search.js +129 -37
  74. package/lib/kinds/cells/bishop.d.ts +1 -1
  75. package/lib/kinds/cells/bishop.js +1 -1
  76. package/lib/kinds/cells/counter.d.ts +26 -0
  77. package/lib/kinds/cells/counter.js +249 -0
  78. package/lib/kinds/cells/cut.d.ts +46 -0
  79. package/lib/kinds/cells/cut.js +400 -0
  80. package/lib/kinds/cells/figure.d.ts +13 -0
  81. package/lib/kinds/cells/figure.js +114 -0
  82. package/lib/kinds/cells/holes.d.ts +6 -0
  83. package/lib/kinds/cells/holes.js +57 -0
  84. package/lib/kinds/cells/index.d.ts +8 -0
  85. package/lib/kinds/cells/index.js +10 -2
  86. package/lib/kinds/cells/kind.d.ts +3 -2
  87. package/lib/kinds/cells/kind.js +23 -8
  88. package/lib/kinds/cells/knight.d.ts +1 -1
  89. package/lib/kinds/cells/number.d.ts +6 -0
  90. package/lib/kinds/cells/number.js +32 -0
  91. package/lib/kinds/cells/operation.d.ts +27 -7
  92. package/lib/kinds/cells/paper.d.ts +10 -2
  93. package/lib/kinds/cells/paper.js +109 -13
  94. package/lib/kinds/cells/path.d.ts +38 -0
  95. package/lib/kinds/cells/path.js +288 -0
  96. package/lib/kinds/cells/piece.d.ts +27 -7
  97. package/lib/kinds/cells/piece.js +202 -37
  98. package/lib/kinds/cells/polyomino.d.ts +45 -0
  99. package/lib/kinds/cells/polyomino.js +461 -0
  100. package/lib/kinds/cells/registry.js +35 -4
  101. package/lib/kinds/cells/schema.js +45 -4
  102. package/lib/kinds/cells/sheet.d.ts +20 -1
  103. package/lib/kinds/cells/sheet.js +84 -6
  104. package/lib/kinds/cells/side.d.ts +33 -0
  105. package/lib/kinds/cells/side.js +86 -0
  106. package/lib/kinds/cells/sieve.d.ts +26 -0
  107. package/lib/kinds/cells/sieve.js +208 -0
  108. package/lib/kinds/cells/step.d.ts +1 -1
  109. package/lib/kinds/cells/step.js +1 -1
  110. package/package.json +5 -1
@@ -0,0 +1,140 @@
1
+ {
2
+ "description": "The course's task div-56-d3-2: lemons counted out in twos, threes, fours, fives or sixes leave one over, and there is more than one lemon. A table of numbers from 1 to 100 in rows of 10, the sieve counting out by 2, 3, 4, 5 and 6 with 1 left. The goal asks the least number above 1 left, at its greatest, 61, the task's key: once by 3, by 4 and by 5, every number left is one more than a multiple of 60, and counting out by 2 or 6 then crosses out nothing more. A width counted twice, and one not given, are refused.",
3
+ "scene": {
4
+ "sheet": {
5
+ "rows": 10,
6
+ "cols": 10,
7
+ "numbers": {
8
+ "first": 1
9
+ }
10
+ },
11
+ "operations": {
12
+ "sieve": {
13
+ "by": [2, 3, 4, 5, 6],
14
+ "left": 1
15
+ }
16
+ },
17
+ "goal": {
18
+ "sieve_least": {
19
+ "above": 1
20
+ }
21
+ }
22
+ },
23
+ "seed": "0",
24
+ "start": {
25
+ "state": {
26
+ "marks": {},
27
+ "sieve": []
28
+ },
29
+ "goal": true
30
+ },
31
+ "sequences": [
32
+ [
33
+ {
34
+ "move": {
35
+ "sieve": {
36
+ "by": 2
37
+ }
38
+ },
39
+ "state": {
40
+ "marks": {},
41
+ "sieve": [2]
42
+ },
43
+ "goal": true
44
+ },
45
+ {
46
+ "move": {
47
+ "sieve": {
48
+ "by": 2
49
+ }
50
+ },
51
+ "refused": "counted"
52
+ },
53
+ {
54
+ "move": {
55
+ "sieve": {
56
+ "by": 7
57
+ }
58
+ },
59
+ "refused": "no-width"
60
+ },
61
+ {
62
+ "move": {
63
+ "sieve": {
64
+ "by": 3
65
+ }
66
+ },
67
+ "state": {
68
+ "marks": {},
69
+ "sieve": [2, 3]
70
+ },
71
+ "goal": true
72
+ },
73
+ {
74
+ "move": {
75
+ "sieve": {
76
+ "by": 4
77
+ }
78
+ },
79
+ "state": {
80
+ "marks": {},
81
+ "sieve": [2, 3, 4]
82
+ },
83
+ "goal": true
84
+ },
85
+ {
86
+ "move": {
87
+ "sieve": {
88
+ "by": 5
89
+ }
90
+ },
91
+ "state": {
92
+ "marks": {},
93
+ "sieve": [2, 3, 4, 5]
94
+ },
95
+ "goal": true
96
+ },
97
+ {
98
+ "move": {
99
+ "sieve": {
100
+ "by": 6
101
+ }
102
+ },
103
+ "state": {
104
+ "marks": {},
105
+ "sieve": [2, 3, 4, 5, 6]
106
+ },
107
+ "goal": true
108
+ }
109
+ ]
110
+ ],
111
+ "proof": {
112
+ "key": 61,
113
+ "asks": "max",
114
+ "witness": {
115
+ "path": [
116
+ {
117
+ "sieve": {
118
+ "by": 3
119
+ }
120
+ },
121
+ {
122
+ "sieve": {
123
+ "by": 4
124
+ }
125
+ },
126
+ {
127
+ "sieve": {
128
+ "by": 5
129
+ }
130
+ }
131
+ ]
132
+ },
133
+ "ends": [
134
+ {
135
+ "marks": {},
136
+ "sieve": [3, 4, 5]
137
+ }
138
+ ]
139
+ }
140
+ }
@@ -0,0 +1,84 @@
1
+ {
2
+ "description": "The course's task gaps-56-d3-1 by its simpler case: a strip of 3 stamps torn into single stamps, each tear running along its line through the piece it splits. The goal is every cell a part of its own; the fewest tears, 2, one fewer than the stamps, as the task's 39 for 5 rows of 8, whose sheet passes the kind's limit. The sequence tears both lines; a tear along a line torn already is refused.",
3
+ "scene": {
4
+ "sheet": {
5
+ "rows": 1,
6
+ "cols": 3
7
+ },
8
+ "operations": {
9
+ "cut": {
10
+ "along": "part"
11
+ }
12
+ },
13
+ "goal": {
14
+ "cells_apart": {}
15
+ }
16
+ },
17
+ "seed": "0",
18
+ "start": {
19
+ "state": {
20
+ "marks": {},
21
+ "cut": []
22
+ },
23
+ "goal": false
24
+ },
25
+ "sequences": [
26
+ [
27
+ {
28
+ "move": {
29
+ "cut": {
30
+ "side": "v2:A"
31
+ }
32
+ },
33
+ "state": {
34
+ "marks": {},
35
+ "cut": ["v2:A"]
36
+ },
37
+ "goal": false
38
+ },
39
+ {
40
+ "move": {
41
+ "cut": {
42
+ "side": "v2:A"
43
+ }
44
+ },
45
+ "refused": "cut"
46
+ },
47
+ {
48
+ "move": {
49
+ "cut": {
50
+ "side": "v1:A"
51
+ }
52
+ },
53
+ "state": {
54
+ "marks": {},
55
+ "cut": ["v1:A", "v2:A"]
56
+ },
57
+ "goal": true
58
+ }
59
+ ]
60
+ ],
61
+ "proof": {
62
+ "key": 2,
63
+ "witness": {
64
+ "path": [
65
+ {
66
+ "cut": {
67
+ "side": "v1:A"
68
+ }
69
+ },
70
+ {
71
+ "cut": {
72
+ "side": "v2:A"
73
+ }
74
+ }
75
+ ]
76
+ },
77
+ "ends": [
78
+ {
79
+ "marks": {},
80
+ "cut": ["v1:A", "v2:A"]
81
+ }
82
+ ]
83
+ }
84
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "description": "The course's sheet of stamps of gaps-56-d3-1, 5 rows of 8, torn along its lines into single stamps: its states, every way the tears have split it, pass the kind's limit, so the scene does not decide; its tears are still played. The first tear splits the whole sheet down v4; the next, from the side h2:1, splits the left half alone.",
3
+ "scene": {
4
+ "sheet": {
5
+ "rows": 5,
6
+ "cols": 8
7
+ },
8
+ "operations": {
9
+ "cut": {
10
+ "along": "part"
11
+ }
12
+ },
13
+ "goal": {
14
+ "cells_apart": {}
15
+ }
16
+ },
17
+ "seed": "0",
18
+ "start": {
19
+ "state": {
20
+ "marks": {},
21
+ "cut": []
22
+ },
23
+ "goal": false
24
+ },
25
+ "sequences": [
26
+ [
27
+ {
28
+ "move": {
29
+ "cut": {
30
+ "side": "v4:C"
31
+ }
32
+ },
33
+ "state": {
34
+ "marks": {},
35
+ "cut": ["v4:A", "v4:B", "v4:C", "v4:D", "v4:E"]
36
+ },
37
+ "goal": false
38
+ },
39
+ {
40
+ "move": {
41
+ "cut": {
42
+ "side": "h2:1"
43
+ }
44
+ },
45
+ "state": {
46
+ "marks": {},
47
+ "cut": ["v4:A", "v4:B", "v4:C", "v4:D", "v4:E", "h2:1", "h2:2", "h2:3", "h2:4"]
48
+ },
49
+ "goal": false
50
+ }
51
+ ]
52
+ ],
53
+ "proof": {
54
+ "undecided": "limit"
55
+ }
56
+ }
@@ -0,0 +1,33 @@
1
+ import type { Json } from "./kind.js";
2
+ import type { StateGraph, StateNode } from "./search.js";
3
+ /**
4
+ * The states of the graph that meet the goal, in the graph's order; where images is given, the
5
+ * first of each class alone, a state being one with every state images makes of it. images gives a
6
+ * state's whole orbit under the scene's symmetries, so that the first of a class stands for it
7
+ * whichever of its states the graph finds first.
8
+ */
9
+ export declare function counted<State extends Json, Move>(graph: StateGraph<State, Move>, images?: (state: State) => readonly State[]): StateNode<State, Move>[];
10
+ /**
11
+ * How many ways of the fewest moves lead from the scene to a state that meets the goal, and the
12
+ * nearest such states, in the graph's order; undefined where no state meets it. A way is a sequence
13
+ * of moves, so two moves from one state to another are two ways; a move that leads to a state of
14
+ * its own layer or an earlier one starts no way of the fewest moves. The count is a sum that may
15
+ * pass the safe integers, which the caller checks: it then is no longer exact.
16
+ */
17
+ export declare function ways<State, Move>(graph: StateGraph<State, Move>): {
18
+ readonly count: number;
19
+ readonly ends: readonly StateNode<State, Move>[];
20
+ } | undefined;
21
+ /**
22
+ * The greatest or least measure of a state that meets the goal, and the index of every state of
23
+ * that measure, in the order given; undefined where no state meets it. Throws a RangeError where a
24
+ * measure is no safe integer: a kind's rules are exact, so a fraction is a fault of the kind.
25
+ */
26
+ export declare function extreme<State>(nodes: readonly {
27
+ readonly index: number;
28
+ readonly goal: boolean;
29
+ readonly state: State;
30
+ }[], which: "max" | "min", measure: (state: State) => number): {
31
+ readonly value: number;
32
+ readonly at: readonly number[];
33
+ } | undefined;
@@ -0,0 +1,77 @@
1
+ // The core of enumeration: what a key that is a count, a maximum or a minimum reads off a scene's
2
+ // whole state graph, which the search core builds within the kind's limits. It adds no state to the
3
+ // graph and walks it no deeper, so the kind's limits bound it as they bound the search.
4
+ import { canonicalKey } from "./key.js";
5
+ /**
6
+ * The states of the graph that meet the goal, in the graph's order; where images is given, the
7
+ * first of each class alone, a state being one with every state images makes of it. images gives a
8
+ * state's whole orbit under the scene's symmetries, so that the first of a class stands for it
9
+ * whichever of its states the graph finds first.
10
+ */
11
+ export function counted(graph, images) {
12
+ const seen = new Set();
13
+ const found = [];
14
+ for (const node of graph.nodes) {
15
+ if (!node.goal || seen.has(node.key)) {
16
+ continue;
17
+ }
18
+ found.push(node);
19
+ for (const image of images?.(node.state) ?? []) {
20
+ seen.add(canonicalKey(image));
21
+ }
22
+ }
23
+ return found;
24
+ }
25
+ /**
26
+ * How many ways of the fewest moves lead from the scene to a state that meets the goal, and the
27
+ * nearest such states, in the graph's order; undefined where no state meets it. A way is a sequence
28
+ * of moves, so two moves from one state to another are two ways; a move that leads to a state of
29
+ * its own layer or an earlier one starts no way of the fewest moves. The count is a sum that may
30
+ * pass the safe integers, which the caller checks: it then is no longer exact.
31
+ */
32
+ export function ways(graph) {
33
+ const nearest = graph.nodes.find((node) => node.goal);
34
+ if (nearest === undefined) {
35
+ return undefined;
36
+ }
37
+ // The graph lists its states by layers, so every way into a state is summed before it is read.
38
+ const count = graph.nodes.map((node) => (node.layer === 0 ? 1 : 0));
39
+ for (const node of graph.nodes) {
40
+ for (const edge of node.next) {
41
+ if (graph.nodes[edge.to].layer === node.layer + 1) {
42
+ count[edge.to] = count[edge.to] + count[node.index];
43
+ }
44
+ }
45
+ }
46
+ const ends = graph.nodes.filter((node) => node.goal && node.layer === nearest.layer);
47
+ return {
48
+ count: ends.reduce((sum, node) => sum + count[node.index], 0),
49
+ ends,
50
+ };
51
+ }
52
+ /**
53
+ * The greatest or least measure of a state that meets the goal, and the index of every state of
54
+ * that measure, in the order given; undefined where no state meets it. Throws a RangeError where a
55
+ * measure is no safe integer: a kind's rules are exact, so a fraction is a fault of the kind.
56
+ */
57
+ export function extreme(nodes, which, measure) {
58
+ let value;
59
+ let at = [];
60
+ for (const node of nodes) {
61
+ if (!node.goal) {
62
+ continue;
63
+ }
64
+ const measured = measure(node.state);
65
+ if (!Number.isSafeInteger(measured)) {
66
+ throw new RangeError(`a measure is a safe integer: ${String(measured)}`);
67
+ }
68
+ if (value === undefined || (which === "max" ? measured > value : measured < value)) {
69
+ value = measured;
70
+ at = [node.index];
71
+ }
72
+ else if (measured === value) {
73
+ at.push(node.index);
74
+ }
75
+ }
76
+ return value === undefined ? undefined : { value, at };
77
+ }
@@ -32,6 +32,15 @@ export type Played<State> = {
32
32
  export interface Kind<Scene, State extends Json, Move extends Json> {
33
33
  /** The most states a scene's whole state graph may hold, the same at a build and on a device. */
34
34
  readonly limit: number;
35
+ /**
36
+ * The most work a scene's whole state graph may take, the same at a build and on a device: each
37
+ * state counts every move the kind lists from it, each move the length of the state's canonical
38
+ * key, what implied adds to it, and moveWork of cores/search.ts more — a move reads the state and
39
+ * writes the one it leads to, keyed again, and trying it costs something whatever the state. It
40
+ * bounds the time of a graph whose states carry many marks or places or have many moves to try,
41
+ * which a count of states does not.
42
+ */
43
+ readonly workLimit: number;
35
44
  read(input: unknown): Read<Scene>;
36
45
  /** The state of the scene as given, at version 0. */
37
46
  start(scene: Scene): State;
@@ -46,11 +55,49 @@ export interface Kind<Scene, State extends Json, Move extends Json> {
46
55
  * path follows. A move listed here that play refuses is skipped.
47
56
  */
48
57
  moves(scene: Scene, state: State): readonly Move[];
58
+ /**
59
+ * What a move from the state reads and writes that its canonical key leaves out, in characters as
60
+ * the key would write it: a place the state keeps by leaving it out, which every move still
61
+ * works on. A kind that leaves it out, or gives 0, keeps nothing so.
62
+ */
63
+ implied?(scene: Scene, state: State): number;
49
64
  hasGoal(scene: Scene): boolean;
50
65
  /** Whether the state meets the scene's goal; never true for a scene with no goal. */
51
66
  meets(scene: Scene, state: State): boolean;
67
+ /**
68
+ * What the scene's goal asks of its state graph, the key its proof gives; a kind that leaves it
69
+ * out asks the fewest moves, and a scene with no goal asks nothing.
70
+ */
71
+ asks?(scene: Scene): Ask<State>;
52
72
  }
53
- /** Why a scene gives no proof. */
73
+ /**
74
+ * The key a scene's goal asks, over every state the scene reaches:
75
+ * - fewest — the fewest moves to a state that meets the goal;
76
+ * - count — how many states meet it, two of them one where images makes one of the other; images
77
+ * gives every state the scene's symmetries make of a state, its whole orbit, so that being one
78
+ * holds both ways;
79
+ * - paths — how many ways of the fewest moves lead to a state that meets it, two moves to one state
80
+ * two ways; where every move leads one layer on, as moves right and down do, that is every way;
81
+ * - max, min — the greatest or least measure of a state that meets it, a safe integer, since the
82
+ * rules are exact.
83
+ * Where no state meets the goal, the key is "unreachable", whatever the goal asks.
84
+ */
85
+ export type Ask<State> = {
86
+ readonly key: "fewest";
87
+ } | {
88
+ readonly key: "count";
89
+ images?(state: State): readonly State[];
90
+ } | {
91
+ readonly key: "paths";
92
+ } | {
93
+ readonly key: "max" | "min";
94
+ measure(state: State): number;
95
+ };
96
+ /**
97
+ * Why a scene gives no proof: limit, its state graph passes the kind's limit of states or of
98
+ * work, or a count of ways passes the safe integers, beyond what the solver takes either way;
99
+ * invalid, the kind refuses it; no-goal, it has no goal to prove.
100
+ */
54
101
  export type Undecided = {
55
102
  readonly undecided: "limit";
56
103
  } | {
@@ -60,10 +107,14 @@ export type Undecided = {
60
107
  readonly undecided: "no-goal";
61
108
  };
62
109
  /**
63
- * A proof as JSON, as the scene vectors and a module's build take it. The key is the fewest moves
64
- * to the goal, or "unreachable", whose witness is the whole state graph, given by the count of
65
- * states in each of its layers. The member witness names its form, so that a core whose witness is
66
- * no path adds its own.
110
+ * A proof as JSON, as the scene vectors and a module's build take it. The key is a whole number,
111
+ * or "unreachable", whose witness is the whole state graph, given by the count of states in each
112
+ * of its layers. A number with no member asks is the fewest moves to the goal, a path of them its
113
+ * witness; asks names any other key and its witness: count, a path to each state counted — one of
114
+ * each class where the scene gives symmetries — in the graph's order; paths, the first of the
115
+ * ways counted; max or min, the path to the first state of that measure. The ends are the states
116
+ * the witness ends in, each meeting the goal. The member witness names its form, so that a core
117
+ * whose witness is no path adds its own.
67
118
  */
68
119
  export type ProofJson = {
69
120
  readonly key: number;
@@ -71,6 +122,20 @@ export type ProofJson = {
71
122
  readonly path: readonly Json[];
72
123
  };
73
124
  readonly ends: readonly Json[];
125
+ } | {
126
+ readonly key: number;
127
+ readonly asks: "count";
128
+ readonly witness: {
129
+ readonly paths: readonly (readonly Json[])[];
130
+ };
131
+ readonly ends: readonly Json[];
132
+ } | {
133
+ readonly key: number;
134
+ readonly asks: "paths" | "max" | "min";
135
+ readonly witness: {
136
+ readonly path: readonly Json[];
137
+ };
138
+ readonly ends: readonly Json[];
74
139
  } | {
75
140
  readonly key: "unreachable";
76
141
  readonly witness: {
package/lib/cores/kind.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // The interface every widget kind gives the cores of solvers: its scene read by its schema, its
2
- // rules, its goal and its limit of states. A kind's state and moves are JSON, as the widget reports
3
- // them; its scene may be any form the kind reads its JSON into.
2
+ // rules, its goal and its limits of states and of work. A kind's state and moves are JSON, as the
3
+ // widget reports them; its scene may be any form the kind reads its JSON into.
4
4
  export {};
@@ -1,4 +1,9 @@
1
- import type { Json, Kind, ProofJson, SceneError, Undecided } from "./kind.js";
1
+ import type { Ask, Json, Kind, ProofJson, SceneError, Undecided } from "./kind.js";
2
+ /**
3
+ * The work of trying one move beyond the length of its state's canonical key, by which a kind's
4
+ * limit of work counts: about what listing, playing and keying a move costs whatever its state.
5
+ */
6
+ export declare const moveWork = 64;
2
7
  /** A move from a state and the index of the state it leads to. */
3
8
  export interface Edge<Move> {
4
9
  readonly move: Move;
@@ -12,8 +17,18 @@ export interface StateNode<State, Move> {
12
17
  /** The fewest moves from the scene to the state. */
13
18
  readonly layer: number;
14
19
  readonly goal: boolean;
15
- /** The fewest moves from the state to a state that meets the goal; null where none can be reached. */
20
+ /**
21
+ * The fewest moves from the state to a state the key aims at — one that meets the goal, and where
22
+ * the goal asks a maximum or a minimum, one of that measure —; null where none can be reached.
23
+ */
16
24
  readonly distance: number | null;
25
+ /**
26
+ * The fewest moves from the state to any state that meets the goal, whatever its measure; null
27
+ * where none can be reached. It is the distance but where the goal asks a maximum or a minimum,
28
+ * so that a state met short of the extreme measure, or one that can still meet the goal only
29
+ * short of it, is told from one where the goal cannot be met at all.
30
+ */
31
+ readonly nearest: number | null;
17
32
  /** Every move the rules take from the state, in the kind's order, a move that changes nothing among them. */
18
33
  readonly next: readonly Edge<Move>[];
19
34
  /** The state and move it was first reached by; null for the scene's own state. */
@@ -23,9 +38,13 @@ export interface StateNode<State, Move> {
23
38
  } | null;
24
39
  }
25
40
  export interface StateGraph<State, Move> {
41
+ /** What the key asks, the fewest moves where the kind does not say: what the distances serve. */
42
+ readonly asks: Ask<State>["key"];
26
43
  readonly nodes: readonly StateNode<State, Move>[];
27
44
  /** The indices of the states of each layer, the scene's own state alone in layer 0. */
28
45
  readonly layers: readonly (readonly number[])[];
46
+ /** The graph's work, as the kind's limit of work counts it. */
47
+ readonly work: number;
29
48
  /** The node of a state, or undefined where the scene cannot reach it or it is no state. */
30
49
  at(state: State): StateNode<State, Move> | undefined;
31
50
  }
@@ -36,15 +55,27 @@ export type GraphResult<State, Move> = {
36
55
  readonly ok: false;
37
56
  } & ({
38
57
  readonly undecided: "limit";
58
+ readonly passes: "states" | "work";
39
59
  } | {
40
60
  readonly undecided: "invalid";
41
61
  readonly errors: readonly SceneError[];
42
62
  }));
63
+ /**
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.
66
+ */
43
67
  export type Proof<State, Move> = {
44
68
  readonly key: number;
69
+ readonly asks: "fewest" | "paths" | "max" | "min";
45
70
  readonly path: readonly Move[];
46
71
  readonly ends: readonly State[];
47
72
  readonly graph: StateGraph<State, Move>;
73
+ } | {
74
+ readonly key: number;
75
+ readonly asks: "count";
76
+ readonly paths: readonly (readonly Move[])[];
77
+ readonly ends: readonly State[];
78
+ readonly graph: StateGraph<State, Move>;
48
79
  } | {
49
80
  readonly key: "unreachable";
50
81
  readonly ends: readonly [];
@@ -53,17 +84,23 @@ export type Proof<State, Move> = {
53
84
  /**
54
85
  * The whole state graph of a scene, read from its JSON by the kind's schema: every state the
55
86
  * scene's moves reach, layer by layer, states that are equal by their canonical key merged. A
56
- * graph with more states than the kind's limit is undecided, wherever its goal lies: the limit
57
- * holds every state a learner can reach, not only the search from the scene to the goal.
87
+ * graph with more states than the kind's limit, or more work than its limit of work, is
88
+ * undecided, wherever its goal lies: the limits hold every state a learner can reach, not only the
89
+ * search from the scene to the goal. A
90
+ * measure the goal asks that is no safe integer throws, as a state that is no JSON of integers
91
+ * does: either is a fault of the kind, not of the scene.
58
92
  */
59
93
  export declare function stateGraph<Scene, State extends Json, Move extends Json>(kind: Kind<Scene, State, Move>, input: unknown, seed: string): GraphResult<State, Move>;
60
94
  /**
61
- * The proof of a scene, read from its JSON by the kind's schema. For a scene with a goal: its key,
62
- * the fewest moves to the goal, with the path of the first state in the graph's order that meets
63
- * it; or, where no state of the graph meets it, the key "unreachable", the whole graph its
64
- * witness. The order of the graph follows the kind's order of moves, so the same scene gives the
65
- * same path on every run. A scene with no goal has nothing to prove once its graph is within the
66
- * limit; past the limit it does not decide, as any scene.
95
+ * The proof of a scene, read from its JSON by the kind's schema. For a scene with a goal, the key
96
+ * it asks: the fewest moves to the goal, with the path of the first state in the graph's order that
97
+ * meets it; how many states meet it, with a path to each, the first of each class where the scene
98
+ * 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.
67
104
  */
68
105
  export declare function prove<Scene, State extends Json, Move extends Json>(kind: Kind<Scene, State, Move>, input: unknown, seed: string): Proof<State, Move>;
69
106
  /** A proof as JSON, as the scene vectors and a module's build take it. */