@logic-pad/core 0.26.0 → 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 (239) hide show
  1. package/README.md +31 -31
  2. package/assets/logic-core.global.d.ts +3264 -3247
  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 -153
  130. package/dist/src/data/solver/backtrack/backtrackSolver.d.ts +0 -11
  131. package/dist/src/data/solver/backtrack/backtrackSolver.js +0 -52
  132. package/dist/src/data/solver/backtrack/backtrackWorker.d.ts +0 -1
  133. package/dist/src/data/solver/backtrack/backtrackWorker.js +0 -308
  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 -93
  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 -117
  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 -211
  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 -14
  223. package/dist/src/data/symbols/symbols.gen.js +0 -18
  224. package/dist/src/data/symbols/viewpointSymbol.d.ts +0 -32
  225. package/dist/src/data/symbols/viewpointSymbol.js +0 -95
  226. package/dist/src/data/tile.d.ts +0 -26
  227. package/dist/src/data/tile.js +0 -56
  228. package/dist/src/data/tileConnections.d.ts +0 -25
  229. package/dist/src/data/tileConnections.js +0 -74
  230. package/dist/src/data/validate.d.ts +0 -5
  231. package/dist/src/data/validate.js +0 -131
  232. package/dist/src/data/validateAsync.d.ts +0 -15
  233. package/dist/src/data/validateAsync.js +0 -71
  234. package/dist/src/data/validateAsyncWorker.d.ts +0 -1
  235. package/dist/src/data/validateAsyncWorker.js +0 -9
  236. package/dist/src/index.d.ts +0 -108
  237. package/dist/src/index.js +0 -111
  238. package/dist/src/polyfill/streamPolyfill.d.ts +0 -2
  239. package/dist/src/polyfill/streamPolyfill.js +0 -1
@@ -1,138 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Color, State } from '../primitives.js';
4
- import AreaNumberSymbol from '../symbols/areaNumberSymbol.js';
5
- import Rule from './rule.js';
6
- export default class CellCountRule extends Rule {
7
- color;
8
- count;
9
- title = 'Total Count';
10
- static CONFIGS = Object.freeze([
11
- {
12
- type: ConfigType.Color,
13
- default: Color.Light,
14
- allowGray: false,
15
- field: 'color',
16
- description: 'Color',
17
- configurable: true,
18
- },
19
- {
20
- type: ConfigType.Number,
21
- default: 10,
22
- min: 0,
23
- field: 'count',
24
- description: 'Count',
25
- configurable: true,
26
- },
27
- ]);
28
- static EXAMPLE_GRID_LIGHT = Object.freeze([
29
- GridData.create(['bbbbb', 'bbbbb', 'bbbbb', 'bbbbb']),
30
- GridData.create(['bbbbb', 'bbbbb', 'bwbbb', 'bbbbb']).withSymbols([
31
- new AreaNumberSymbol(1, 2, 1),
32
- ]),
33
- GridData.create(['bbbbb', 'bbbbb', 'bwwbb', 'bbbbb']).withSymbols([
34
- new AreaNumberSymbol(1, 2, 2),
35
- ]),
36
- GridData.create(['bbbbb', 'bwbbb', 'bwwbb', 'bbbbb']).withSymbols([
37
- new AreaNumberSymbol(1, 2, 3),
38
- ]),
39
- GridData.create(['bbbbb', 'bwwbb', 'bwwbb', 'bbbbb']).withSymbols([
40
- new AreaNumberSymbol(1, 2, 4),
41
- ]),
42
- GridData.create(['bbbbb', 'bwwbb', 'bwwwb', 'bbbbb']).withSymbols([
43
- new AreaNumberSymbol(1, 2, 5),
44
- ]),
45
- GridData.create(['bbbbb', 'bwwwb', 'bwwwb', 'bbbbb']).withSymbols([
46
- new AreaNumberSymbol(1, 2, 6),
47
- ]),
48
- GridData.create(['bbbbb', 'bbbbb', 'wwwbb', 'wwwwb']).withSymbols([
49
- new AreaNumberSymbol(1, 2, 7),
50
- ]),
51
- GridData.create(['bbbbb', 'wbbbb', 'wwwbb', 'wwwwb']).withSymbols([
52
- new AreaNumberSymbol(1, 2, 8),
53
- ]),
54
- GridData.create(['bbbbb', 'wwbbb', 'wwwbb', 'wwwwb']).withSymbols([
55
- new AreaNumberSymbol(1, 2, 9),
56
- ]),
57
- GridData.create(['wbbbb', 'wwbbb', 'wwwbb', 'wwwwb']).withSymbols([
58
- new AreaNumberSymbol(1, 2, 10),
59
- ]),
60
- ]);
61
- static EXAMPLE_GRID_DARK = Object.freeze(CellCountRule.EXAMPLE_GRID_LIGHT.map(grid => grid.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Dark ? Color.Light : Color.Dark))))));
62
- static SEARCH_VARIANTS = [
63
- new CellCountRule(Color.Light, 10).searchVariant(),
64
- new CellCountRule(Color.Dark, 10).searchVariant(),
65
- ];
66
- /**
67
- * **There are <count> <color> cells in total**
68
- *
69
- * @param color - The color of the cells to count.
70
- * @param count - The total number of cells of the given color.
71
- */
72
- constructor(color, count) {
73
- super();
74
- this.color = color;
75
- this.count = count;
76
- this.color = color;
77
- this.count = count;
78
- }
79
- get id() {
80
- return `cell_count`;
81
- }
82
- get explanation() {
83
- return `There ${this.count === 1 ? 'is' : 'are'} ${this.count} ${this.color} cell${this.count === 1 ? '' : 's'} *in total*`;
84
- }
85
- get configs() {
86
- return CellCountRule.CONFIGS;
87
- }
88
- createExampleGrid() {
89
- if (this.count < CellCountRule.EXAMPLE_GRID_LIGHT.length) {
90
- if (this.color === Color.Light) {
91
- return CellCountRule.EXAMPLE_GRID_LIGHT[this.count];
92
- }
93
- else {
94
- return CellCountRule.EXAMPLE_GRID_DARK[this.count];
95
- }
96
- }
97
- else {
98
- const grid = this.color === Color.Light
99
- ? GridData.create(['wbbbb', 'wwbbb', 'wwwbb', 'wwwwb'])
100
- : GridData.create(['bwwww', 'bbwww', 'bbbww', 'bbbbw']);
101
- return grid.addSymbol(new AreaNumberSymbol(1, 2, this.count));
102
- }
103
- }
104
- get searchVariants() {
105
- return CellCountRule.SEARCH_VARIANTS;
106
- }
107
- validateGrid(grid) {
108
- let colored = 0;
109
- let possible = 0;
110
- grid.forEach(tile => {
111
- if (!tile.exists)
112
- return;
113
- if (tile.color === this.color)
114
- colored++;
115
- if (tile.color === Color.Gray)
116
- possible++;
117
- });
118
- if (colored > this.count || colored + possible < this.count) {
119
- return { state: State.Error, positions: [] };
120
- }
121
- else if (colored === this.count && possible === 0) {
122
- return { state: State.Satisfied };
123
- }
124
- else {
125
- return { state: State.Incomplete };
126
- }
127
- }
128
- copyWith({ color, count }) {
129
- return new CellCountRule(color ?? this.color, count ?? this.count);
130
- }
131
- withColor(color) {
132
- return this.copyWith({ color });
133
- }
134
- withCount(count) {
135
- return this.copyWith({ count });
136
- }
137
- }
138
- export const instance = new CellCountRule(Color.Dark, 10);
@@ -1,24 +0,0 @@
1
- import GridData from '../grid.js';
2
- import { RuleState } from '../primitives.js';
3
- import Rule, { SearchVariant } from './rule.js';
4
- export default class CompletePatternRule extends Rule {
5
- readonly title = "Complete The Pattern";
6
- get configExplanation(): string;
7
- private static readonly EXAMPLE_GRID;
8
- private static readonly SEARCH_VARIANTS;
9
- /**
10
- * **Complete the pattern**
11
- *
12
- * This rule validates answers based on the provided solution.
13
- */
14
- constructor();
15
- get id(): string;
16
- get explanation(): string;
17
- createExampleGrid(): GridData;
18
- get searchVariants(): SearchVariant[];
19
- validateGrid(_grid: GridData): RuleState;
20
- copyWith(_: object): this;
21
- get validateWithSolution(): boolean;
22
- get isSingleton(): boolean;
23
- }
24
- export declare const instance: CompletePatternRule;
@@ -1,46 +0,0 @@
1
- import GridData from '../grid.js';
2
- import { MajorRule, State } from '../primitives.js';
3
- import Rule from './rule.js';
4
- export default class CompletePatternRule extends Rule {
5
- title = 'Complete The Pattern';
6
- get configExplanation() {
7
- return 'Complete the grid by pattern recognition. Your provided solution may override auto-validation.';
8
- }
9
- static EXAMPLE_GRID = Object.freeze(GridData.create(['wbwbw', 'bwbwb', 'wbwbw', 'bwbwb']));
10
- static SEARCH_VARIANTS = [
11
- new CompletePatternRule().searchVariant(),
12
- ];
13
- /**
14
- * **Complete the pattern**
15
- *
16
- * This rule validates answers based on the provided solution.
17
- */
18
- constructor() {
19
- super();
20
- }
21
- get id() {
22
- return MajorRule.CompletePattern;
23
- }
24
- get explanation() {
25
- return `Complete the pattern`;
26
- }
27
- createExampleGrid() {
28
- return CompletePatternRule.EXAMPLE_GRID;
29
- }
30
- get searchVariants() {
31
- return CompletePatternRule.SEARCH_VARIANTS;
32
- }
33
- validateGrid(_grid) {
34
- return { state: State.Incomplete };
35
- }
36
- copyWith(_) {
37
- return new CompletePatternRule();
38
- }
39
- get validateWithSolution() {
40
- return true;
41
- }
42
- get isSingleton() {
43
- return true;
44
- }
45
- }
46
- export const instance = new CompletePatternRule();
@@ -1,29 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Color, RuleState } from '../primitives.js';
4
- import Rule, { SearchVariant } from './rule.js';
5
- export default class ConnectAllRule extends Rule {
6
- readonly color: Color;
7
- readonly title = "Connect All";
8
- private static readonly CONFIGS;
9
- private static readonly EXAMPLE_GRID_LIGHT;
10
- private static readonly EXAMPLE_GRID_DARK;
11
- private static readonly SEARCH_VARIANTS;
12
- /**
13
- * **Connect all &lt;color&gt; cells**
14
- *
15
- * @param color - The color of the cells to connect.
16
- */
17
- constructor(color: Color);
18
- get id(): string;
19
- get explanation(): string;
20
- get configs(): readonly AnyConfig[] | null;
21
- createExampleGrid(): GridData;
22
- get searchVariants(): SearchVariant[];
23
- validateGrid(grid: GridData): RuleState;
24
- copyWith({ color }: {
25
- color?: Color;
26
- }): this;
27
- withColor(color: Color): this;
28
- }
29
- export declare const instance: ConnectAllRule;
@@ -1,88 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { array, minBy } from '../dataHelper.js';
4
- import { Color, State } from '../primitives.js';
5
- import Rule from './rule.js';
6
- export default class ConnectAllRule extends Rule {
7
- color;
8
- title = 'Connect All';
9
- static CONFIGS = Object.freeze([
10
- {
11
- type: ConfigType.Color,
12
- default: Color.Light,
13
- allowGray: false,
14
- field: 'color',
15
- description: 'Color',
16
- configurable: true,
17
- },
18
- ]);
19
- static EXAMPLE_GRID_LIGHT = Object.freeze(GridData.create(['bwwwb', 'bwbww', 'wwwbb', 'wbwww']));
20
- static EXAMPLE_GRID_DARK = Object.freeze(GridData.create(['wbbbw', 'wbwbb', 'bbbww', 'bwbbb']));
21
- static SEARCH_VARIANTS = [
22
- new ConnectAllRule(Color.Light).searchVariant(),
23
- new ConnectAllRule(Color.Dark).searchVariant(),
24
- ];
25
- /**
26
- * **Connect all &lt;color&gt; cells**
27
- *
28
- * @param color - The color of the cells to connect.
29
- */
30
- constructor(color) {
31
- super();
32
- this.color = color;
33
- this.color = color;
34
- }
35
- get id() {
36
- return `connect_all`;
37
- }
38
- get explanation() {
39
- return `Connect all ${this.color} cells`;
40
- }
41
- get configs() {
42
- return ConnectAllRule.CONFIGS;
43
- }
44
- createExampleGrid() {
45
- return this.color === Color.Light
46
- ? ConnectAllRule.EXAMPLE_GRID_LIGHT
47
- : ConnectAllRule.EXAMPLE_GRID_DARK;
48
- }
49
- get searchVariants() {
50
- return ConnectAllRule.SEARCH_VARIANTS;
51
- }
52
- validateGrid(grid) {
53
- let complete = true;
54
- const visited = array(grid.width, grid.height, (i, j) => !grid.getTile(i, j).exists);
55
- const islands = [];
56
- while (true) {
57
- const seed = grid.find((tile, x, y) => !visited[y][x] && tile.color === this.color);
58
- if (!seed)
59
- break;
60
- const positions = [];
61
- grid.iterateArea(seed, tile => tile.color === this.color || tile.color === Color.Gray, (tile, x, y) => {
62
- if (tile.color === Color.Gray)
63
- complete = false;
64
- positions.push({ x, y });
65
- }, visited);
66
- islands.push(positions);
67
- }
68
- if (islands.length > 1) {
69
- return {
70
- state: State.Error,
71
- positions: minBy(islands, island => island.length),
72
- };
73
- }
74
- else if (islands.length <= 1) {
75
- return { state: complete ? State.Satisfied : State.Incomplete };
76
- }
77
- else {
78
- return { state: State.Incomplete }; // not reachable but the TS is not happy
79
- }
80
- }
81
- copyWith({ color }) {
82
- return new ConnectAllRule(color ?? this.color);
83
- }
84
- withColor(color) {
85
- return this.copyWith({ color });
86
- }
87
- }
88
- export const instance = new ConnectAllRule(Color.Dark);
@@ -1,29 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Color, RuleState } from '../primitives.js';
4
- import Rule, { SearchVariant } from './rule.js';
5
- export default class ConnectZonesRule extends Rule {
6
- readonly color: Color;
7
- readonly title = "Connect Zones";
8
- private static readonly CONFIGS;
9
- private static readonly EXAMPLE_GRID_LIGHT;
10
- private static readonly EXAMPLE_GRID_DARK;
11
- private static readonly SEARCH_VARIANTS;
12
- /**
13
- * **Connect all &lt;color&gt; cells in each zone**
14
- *
15
- * @param color - The color of the cells to connect.
16
- */
17
- constructor(color: Color);
18
- get id(): string;
19
- get explanation(): string;
20
- get configs(): readonly AnyConfig[] | null;
21
- createExampleGrid(): GridData;
22
- get searchVariants(): SearchVariant[];
23
- validateGrid(grid: GridData): RuleState;
24
- copyWith({ color }: {
25
- color?: Color;
26
- }): this;
27
- withColor(color: Color): this;
28
- }
29
- export declare const instance: ConnectZonesRule;
@@ -1,111 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { array, minBy } from '../dataHelper.js';
4
- import { Color, State } from '../primitives.js';
5
- import Rule from './rule.js';
6
- import GridZones from '../gridZones.js';
7
- export default class ConnectZonesRule extends Rule {
8
- color;
9
- title = 'Connect Zones';
10
- static CONFIGS = Object.freeze([
11
- {
12
- type: ConfigType.Color,
13
- default: Color.Light,
14
- allowGray: false,
15
- field: 'color',
16
- description: 'Color',
17
- configurable: true,
18
- },
19
- ]);
20
- static EXAMPLE_GRID_LIGHT = Object.freeze(GridData.create(['wbbwb', 'wbbwb', 'wbbww', 'wwbbb'])
21
- .withZones(new GridZones([
22
- { x1: 2, y1: 1, x2: 2, y2: 2 },
23
- { x1: 1, y1: 0, x2: 2, y2: 0 },
24
- { x1: 1, y1: 1, x2: 2, y2: 1 },
25
- { x1: 2, y1: 2, x2: 3, y2: 2 },
26
- { x1: 2, y1: 3, x2: 3, y2: 3 },
27
- ]))
28
- .addRule(new ConnectZonesRule(Color.Light)));
29
- static EXAMPLE_GRID_DARK = Object.freeze(ConnectZonesRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Dark ? Color.Light : Color.Dark)))));
30
- static SEARCH_VARIANTS = [
31
- new ConnectZonesRule(Color.Light).searchVariant(),
32
- new ConnectZonesRule(Color.Dark).searchVariant(),
33
- ];
34
- /**
35
- * **Connect all &lt;color&gt; cells in each zone**
36
- *
37
- * @param color - The color of the cells to connect.
38
- */
39
- constructor(color) {
40
- super();
41
- this.color = color;
42
- this.color = color;
43
- }
44
- get id() {
45
- return `connect_zones`;
46
- }
47
- get explanation() {
48
- return `Connect all ${this.color} cells in each zone`;
49
- }
50
- get configs() {
51
- return ConnectZonesRule.CONFIGS;
52
- }
53
- createExampleGrid() {
54
- return this.color === Color.Light
55
- ? ConnectZonesRule.EXAMPLE_GRID_LIGHT
56
- : ConnectZonesRule.EXAMPLE_GRID_DARK;
57
- }
58
- get searchVariants() {
59
- return ConnectZonesRule.SEARCH_VARIANTS;
60
- }
61
- validateGrid(grid) {
62
- let complete = true;
63
- let zoneId = 1;
64
- const zoneMap = array(grid.width, grid.height, () => 0);
65
- const visited = array(grid.width, grid.height, (i, j) => !grid.getTile(i, j).exists);
66
- const zones = grid.reduceByZone((zone, tile, x, y) => {
67
- zoneMap[y][x] = zone;
68
- if (tile.exists && tile.color === Color.Gray) {
69
- complete = false;
70
- }
71
- return zone;
72
- }, () => zoneId++);
73
- for (const zone of zones) {
74
- const islands = [];
75
- while (true) {
76
- const seed = grid.find((tile, x, y) => !visited[y][x] &&
77
- zoneMap[y][x] === zone &&
78
- tile.color === this.color);
79
- if (!seed)
80
- break;
81
- const positions = [];
82
- grid.iterateArea(seed, (tile, x, y) => {
83
- if (tile.color !== this.color && tile.color !== Color.Gray) {
84
- return false;
85
- }
86
- const pos = grid.toArrayCoordinates(x, y);
87
- return zoneMap[pos.y][pos.x] === zone;
88
- }, (tile, x, y) => {
89
- if (tile.color === Color.Gray)
90
- complete = false;
91
- positions.push({ x, y });
92
- }, visited);
93
- islands.push(positions);
94
- }
95
- if (islands.length > 1) {
96
- return {
97
- state: State.Error,
98
- positions: minBy(islands, island => island.length),
99
- };
100
- }
101
- }
102
- return { state: complete ? State.Satisfied : State.Incomplete };
103
- }
104
- copyWith({ color }) {
105
- return new ConnectZonesRule(color ?? this.color);
106
- }
107
- withColor(color) {
108
- return this.copyWith({ color });
109
- }
110
- }
111
- export const instance = new ConnectZonesRule(Color.Dark);
@@ -1,34 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Color, RuleState } from '../primitives.js';
4
- import { Shape } from '../shapes.js';
5
- import RegionShapeRule from './regionShapeRule.js';
6
- import { SearchVariant } from './rule.js';
7
- export default class ContainsShapeRule extends RegionShapeRule {
8
- readonly title = "Areas Contain Pattern";
9
- private static readonly EXAMPLE_GRID_LIGHT;
10
- private static readonly EXAMPLE_GRID_DARK;
11
- private static readonly CONFIGS;
12
- private static readonly SEARCH_VARIANTS;
13
- readonly pattern: GridData;
14
- readonly cache: Shape[];
15
- /**
16
- * **All &lt;color&gt; areas must contain this pattern**
17
- *
18
- * @param color - The color of the regions to compare.
19
- * @param pattern - GridData representing the required pattern. Only non-gray tiles are considered.
20
- */
21
- constructor(color: Color, pattern: GridData);
22
- get id(): string;
23
- get explanation(): string;
24
- get configs(): readonly AnyConfig[] | null;
25
- createExampleGrid(): GridData;
26
- get searchVariants(): SearchVariant[];
27
- validateGrid(grid: GridData): RuleState;
28
- copyWith({ color, pattern, }: {
29
- color?: Color;
30
- pattern?: GridData;
31
- }): this;
32
- withPattern(pattern: GridData): this;
33
- }
34
- export declare const instance: ContainsShapeRule;
@@ -1,125 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import { array } from '../dataHelper.js';
3
- import GridData from '../grid.js';
4
- import { Color, State } from '../primitives.js';
5
- import { getShapeVariants, sanitizePatternGrid, tilesToShape, } from '../shapes.js';
6
- import RegionShapeRule from './regionShapeRule.js';
7
- export default class ContainsShapeRule extends RegionShapeRule {
8
- title = 'Areas Contain Pattern';
9
- static EXAMPLE_GRID_LIGHT = Object.freeze(GridData.create(['nnnnn', 'nnnnn', 'wwwwn', 'nnnnn', 'nnnnn']));
10
- static EXAMPLE_GRID_DARK = Object.freeze(GridData.create(['nnnnn', 'nnnnn', 'bbbbn', 'nnnnn', 'nnnnn']));
11
- static CONFIGS = Object.freeze([
12
- {
13
- type: ConfigType.Color,
14
- default: Color.Light,
15
- allowGray: false,
16
- field: 'color',
17
- description: 'Color',
18
- configurable: true,
19
- },
20
- {
21
- type: ConfigType.Shape,
22
- default: ContainsShapeRule.EXAMPLE_GRID_LIGHT,
23
- resizable: true,
24
- field: 'pattern',
25
- description: 'Pattern',
26
- explanation: 'The pattern to be contained. Must only include tiles of the selected color.',
27
- configurable: true,
28
- },
29
- ]);
30
- static SEARCH_VARIANTS = [
31
- new ContainsShapeRule(Color.Light, ContainsShapeRule.EXAMPLE_GRID_LIGHT).searchVariant(),
32
- new ContainsShapeRule(Color.Dark, ContainsShapeRule.EXAMPLE_GRID_DARK).searchVariant(),
33
- ];
34
- pattern;
35
- cache;
36
- /**
37
- * **All &lt;color&gt; areas must contain this pattern**
38
- *
39
- * @param color - The color of the regions to compare.
40
- * @param pattern - GridData representing the required pattern. Only non-gray tiles are considered.
41
- */
42
- constructor(color, pattern) {
43
- super(color);
44
- this.pattern = sanitizePatternGrid(pattern, t => t.color === color ? t : t.withColor(Color.Gray));
45
- this.cache = getShapeVariants(tilesToShape(this.pattern.tiles));
46
- }
47
- get id() {
48
- return `contains_shape`;
49
- }
50
- get explanation() {
51
- return `All ${this.color} areas must contain this pattern`;
52
- }
53
- get configs() {
54
- return ContainsShapeRule.CONFIGS;
55
- }
56
- createExampleGrid() {
57
- let minX = Number.POSITIVE_INFINITY;
58
- let minY = Number.POSITIVE_INFINITY;
59
- let maxX = Number.NEGATIVE_INFINITY;
60
- let maxY = Number.NEGATIVE_INFINITY;
61
- this.pattern.forEach((tile, x, y) => {
62
- if (tile.color !== Color.Gray && tile.exists) {
63
- minX = Math.min(minX, x);
64
- minY = Math.min(minY, y);
65
- maxX = Math.max(maxX, x);
66
- maxY = Math.max(maxY, y);
67
- }
68
- });
69
- const width = maxX - minX + 1;
70
- const height = maxY - minY + 1;
71
- if (!Number.isFinite(width) || !Number.isFinite(height)) {
72
- return GridData.create(0, 0);
73
- }
74
- const tiles = array(width, height, (x, y) => {
75
- const tile = this.pattern.getTile(x + minX, y + minY);
76
- if (!tile.exists || tile.color !== Color.Gray)
77
- return tile;
78
- return tile.withExists(false);
79
- });
80
- return GridData.create(width, height, tiles);
81
- }
82
- get searchVariants() {
83
- return ContainsShapeRule.SEARCH_VARIANTS;
84
- }
85
- validateGrid(grid) {
86
- const { regions, complete } = this.getShapeRegions(grid);
87
- const errorRegion = regions.find(r => {
88
- for (const pattern of this.cache) {
89
- if (r.shape.elements.length < pattern.elements.length)
90
- continue;
91
- for (let y = 0; y <= r.shape.height - pattern.height; y++) {
92
- for (let x = 0; x <= r.shape.width - pattern.width; x++) {
93
- let match = true;
94
- for (const element of pattern.elements) {
95
- const tile = r.shape.elements.find(e => e.x === x + element.x && e.y === y + element.y);
96
- if (!tile || tile.color !== element.color) {
97
- match = false;
98
- break;
99
- }
100
- }
101
- if (match)
102
- return false;
103
- }
104
- }
105
- }
106
- return true;
107
- });
108
- if (errorRegion) {
109
- return {
110
- state: State.Error,
111
- positions: errorRegion.positions,
112
- };
113
- }
114
- else {
115
- return { state: complete ? State.Satisfied : State.Incomplete };
116
- }
117
- }
118
- copyWith({ color, pattern, }) {
119
- return new ContainsShapeRule(color ?? this.color, pattern ?? this.pattern);
120
- }
121
- withPattern(pattern) {
122
- return this.copyWith({ pattern });
123
- }
124
- }
125
- export const instance = new ContainsShapeRule(Color.Dark, GridData.create([]));
@@ -1,34 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { RuleState } from '../primitives.js';
4
- import Rule, { SearchVariant } from './rule.js';
5
- export default class CustomRule extends Rule {
6
- readonly description: string;
7
- readonly grid: GridData;
8
- readonly title = "Custom Rule";
9
- get configExplanation(): string;
10
- private static readonly EXAMPLE_GRID;
11
- static readonly configs: readonly AnyConfig[];
12
- private static readonly SEARCH_VARIANTS;
13
- /**
14
- * A custom rule with a description and thumbnail grid.
15
- *
16
- * This rule validates answers based on the provided solution.
17
- *
18
- * @param description - The description of the rule.
19
- * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
20
- */
21
- constructor(description: string, grid: GridData);
22
- get id(): string;
23
- get explanation(): string;
24
- get configs(): readonly AnyConfig[] | null;
25
- createExampleGrid(): GridData;
26
- get searchVariants(): SearchVariant[];
27
- validateGrid(_grid: GridData): RuleState;
28
- copyWith({ description, grid, }: {
29
- description?: string;
30
- grid?: GridData;
31
- }): this;
32
- get validateWithSolution(): boolean;
33
- }
34
- export declare const instance: CustomRule;