@logic-pad/core 0.26.1 → 0.26.2

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 (241) hide show
  1. package/README.md +31 -31
  2. package/assets/logic-core.global.d.ts +3264 -3262
  3. package/package.json +4 -1
  4. package/dist/benchmark/helper.d.ts +0 -21
  5. package/dist/benchmark/helper.js +0 -34
  6. package/dist/benchmark/prepareBench.d.ts +0 -1
  7. package/dist/benchmark/prepareBench.js +0 -140
  8. package/dist/benchmark/runBench.d.ts +0 -1
  9. package/dist/benchmark/runBench.js +0 -206
  10. package/dist/src/data/config.d.ts +0 -119
  11. package/dist/src/data/config.js +0 -72
  12. package/dist/src/data/configurable.d.ts +0 -14
  13. package/dist/src/data/configurable.js +0 -26
  14. package/dist/src/data/dataHelper.d.ts +0 -92
  15. package/dist/src/data/dataHelper.js +0 -217
  16. package/dist/src/data/events/eventHelper.d.ts +0 -1
  17. package/dist/src/data/events/eventHelper.js +0 -6
  18. package/dist/src/data/events/onFinalValidation.d.ts +0 -14
  19. package/dist/src/data/events/onFinalValidation.js +0 -4
  20. package/dist/src/data/events/onGetTile.d.ts +0 -7
  21. package/dist/src/data/events/onGetTile.js +0 -4
  22. package/dist/src/data/events/onGridChange.d.ts +0 -6
  23. package/dist/src/data/events/onGridChange.js +0 -4
  24. package/dist/src/data/events/onGridResize.d.ts +0 -9
  25. package/dist/src/data/events/onGridResize.js +0 -4
  26. package/dist/src/data/events/onSetGrid.d.ts +0 -7
  27. package/dist/src/data/events/onSetGrid.js +0 -19
  28. package/dist/src/data/events/onSymbolDisplay.d.ts +0 -16
  29. package/dist/src/data/events/onSymbolDisplay.js +0 -4
  30. package/dist/src/data/events/onSymbolMerge.d.ts +0 -10
  31. package/dist/src/data/events/onSymbolMerge.js +0 -4
  32. package/dist/src/data/events/onSymbolValidation.d.ts +0 -18
  33. package/dist/src/data/events/onSymbolValidation.js +0 -4
  34. package/dist/src/data/grid.d.ts +0 -410
  35. package/dist/src/data/grid.js +0 -1106
  36. package/dist/src/data/gridConnections.d.ts +0 -25
  37. package/dist/src/data/gridConnections.js +0 -309
  38. package/dist/src/data/gridZones.d.ts +0 -26
  39. package/dist/src/data/gridZones.js +0 -117
  40. package/dist/src/data/instruction.d.ts +0 -26
  41. package/dist/src/data/instruction.js +0 -29
  42. package/dist/src/data/primitives.d.ts +0 -138
  43. package/dist/src/data/primitives.js +0 -177
  44. package/dist/src/data/puzzle.d.ts +0 -73
  45. package/dist/src/data/puzzle.js +0 -105
  46. package/dist/src/data/rules/banPatternRule.d.ts +0 -30
  47. package/dist/src/data/rules/banPatternRule.js +0 -125
  48. package/dist/src/data/rules/cellCountPerZoneRule.d.ts +0 -23
  49. package/dist/src/data/rules/cellCountPerZoneRule.js +0 -39
  50. package/dist/src/data/rules/cellCountRule.d.ts +0 -33
  51. package/dist/src/data/rules/cellCountRule.js +0 -138
  52. package/dist/src/data/rules/completePatternRule.d.ts +0 -24
  53. package/dist/src/data/rules/completePatternRule.js +0 -46
  54. package/dist/src/data/rules/connectAllRule.d.ts +0 -29
  55. package/dist/src/data/rules/connectAllRule.js +0 -88
  56. package/dist/src/data/rules/connectZonesRule.d.ts +0 -29
  57. package/dist/src/data/rules/connectZonesRule.js +0 -111
  58. package/dist/src/data/rules/containsShapeRule.d.ts +0 -34
  59. package/dist/src/data/rules/containsShapeRule.js +0 -125
  60. package/dist/src/data/rules/customRule.d.ts +0 -34
  61. package/dist/src/data/rules/customRule.js +0 -74
  62. package/dist/src/data/rules/differentCountPerZoneRule.d.ts +0 -30
  63. package/dist/src/data/rules/differentCountPerZoneRule.js +0 -96
  64. package/dist/src/data/rules/exactCountPerZoneRule.d.ts +0 -33
  65. package/dist/src/data/rules/exactCountPerZoneRule.js +0 -99
  66. package/dist/src/data/rules/foresightRule.d.ts +0 -36
  67. package/dist/src/data/rules/foresightRule.js +0 -107
  68. package/dist/src/data/rules/index.d.ts +0 -3
  69. package/dist/src/data/rules/index.js +0 -10
  70. package/dist/src/data/rules/lyingSymbolRule.d.ts +0 -31
  71. package/dist/src/data/rules/lyingSymbolRule.js +0 -207
  72. package/dist/src/data/rules/musicControlLine.d.ts +0 -82
  73. package/dist/src/data/rules/musicControlLine.js +0 -167
  74. package/dist/src/data/rules/musicGridRule.d.ts +0 -51
  75. package/dist/src/data/rules/musicGridRule.js +0 -212
  76. package/dist/src/data/rules/mysteryRule.d.ts +0 -39
  77. package/dist/src/data/rules/mysteryRule.js +0 -146
  78. package/dist/src/data/rules/noLoopsRule.d.ts +0 -29
  79. package/dist/src/data/rules/noLoopsRule.js +0 -218
  80. package/dist/src/data/rules/offByXRule.d.ts +0 -32
  81. package/dist/src/data/rules/offByXRule.js +0 -124
  82. package/dist/src/data/rules/perfectionRule.d.ts +0 -45
  83. package/dist/src/data/rules/perfectionRule.js +0 -158
  84. package/dist/src/data/rules/regionAreaRule.d.ts +0 -34
  85. package/dist/src/data/rules/regionAreaRule.js +0 -149
  86. package/dist/src/data/rules/regionShapeRule.d.ts +0 -22
  87. package/dist/src/data/rules/regionShapeRule.js +0 -58
  88. package/dist/src/data/rules/rule.d.ts +0 -18
  89. package/dist/src/data/rules/rule.js +0 -19
  90. package/dist/src/data/rules/rules.gen.d.ts +0 -23
  91. package/dist/src/data/rules/rules.gen.js +0 -27
  92. package/dist/src/data/rules/sameCountPerZoneRule.d.ts +0 -30
  93. package/dist/src/data/rules/sameCountPerZoneRule.js +0 -95
  94. package/dist/src/data/rules/sameShapeRule.d.ts +0 -28
  95. package/dist/src/data/rules/sameShapeRule.js +0 -68
  96. package/dist/src/data/rules/symbolsPerRegionRule.d.ts +0 -38
  97. package/dist/src/data/rules/symbolsPerRegionRule.js +0 -181
  98. package/dist/src/data/rules/undercluedRule.d.ts +0 -24
  99. package/dist/src/data/rules/undercluedRule.js +0 -53
  100. package/dist/src/data/rules/uniqueShapeRule.d.ts +0 -28
  101. package/dist/src/data/rules/uniqueShapeRule.js +0 -65
  102. package/dist/src/data/rules/wrapAroundRule.d.ts +0 -36
  103. package/dist/src/data/rules/wrapAroundRule.js +0 -241
  104. package/dist/src/data/serializer/allSerializers.d.ts +0 -32
  105. package/dist/src/data/serializer/allSerializers.js +0 -71
  106. package/dist/src/data/serializer/compressor/allCompressors.d.ts +0 -14
  107. package/dist/src/data/serializer/compressor/allCompressors.js +0 -43
  108. package/dist/src/data/serializer/compressor/checksumCompressor.d.ts +0 -6
  109. package/dist/src/data/serializer/compressor/checksumCompressor.js +0 -21
  110. package/dist/src/data/serializer/compressor/compressorBase.d.ts +0 -16
  111. package/dist/src/data/serializer/compressor/compressorBase.js +0 -2
  112. package/dist/src/data/serializer/compressor/deflateCompressor.d.ts +0 -7
  113. package/dist/src/data/serializer/compressor/deflateCompressor.js +0 -17
  114. package/dist/src/data/serializer/compressor/gzipCompressor.d.ts +0 -5
  115. package/dist/src/data/serializer/compressor/gzipCompressor.js +0 -9
  116. package/dist/src/data/serializer/compressor/streamCompressor.d.ts +0 -6
  117. package/dist/src/data/serializer/compressor/streamCompressor.js +0 -41
  118. package/dist/src/data/serializer/serializerBase.d.ts +0 -32
  119. package/dist/src/data/serializer/serializerBase.js +0 -2
  120. package/dist/src/data/serializer/serializer_checksum.d.ts +0 -35
  121. package/dist/src/data/serializer/serializer_checksum.js +0 -179
  122. package/dist/src/data/serializer/serializer_v0.d.ts +0 -55
  123. package/dist/src/data/serializer/serializer_v0.js +0 -484
  124. package/dist/src/data/shapes.d.ts +0 -19
  125. package/dist/src/data/shapes.js +0 -137
  126. package/dist/src/data/solver/allSolvers.d.ts +0 -3
  127. package/dist/src/data/solver/allSolvers.js +0 -13
  128. package/dist/src/data/solver/auto/autoSolver.d.ts +0 -18
  129. package/dist/src/data/solver/auto/autoSolver.js +0 -156
  130. package/dist/src/data/solver/backtrack/backtrackSolver.d.ts +0 -11
  131. package/dist/src/data/solver/backtrack/backtrackSolver.js +0 -54
  132. package/dist/src/data/solver/backtrack/backtrackWorker.d.ts +0 -1
  133. package/dist/src/data/solver/backtrack/backtrackWorker.js +0 -312
  134. package/dist/src/data/solver/backtrack/data.d.ts +0 -47
  135. package/dist/src/data/solver/backtrack/data.js +0 -151
  136. package/dist/src/data/solver/backtrack/rules/banPattern.d.ts +0 -9
  137. package/dist/src/data/solver/backtrack/rules/banPattern.js +0 -77
  138. package/dist/src/data/solver/backtrack/rules/cellCount.d.ts +0 -7
  139. package/dist/src/data/solver/backtrack/rules/cellCount.js +0 -25
  140. package/dist/src/data/solver/backtrack/rules/connectAll.d.ts +0 -7
  141. package/dist/src/data/solver/backtrack/rules/connectAll.js +0 -44
  142. package/dist/src/data/solver/backtrack/rules/regionArea.d.ts +0 -8
  143. package/dist/src/data/solver/backtrack/rules/regionArea.js +0 -71
  144. package/dist/src/data/solver/backtrack/rules/regionShape.d.ts +0 -8
  145. package/dist/src/data/solver/backtrack/rules/regionShape.js +0 -57
  146. package/dist/src/data/solver/backtrack/rules/sameShape.d.ts +0 -8
  147. package/dist/src/data/solver/backtrack/rules/sameShape.js +0 -14
  148. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.d.ts +0 -10
  149. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.js +0 -82
  150. package/dist/src/data/solver/backtrack/rules/uniqueShape.d.ts +0 -8
  151. package/dist/src/data/solver/backtrack/rules/uniqueShape.js +0 -14
  152. package/dist/src/data/solver/backtrack/symbols/areaNumber.d.ts +0 -9
  153. package/dist/src/data/solver/backtrack/symbols/areaNumber.js +0 -75
  154. package/dist/src/data/solver/backtrack/symbols/dart.d.ts +0 -8
  155. package/dist/src/data/solver/backtrack/symbols/dart.js +0 -45
  156. package/dist/src/data/solver/backtrack/symbols/directionLinker.d.ts +0 -11
  157. package/dist/src/data/solver/backtrack/symbols/directionLinker.js +0 -121
  158. package/dist/src/data/solver/backtrack/symbols/focus.d.ts +0 -9
  159. package/dist/src/data/solver/backtrack/symbols/focus.js +0 -48
  160. package/dist/src/data/solver/backtrack/symbols/galaxy.d.ts +0 -9
  161. package/dist/src/data/solver/backtrack/symbols/galaxy.js +0 -14
  162. package/dist/src/data/solver/backtrack/symbols/letter.d.ts +0 -9
  163. package/dist/src/data/solver/backtrack/symbols/letter.js +0 -95
  164. package/dist/src/data/solver/backtrack/symbols/lotus.d.ts +0 -11
  165. package/dist/src/data/solver/backtrack/symbols/lotus.js +0 -55
  166. package/dist/src/data/solver/backtrack/symbols/minesweeper.d.ts +0 -9
  167. package/dist/src/data/solver/backtrack/symbols/minesweeper.js +0 -44
  168. package/dist/src/data/solver/backtrack/symbols/myopia.d.ts +0 -7
  169. package/dist/src/data/solver/backtrack/symbols/myopia.js +0 -73
  170. package/dist/src/data/solver/backtrack/symbols/viewpoint.d.ts +0 -7
  171. package/dist/src/data/solver/backtrack/symbols/viewpoint.js +0 -51
  172. package/dist/src/data/solver/cspuz/cspuzSolver.d.ts +0 -13
  173. package/dist/src/data/solver/cspuz/cspuzSolver.js +0 -124
  174. package/dist/src/data/solver/cspuz/cspuzWorker.d.ts +0 -1
  175. package/dist/src/data/solver/cspuz/cspuzWorker.js +0 -82
  176. package/dist/src/data/solver/cspuz/jsonify.d.ts +0 -3
  177. package/dist/src/data/solver/cspuz/jsonify.js +0 -215
  178. package/dist/src/data/solver/eventIteratingSolver.d.ts +0 -8
  179. package/dist/src/data/solver/eventIteratingSolver.js +0 -54
  180. package/dist/src/data/solver/solver.d.ts +0 -77
  181. package/dist/src/data/solver/solver.js +0 -59
  182. package/dist/src/data/solver/universal/universalSolver.d.ts +0 -7
  183. package/dist/src/data/solver/universal/universalSolver.js +0 -13
  184. package/dist/src/data/solver/universal/universalWorker.d.ts +0 -1
  185. package/dist/src/data/solver/universal/universalWorker.js +0 -128
  186. package/dist/src/data/symbols/areaNumberSymbol.d.ts +0 -31
  187. package/dist/src/data/symbols/areaNumberSymbol.js +0 -80
  188. package/dist/src/data/symbols/customIconSymbol.d.ts +0 -35
  189. package/dist/src/data/symbols/customIconSymbol.js +0 -94
  190. package/dist/src/data/symbols/customSymbol.d.ts +0 -25
  191. package/dist/src/data/symbols/customSymbol.js +0 -45
  192. package/dist/src/data/symbols/customTextSymbol.d.ts +0 -35
  193. package/dist/src/data/symbols/customTextSymbol.js +0 -95
  194. package/dist/src/data/symbols/dartSymbol.d.ts +0 -36
  195. package/dist/src/data/symbols/dartSymbol.js +0 -96
  196. package/dist/src/data/symbols/directionLinkerSymbol.d.ts +0 -29
  197. package/dist/src/data/symbols/directionLinkerSymbol.js +0 -232
  198. package/dist/src/data/symbols/everyLetterSymbol.d.ts +0 -32
  199. package/dist/src/data/symbols/everyLetterSymbol.js +0 -119
  200. package/dist/src/data/symbols/focusSymbol.d.ts +0 -40
  201. package/dist/src/data/symbols/focusSymbol.js +0 -159
  202. package/dist/src/data/symbols/galaxySymbol.d.ts +0 -27
  203. package/dist/src/data/symbols/galaxySymbol.js +0 -61
  204. package/dist/src/data/symbols/hiddenSymbol.d.ts +0 -38
  205. package/dist/src/data/symbols/hiddenSymbol.js +0 -113
  206. package/dist/src/data/symbols/houseSymbol.d.ts +0 -33
  207. package/dist/src/data/symbols/houseSymbol.js +0 -104
  208. package/dist/src/data/symbols/index.d.ts +0 -3
  209. package/dist/src/data/symbols/index.js +0 -10
  210. package/dist/src/data/symbols/letterSymbol.d.ts +0 -32
  211. package/dist/src/data/symbols/letterSymbol.js +0 -118
  212. package/dist/src/data/symbols/lotusSymbol.d.ts +0 -30
  213. package/dist/src/data/symbols/lotusSymbol.js +0 -132
  214. package/dist/src/data/symbols/minesweeperSymbol.d.ts +0 -33
  215. package/dist/src/data/symbols/minesweeperSymbol.js +0 -106
  216. package/dist/src/data/symbols/myopiaSymbol.d.ts +0 -37
  217. package/dist/src/data/symbols/myopiaSymbol.js +0 -182
  218. package/dist/src/data/symbols/numberSymbol.d.ts +0 -19
  219. package/dist/src/data/symbols/numberSymbol.js +0 -32
  220. package/dist/src/data/symbols/symbol.d.ts +0 -29
  221. package/dist/src/data/symbols/symbol.js +0 -87
  222. package/dist/src/data/symbols/symbols.gen.d.ts +0 -15
  223. package/dist/src/data/symbols/symbols.gen.js +0 -19
  224. package/dist/src/data/symbols/unsupportedSymbol.d.ts +0 -23
  225. package/dist/src/data/symbols/unsupportedSymbol.js +0 -47
  226. package/dist/src/data/symbols/viewpointSymbol.d.ts +0 -32
  227. package/dist/src/data/symbols/viewpointSymbol.js +0 -95
  228. package/dist/src/data/tile.d.ts +0 -26
  229. package/dist/src/data/tile.js +0 -56
  230. package/dist/src/data/tileConnections.d.ts +0 -25
  231. package/dist/src/data/tileConnections.js +0 -74
  232. package/dist/src/data/validate.d.ts +0 -5
  233. package/dist/src/data/validate.js +0 -131
  234. package/dist/src/data/validateAsync.d.ts +0 -15
  235. package/dist/src/data/validateAsync.js +0 -71
  236. package/dist/src/data/validateAsyncWorker.d.ts +0 -1
  237. package/dist/src/data/validateAsyncWorker.js +0 -9
  238. package/dist/src/index.d.ts +0 -109
  239. package/dist/src/index.js +0 -112
  240. package/dist/src/polyfill/streamPolyfill.d.ts +0 -2
  241. package/dist/src/polyfill/streamPolyfill.js +0 -1
@@ -1,25 +0,0 @@
1
- import GridZones from './gridZones.js';
2
- import { Edge, Position } from './primitives.js';
3
- import TileConnections from './tileConnections.js';
4
- export default class GridConnections extends GridZones {
5
- constructor(edges?: readonly Edge[]);
6
- addEdge(edge: Edge): GridConnections;
7
- removeEdge(edge: Edge): GridConnections;
8
- getForTile({ x, y }: Position): TileConnections;
9
- getConnectedTiles({ x, y }: Position): readonly Position[];
10
- /**
11
- * Create new GridConnections from a string array.
12
- *
13
- * - Use `.` for cells that don't connect to anything.
14
- * - Use any other character for cells that connect to the same character.
15
- *
16
- * @param array - The string array to create the connections from.
17
- * @returns The created connections. You can apply this to a GridData object using GridData.withConnections.
18
- */
19
- static create(array: string[]): GridConnections;
20
- static validateEdges(connections: GridConnections, width: number, height: number): GridConnections;
21
- insertColumn(index: number): GridConnections;
22
- insertRow(index: number): GridConnections;
23
- removeColumn(index: number): GridConnections;
24
- removeRow(index: number): GridConnections;
25
- }
@@ -1,309 +0,0 @@
1
- import { isSameEdge } from './dataHelper.js';
2
- import GridZones from './gridZones.js';
3
- import TileConnections from './tileConnections.js';
4
- export default class GridConnections extends GridZones {
5
- constructor(edges) {
6
- super(edges);
7
- }
8
- addEdge(edge) {
9
- if (this.edges.some(e => isSameEdge(e, edge))) {
10
- return this;
11
- }
12
- return new GridConnections([...this.edges, edge]);
13
- }
14
- removeEdge(edge) {
15
- return new GridConnections(this.edges.filter(e => !isSameEdge(e, edge)));
16
- }
17
- getForTile({ x, y }) {
18
- const result = new TileConnections();
19
- // Get all connections within 2 steps of the tile
20
- const edges = this.getEdgesAt({ x, y });
21
- const edges2 = [
22
- ...edges,
23
- ...edges.flatMap(edge => {
24
- if (edge.x1 === x && edge.y1 === y) {
25
- return this.getEdgesAt({ x: edge.x2, y: edge.y2 });
26
- }
27
- else {
28
- return this.getEdgesAt({ x: edge.x1, y: edge.y1 });
29
- }
30
- }),
31
- ];
32
- // Fill in the connections
33
- for (const edge of edges2) {
34
- if (edge.x1 !== x || edge.y1 !== y) {
35
- const offsetX = edge.x1 - x;
36
- const offsetY = edge.y1 - y;
37
- if (offsetX >= -1 && offsetX <= 1 && offsetY >= -1 && offsetY <= 1) {
38
- result[offsetY][offsetX] = true;
39
- }
40
- }
41
- if (edge.x2 !== x || edge.y2 !== y) {
42
- const offsetX = edge.x2 - x;
43
- const offsetY = edge.y2 - y;
44
- if (offsetX >= -1 && offsetX <= 1 && offsetY >= -1 && offsetY <= 1) {
45
- result[offsetY][offsetX] = true;
46
- }
47
- }
48
- }
49
- // Fix the center and corner connections
50
- result.center = true;
51
- if (!result.top || !result.left) {
52
- result.topLeft = false;
53
- }
54
- if (!result.top || !result.right) {
55
- result.topRight = false;
56
- }
57
- if (!result.bottom || !result.left) {
58
- result.bottomLeft = false;
59
- }
60
- if (!result.bottom || !result.right) {
61
- result.bottomRight = false;
62
- }
63
- return result;
64
- }
65
- getConnectedTiles({ x, y }) {
66
- const result = [];
67
- const visited = new Set();
68
- const queue = [{ x, y }];
69
- while (queue.length > 0) {
70
- const current = queue.pop();
71
- if (visited.has(`${current.x},${current.y}`)) {
72
- continue;
73
- }
74
- visited.add(`${current.x},${current.y}`);
75
- result.push(current);
76
- const edges = this.getEdgesAt(current);
77
- for (const edge of edges) {
78
- if (edge.x1 === current.x && edge.y1 === current.y) {
79
- queue.push({ x: edge.x2, y: edge.y2 });
80
- }
81
- else {
82
- queue.push({ x: edge.x1, y: edge.y1 });
83
- }
84
- }
85
- }
86
- return result;
87
- }
88
- /**
89
- * Create new GridConnections from a string array.
90
- *
91
- * - Use `.` for cells that don't connect to anything.
92
- * - Use any other character for cells that connect to the same character.
93
- *
94
- * @param array - The string array to create the connections from.
95
- * @returns The created connections. You can apply this to a GridData object using GridData.withConnections.
96
- */
97
- static create(array) {
98
- const edges = [];
99
- for (let y = 0; y < array.length; y++) {
100
- for (let x = 0; x < array[y].length; x++) {
101
- if (array[y][x] === '.') {
102
- continue;
103
- }
104
- if (x > 0 && array[y][x - 1] === array[y][x]) {
105
- edges.push({ x1: x - 1, y1: y, x2: x, y2: y });
106
- }
107
- if (y > 0 && array[y - 1][x] === array[y][x]) {
108
- edges.push({ x1: x, y1: y - 1, x2: x, y2: y });
109
- }
110
- }
111
- }
112
- return new GridConnections(edges);
113
- }
114
- static validateEdges(connections, width, height) {
115
- const newEdges = [];
116
- for (const edge of connections.edges) {
117
- if (edge.x1 < 0 || edge.x1 >= width || edge.y1 < 0 || edge.y1 >= height) {
118
- continue;
119
- }
120
- if (edge.x2 < 0 || edge.x2 >= width || edge.y2 < 0 || edge.y2 >= height) {
121
- continue;
122
- }
123
- if (Math.abs(edge.x1 - edge.x2) + Math.abs(edge.y1 - edge.y2) !== 1) {
124
- continue;
125
- }
126
- newEdges.push(edge);
127
- }
128
- if (newEdges.length === connections.edges.length) {
129
- return connections;
130
- }
131
- return new GridConnections(newEdges);
132
- }
133
- insertColumn(index) {
134
- return new GridConnections(this.edges.flatMap(edge => {
135
- if ((edge.x1 < index && edge.x2 < index) ||
136
- (edge.x1 >= index && edge.x2 >= index)) {
137
- if (edge.x1 < index) {
138
- return [edge];
139
- }
140
- return [
141
- { x1: edge.x1 + 1, y1: edge.y1, x2: edge.x2 + 1, y2: edge.y2 },
142
- ];
143
- }
144
- return [
145
- { x1: edge.x1, y1: edge.y1, x2: edge.x2, y2: edge.y2 },
146
- { x1: edge.x1 + 1, y1: edge.y1, x2: edge.x2 + 1, y2: edge.y2 },
147
- ];
148
- }));
149
- }
150
- insertRow(index) {
151
- return new GridConnections(this.edges.flatMap(edge => {
152
- if ((edge.y1 < index && edge.y2 < index) ||
153
- (edge.y1 >= index && edge.y2 >= index)) {
154
- if (edge.y1 < index) {
155
- return [edge];
156
- }
157
- return [
158
- { x1: edge.x1, y1: edge.y1 + 1, x2: edge.x2, y2: edge.y2 + 1 },
159
- ];
160
- }
161
- return [
162
- { x1: edge.x1, y1: edge.y1, x2: edge.x2, y2: edge.y2 },
163
- { x1: edge.x1, y1: edge.y1 + 1, x2: edge.x2, y2: edge.y2 + 1 },
164
- ];
165
- }));
166
- }
167
- removeColumn(index) {
168
- const toProcess = new Map();
169
- const toKeep = [];
170
- this.edges.forEach(edge => {
171
- if ((edge.x1 < index && edge.x2 < index) ||
172
- (edge.x1 > index && edge.x2 > index)) {
173
- if (edge.x1 < index) {
174
- toKeep.push(edge);
175
- }
176
- else {
177
- toKeep.push({
178
- x1: edge.x1 - 1,
179
- y1: edge.y1,
180
- x2: edge.x2 - 1,
181
- y2: edge.y2,
182
- });
183
- }
184
- }
185
- else if (edge.x1 !== index && edge.x2 !== index) {
186
- toKeep.push({
187
- x1: edge.x1 > index ? edge.x1 - 1 : edge.x1,
188
- y1: edge.y1,
189
- x2: edge.x2 > index ? edge.x2 - 1 : edge.x2,
190
- y2: edge.y2,
191
- });
192
- }
193
- else {
194
- if (edge.x1 === index) {
195
- if (!toProcess.has(edge.y1)) {
196
- toProcess.set(edge.y1, [edge]);
197
- }
198
- else {
199
- toProcess.get(edge.y1).push(edge);
200
- }
201
- }
202
- else if (edge.x2 === index) {
203
- if (!toProcess.has(edge.y2)) {
204
- toProcess.set(edge.y2, [edge]);
205
- }
206
- else {
207
- toProcess.get(edge.y2).push(edge);
208
- }
209
- }
210
- }
211
- });
212
- for (const [key, list] of toProcess.entries()) {
213
- for (let i = 1; i < list.length; i++) {
214
- if (!isSameEdge(list[i], list[i - 1])) {
215
- let x1, y1, x2, y2;
216
- if (list[i].x1 === index && list[i].y1 === key) {
217
- x1 = list[i].x2 > index ? list[i].x2 - 1 : list[i].x2;
218
- y1 = list[i].y2;
219
- }
220
- else {
221
- x1 = list[i].x1 > index ? list[i].x1 - 1 : list[i].x1;
222
- y1 = list[i].y1;
223
- }
224
- if (list[i - 1].x1 === index && list[i - 1].y1 === key) {
225
- x2 = list[i - 1].x2 > index ? list[i - 1].x2 - 1 : list[i - 1].x2;
226
- y2 = list[i - 1].y2;
227
- }
228
- else {
229
- x2 = list[i - 1].x1 > index ? list[i - 1].x1 - 1 : list[i - 1].x1;
230
- y2 = list[i - 1].y1;
231
- }
232
- toKeep.push({ x1, y1, x2, y2 });
233
- }
234
- }
235
- }
236
- return new GridConnections(toKeep);
237
- }
238
- removeRow(index) {
239
- const toProcess = new Map();
240
- const toKeep = [];
241
- this.edges.forEach(edge => {
242
- if ((edge.y1 < index && edge.y2 < index) ||
243
- (edge.y1 > index && edge.y2 > index)) {
244
- if (edge.y1 < index) {
245
- toKeep.push(edge);
246
- }
247
- else {
248
- toKeep.push({
249
- x1: edge.x1,
250
- y1: edge.y1 - 1,
251
- x2: edge.x2,
252
- y2: edge.y2 - 1,
253
- });
254
- }
255
- }
256
- else if (edge.y1 !== index && edge.y2 !== index) {
257
- toKeep.push({
258
- x1: edge.x1,
259
- y1: edge.y1 > index ? edge.y1 - 1 : edge.y1,
260
- x2: edge.x2,
261
- y2: edge.y2 > index ? edge.y2 - 1 : edge.y2,
262
- });
263
- }
264
- else {
265
- if (edge.y1 === index) {
266
- if (!toProcess.has(edge.x1)) {
267
- toProcess.set(edge.x1, [edge]);
268
- }
269
- else {
270
- toProcess.get(edge.x1).push(edge);
271
- }
272
- }
273
- else if (edge.y2 === index) {
274
- if (!toProcess.has(edge.x2)) {
275
- toProcess.set(edge.x2, [edge]);
276
- }
277
- else {
278
- toProcess.get(edge.x2).push(edge);
279
- }
280
- }
281
- }
282
- });
283
- for (const [key, list] of toProcess.entries()) {
284
- for (let i = 1; i < list.length; i++) {
285
- if (!isSameEdge(list[i], list[i - 1])) {
286
- let x1, y1, x2, y2;
287
- if (list[i].y1 === index && list[i].x1 === key) {
288
- x1 = list[i].x2;
289
- y1 = list[i].y2 > index ? list[i].y2 - 1 : list[i].y2;
290
- }
291
- else {
292
- x1 = list[i].x1;
293
- y1 = list[i].y1 > index ? list[i].y1 - 1 : list[i].y1;
294
- }
295
- if (list[i - 1].y1 === index && list[i - 1].x1 === key) {
296
- x2 = list[i - 1].x2;
297
- y2 = list[i - 1].y2 > index ? list[i - 1].y2 - 1 : list[i - 1].y2;
298
- }
299
- else {
300
- x2 = list[i - 1].x1;
301
- y2 = list[i - 1].y1 > index ? list[i - 1].y1 - 1 : list[i - 1].y1;
302
- }
303
- toKeep.push({ x1, y1, x2, y2 });
304
- }
305
- }
306
- }
307
- return new GridConnections(toKeep);
308
- }
309
- }
@@ -1,26 +0,0 @@
1
- import { Edge, Position } from './primitives.js';
2
- export default class GridZones {
3
- readonly edges: readonly Edge[];
4
- constructor(edges?: readonly Edge[]);
5
- addEdge(edge: Edge): GridZones;
6
- removeEdge(edge: Edge): GridZones;
7
- hasEdge(edge: Edge): boolean;
8
- getEdgesAt({ x, y }: Position): readonly Edge[];
9
- /**
10
- * Check if two GridZones objects are equal.
11
- * @param other The other GridZones object to compare to.
12
- * @returns Whether the two objects are equal.
13
- */
14
- equals(other: GridZones): boolean;
15
- /**
16
- * Deduplicate an array of edges.
17
- * @param edges The array of edges to deduplicate.
18
- * @returns The deduplicated array of edges.
19
- */
20
- static deduplicateEdges(edges: readonly Edge[]): readonly Edge[];
21
- static validateEdges(connections: GridZones, width: number, height: number): GridZones;
22
- insertColumn(index: number): GridZones;
23
- insertRow(index: number): GridZones;
24
- removeColumn(index: number): GridZones;
25
- removeRow(index: number): GridZones;
26
- }
@@ -1,117 +0,0 @@
1
- import { isSameEdge } from './dataHelper.js';
2
- export default class GridZones {
3
- edges;
4
- constructor(edges) {
5
- this.edges = GridZones.deduplicateEdges(edges ?? []);
6
- }
7
- addEdge(edge) {
8
- if (this.edges.some(e => isSameEdge(e, edge))) {
9
- return this;
10
- }
11
- return new GridZones([...this.edges, edge]);
12
- }
13
- removeEdge(edge) {
14
- return new GridZones(this.edges.filter(e => !isSameEdge(e, edge)));
15
- }
16
- hasEdge(edge) {
17
- if (edge.x1 === edge.x2 && edge.y1 === edge.y2)
18
- return true;
19
- return this.edges.some(e => isSameEdge(e, edge));
20
- }
21
- getEdgesAt({ x, y }) {
22
- return this.edges.filter(e => (e.x1 === x && e.y1 === y) || (e.x2 === x && e.y2 === y));
23
- }
24
- /**
25
- * Check if two GridZones objects are equal.
26
- * @param other The other GridZones object to compare to.
27
- * @returns Whether the two objects are equal.
28
- */
29
- equals(other) {
30
- if (this.edges.length !== other.edges.length)
31
- return false;
32
- for (const edge of this.edges) {
33
- if (!other.hasEdge(edge))
34
- return false;
35
- }
36
- return true;
37
- }
38
- /**
39
- * Deduplicate an array of edges.
40
- * @param edges The array of edges to deduplicate.
41
- * @returns The deduplicated array of edges.
42
- */
43
- static deduplicateEdges(edges) {
44
- return edges.filter((edge, index) => edges.findIndex(e => isSameEdge(e, edge)) === index);
45
- }
46
- static validateEdges(connections, width, height) {
47
- const newEdges = [];
48
- for (const edge of connections.edges) {
49
- if (edge.x1 < -1 ||
50
- edge.x1 >= width + 1 ||
51
- edge.y1 < -1 ||
52
- edge.y1 >= height + 1) {
53
- continue;
54
- }
55
- if (edge.x2 < -1 ||
56
- edge.x2 >= width + 1 ||
57
- edge.y2 < -1 ||
58
- edge.y2 >= height + 1) {
59
- continue;
60
- }
61
- if ((edge.x1 < 0 && edge.x2 < 0) ||
62
- (edge.y1 < 0 && edge.y2 < 0) ||
63
- (edge.x1 >= width && edge.x2 >= width) ||
64
- (edge.y1 >= height && edge.y2 >= height)) {
65
- continue;
66
- }
67
- if (Math.abs(edge.x1 - edge.x2) + Math.abs(edge.y1 - edge.y2) !== 1) {
68
- continue;
69
- }
70
- newEdges.push(edge);
71
- }
72
- if (newEdges.length === connections.edges.length) {
73
- return connections;
74
- }
75
- return new GridZones(newEdges);
76
- }
77
- insertColumn(index) {
78
- return new GridZones(this.edges.map(edge => {
79
- if (edge.x1 < index || edge.x2 < index) {
80
- return edge;
81
- }
82
- else {
83
- return { x1: edge.x1 + 1, y1: edge.y1, x2: edge.x2 + 1, y2: edge.y2 };
84
- }
85
- }));
86
- }
87
- insertRow(index) {
88
- return new GridZones(this.edges.map(edge => {
89
- if (edge.y1 < index || edge.y2 < index) {
90
- return edge;
91
- }
92
- else {
93
- return { x1: edge.x1, y1: edge.y1 + 1, x2: edge.x2, y2: edge.y2 + 1 };
94
- }
95
- }));
96
- }
97
- removeColumn(index) {
98
- return new GridZones(this.edges.map(edge => {
99
- if (edge.x1 > index || edge.x2 > index) {
100
- return { x1: edge.x1 - 1, y1: edge.y1, x2: edge.x2 - 1, y2: edge.y2 };
101
- }
102
- else {
103
- return edge;
104
- }
105
- }));
106
- }
107
- removeRow(index) {
108
- return new GridZones(this.edges.map(edge => {
109
- if (edge.y1 > index || edge.y2 > index) {
110
- return { x1: edge.x1, y1: edge.y1 - 1, x2: edge.x2, y2: edge.y2 - 1 };
111
- }
112
- else {
113
- return edge;
114
- }
115
- }));
116
- }
117
- }
@@ -1,26 +0,0 @@
1
- import Configurable from './configurable.js';
2
- import GridData from './grid.js';
3
- import { Mode } from './primitives.js';
4
- export default abstract class Instruction extends Configurable {
5
- abstract get id(): string;
6
- abstract get explanation(): string;
7
- get configExplanation(): string;
8
- abstract createExampleGrid(): GridData;
9
- /**
10
- * Indicates that validation by logic is not available and the solution must be used for validation
11
- */
12
- get validateWithSolution(): boolean;
13
- get necessaryForCompletion(): boolean;
14
- get visibleWhenSolving(): boolean;
15
- /**
16
- * Return a variant of this instruction that is suitable for the given mode.
17
- */
18
- abstract modeVariant(mode: Mode): Instruction | null;
19
- /**
20
- * Check if this instruction is equal to another instruction by comparing their IDs and configs.
21
- *
22
- * @param other The other instruction to compare to.
23
- * @returns Whether the two instructions are equal.
24
- */
25
- equals(other: Instruction): boolean;
26
- }
@@ -1,29 +0,0 @@
1
- import Configurable from './configurable.js';
2
- export default class Instruction extends Configurable {
3
- get configExplanation() {
4
- return this.explanation;
5
- }
6
- /**
7
- * Indicates that validation by logic is not available and the solution must be used for validation
8
- */
9
- get validateWithSolution() {
10
- return false;
11
- }
12
- get necessaryForCompletion() {
13
- return true;
14
- }
15
- get visibleWhenSolving() {
16
- return true;
17
- }
18
- /**
19
- * Check if this instruction is equal to another instruction by comparing their IDs and configs.
20
- *
21
- * @param other The other instruction to compare to.
22
- * @returns Whether the two instructions are equal.
23
- */
24
- equals(other) {
25
- if (this.id !== other.id)
26
- return false;
27
- return super.equals(other);
28
- }
29
- }
@@ -1,138 +0,0 @@
1
- export interface Position {
2
- readonly x: number;
3
- readonly y: number;
4
- }
5
- export interface Edge {
6
- readonly x1: number;
7
- readonly y1: number;
8
- readonly x2: number;
9
- readonly y2: number;
10
- }
11
- /**
12
- * Major rules are frequently referenced in grids to provide additional UI.
13
- */
14
- export declare enum MajorRule {
15
- MusicGrid = "music",
16
- CompletePattern = "complete_pattern",
17
- Underclued = "underclued",
18
- WrapAround = "wrap_around"
19
- }
20
- /**
21
- * General puzzle types for categorization. One puzzle can have multiple types.
22
- */
23
- export declare enum PuzzleType {
24
- Logic = "logic",
25
- Underclued = "underclued",
26
- Pattern = "pattern",
27
- Music = "music"
28
- }
29
- export declare enum State {
30
- /**
31
- * Describes the violation of a rule.
32
- */
33
- Error = "error",
34
- /**
35
- * Describes that a rule is satisfied and complete in the current grid.
36
- */
37
- Satisfied = "satisfied",
38
- /**
39
- * Describes that a rule is not violated, but is not yet complete in the current grid.
40
- */
41
- Incomplete = "incomplete",
42
- /**
43
- * Describes that a rule is violated but ignored due to the effect of another rule.
44
- */
45
- Ignored = "ignored"
46
- }
47
- export declare namespace State {
48
- function isSatisfied(state: State): boolean;
49
- }
50
- export type RuleState = {
51
- readonly state: State.Error;
52
- readonly positions: readonly Position[];
53
- } | {
54
- readonly state: State.Satisfied;
55
- } | {
56
- readonly state: State.Incomplete;
57
- } | {
58
- readonly state: State.Ignored;
59
- };
60
- export interface GridState {
61
- final: State;
62
- rules: readonly RuleState[];
63
- symbols: ReadonlyMap<string, State[]>;
64
- }
65
- export declare enum Color {
66
- Dark = "dark",
67
- Light = "light",
68
- Gray = "gray"
69
- }
70
- export declare enum Comparison {
71
- Equal = "eq",
72
- AtLeast = "ge",
73
- AtMost = "le"
74
- }
75
- export declare const COMPARISONS: readonly Comparison[];
76
- export declare enum Wrapping {
77
- None = "none",
78
- Wrap = "wrap",
79
- WrapReverse = "wrap-reverse",
80
- ReflectReverse = "reflect-reverse"
81
- }
82
- export declare const WRAPPINGS: readonly Wrapping[];
83
- export declare enum Direction {
84
- Up = "up",
85
- Down = "down",
86
- Left = "left",
87
- Right = "right"
88
- }
89
- export declare const DIRECTIONS: readonly Direction[];
90
- export type DirectionMap<T> = Record<Direction, T>;
91
- export type DirectionToggle = Readonly<DirectionMap<boolean>>;
92
- export declare function directionToggle(...directions: readonly Direction[]): {
93
- up: boolean;
94
- down: boolean;
95
- left: boolean;
96
- right: boolean;
97
- };
98
- export declare enum Orientation {
99
- Up = "up",
100
- UpRight = "up-right",
101
- Right = "right",
102
- DownRight = "down-right",
103
- Down = "down",
104
- DownLeft = "down-left",
105
- Left = "left",
106
- UpLeft = "up-left"
107
- }
108
- export declare const ORIENTATIONS: readonly Orientation[];
109
- export type OrientationMap<T> = Record<Orientation, T>;
110
- export type OrientationToggle = Readonly<OrientationMap<boolean>>;
111
- export declare function orientationToggle(...orientations: readonly Orientation[]): {
112
- up: boolean;
113
- 'up-right': boolean;
114
- right: boolean;
115
- 'down-right': boolean;
116
- down: boolean;
117
- 'down-left': boolean;
118
- left: boolean;
119
- 'up-left': boolean;
120
- };
121
- export declare enum Mode {
122
- Create = "create",
123
- Solve = "solve",
124
- Perfection = "perfection"
125
- }
126
- export declare enum Instrument {
127
- Piano = "piano",
128
- Drum = "drum",
129
- Violin = "violin",
130
- Xylophone = "xylophone",
131
- GuitarAcoustic = "guitar-acoustic",
132
- GuitarElectric = "guitar-electric",
133
- Flute = "flute",
134
- Trumpet = "trumpet"
135
- }
136
- export declare const INSTRUMENTS: readonly Instrument[];
137
- export declare const DRUM_SAMPLES: readonly ["snare", "kick", "hihat", "hihat-open", "crash", "tom", "rim"];
138
- export declare function isDrumSample(note: string): boolean;