@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,36 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Orientation } from '../primitives.js';
4
- import NumberSymbol from './numberSymbol.js';
5
- export default class DartSymbol extends NumberSymbol {
6
- readonly orientation: Orientation;
7
- readonly title = "Dart";
8
- private static readonly CONFIGS;
9
- private static readonly EXAMPLE_GRID;
10
- /**
11
- * **Darts count opposite color cells in that direction**
12
- *
13
- * @param x - The x-coordinate of the symbol.
14
- * @param y - The y-coordinate of the symbol.
15
- * @param number - The number of cells seen by the symbol.
16
- * @param orientation - The orientation of the symbol.
17
- */
18
- constructor(x: number, y: number, number: number, orientation: Orientation);
19
- get id(): string;
20
- get placementStep(): number;
21
- get explanation(): string;
22
- get configs(): readonly AnyConfig[] | null;
23
- createExampleGrid(): GridData;
24
- countTiles(grid: GridData): {
25
- completed: number;
26
- possible: number;
27
- };
28
- copyWith({ x, y, number, orientation, }: {
29
- x?: number;
30
- y?: number;
31
- number?: number;
32
- orientation?: Orientation;
33
- }): this;
34
- withNumber(number: number): this;
35
- }
36
- export declare const instance: DartSymbol;
@@ -1,96 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Color, Orientation } from '../primitives.js';
4
- import NumberSymbol from './numberSymbol.js';
5
- export default class DartSymbol extends NumberSymbol {
6
- orientation;
7
- title = 'Dart';
8
- static CONFIGS = Object.freeze([
9
- {
10
- type: ConfigType.Number,
11
- default: 0,
12
- field: 'x',
13
- description: 'X',
14
- configurable: false,
15
- },
16
- {
17
- type: ConfigType.Number,
18
- default: 0,
19
- field: 'y',
20
- description: 'Y',
21
- configurable: false,
22
- },
23
- {
24
- type: ConfigType.Number,
25
- default: 1,
26
- field: 'number',
27
- description: 'Number',
28
- configurable: true,
29
- },
30
- {
31
- type: ConfigType.Orientation,
32
- default: Orientation.Right,
33
- field: 'orientation',
34
- description: 'Orientation',
35
- configurable: true,
36
- },
37
- ]);
38
- static EXAMPLE_GRID = Object.freeze(GridData.create(['wwbbw', 'wwwww', 'wbwbb', 'wwwww'])
39
- .addSymbol(new DartSymbol(1, 0, 1, Orientation.Down))
40
- .addSymbol(new DartSymbol(4, 0, 2, Orientation.Left))
41
- .addSymbol(new DartSymbol(3, 1, 1, Orientation.Down))
42
- .addSymbol(new DartSymbol(0, 2, 3, Orientation.Right)));
43
- /**
44
- * **Darts count opposite color cells in that direction**
45
- *
46
- * @param x - The x-coordinate of the symbol.
47
- * @param y - The y-coordinate of the symbol.
48
- * @param number - The number of cells seen by the symbol.
49
- * @param orientation - The orientation of the symbol.
50
- */
51
- constructor(x, y, number, orientation) {
52
- super(x, y, number);
53
- this.orientation = orientation;
54
- this.orientation = orientation;
55
- }
56
- get id() {
57
- return `dart`;
58
- }
59
- get placementStep() {
60
- return 1;
61
- }
62
- get explanation() {
63
- return `*Darts* count opposite color cells in that direction`;
64
- }
65
- get configs() {
66
- return DartSymbol.CONFIGS;
67
- }
68
- createExampleGrid() {
69
- return DartSymbol.EXAMPLE_GRID;
70
- }
71
- countTiles(grid) {
72
- if (Math.floor(this.x) !== this.x || Math.floor(this.y) !== this.y)
73
- return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
74
- const color = grid.getTile(this.x, this.y).color;
75
- if (color === Color.Gray)
76
- return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
77
- let gray = 0;
78
- let opposite = 0;
79
- grid.iterateDirectionAll({ x: this.x, y: this.y }, this.orientation, () => true, tile => {
80
- if (!tile.exists)
81
- return;
82
- if (tile.color === Color.Gray)
83
- gray++;
84
- else if (tile.color !== color)
85
- opposite++;
86
- });
87
- return { completed: opposite, possible: opposite + gray };
88
- }
89
- copyWith({ x, y, number, orientation, }) {
90
- return new DartSymbol(x ?? this.x, y ?? this.y, number ?? this.number, orientation ?? this.orientation);
91
- }
92
- withNumber(number) {
93
- return this.copyWith({ number });
94
- }
95
- }
96
- export const instance = new DartSymbol(0, 0, 1, Orientation.Right);
@@ -1,29 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Direction, State } from '../primitives.js';
4
- import Symbol from './symbol.js';
5
- export type DirectionLinkerMap = Record<Direction, Direction>;
6
- export default abstract class DirectionLinkerSymbol extends Symbol {
7
- readonly x: number;
8
- readonly y: number;
9
- private static readonly CONFIGS;
10
- private static readonly EXAMPLE_GRID;
11
- private static readonly directionDeltas;
12
- private linkedDirections;
13
- /**
14
- * **Darts count opposite color cells in that direction**
15
- *
16
- * @param x - The x-coordinate of the symbol.
17
- * @param y - The y-coordinate of the symbol.
18
- */
19
- constructor(x: number, y: number);
20
- changeDirections(linkedDirections: DirectionLinkerMap): this;
21
- get id(): string;
22
- get explanation(): string;
23
- get configs(): readonly AnyConfig[] | null;
24
- createExampleGrid(): GridData;
25
- private deltaCoordinate;
26
- validateSymbol(grid: GridData): State;
27
- private getInitialCheckedCouples;
28
- }
29
- export declare const instance: undefined;
@@ -1,232 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { Color, Direction, State } from '../primitives.js';
4
- import Symbol from './symbol.js';
5
- function getColor(c, grid) {
6
- if (!grid.isPositionValid(c.x, c.y) || !grid.getTile(c.x, c.y).exists) {
7
- return null;
8
- }
9
- return grid.getTile(c.x, c.y).color;
10
- }
11
- function makeTurtle(pos1, pos2, grid) {
12
- return {
13
- pos1,
14
- color1: getColor(pos1, grid),
15
- pos2,
16
- color2: getColor(pos2, grid),
17
- };
18
- }
19
- export default class DirectionLinkerSymbol extends Symbol {
20
- x;
21
- y;
22
- static CONFIGS = Object.freeze([
23
- {
24
- type: ConfigType.Number,
25
- default: 0,
26
- field: 'x',
27
- description: 'X',
28
- configurable: false,
29
- },
30
- {
31
- type: ConfigType.Number,
32
- default: 0,
33
- field: 'y',
34
- description: 'Y',
35
- configurable: false,
36
- },
37
- ]);
38
- static EXAMPLE_GRID = Object.freeze(GridData.create(['wwbbw', 'wwwww', 'wwwww', 'wwwww']));
39
- static directionDeltas = {
40
- [Direction.Up]: { dx: 0, dy: -1 },
41
- [Direction.Down]: { dx: 0, dy: 1 },
42
- [Direction.Left]: { dx: -1, dy: 0 },
43
- [Direction.Right]: { dx: 1, dy: 0 },
44
- };
45
- linkedDirections = {
46
- [Direction.Left]: Direction.Left,
47
- [Direction.Up]: Direction.Up,
48
- [Direction.Right]: Direction.Right,
49
- [Direction.Down]: Direction.Down,
50
- };
51
- /**
52
- * **Darts count opposite color cells in that direction**
53
- *
54
- * @param x - The x-coordinate of the symbol.
55
- * @param y - The y-coordinate of the symbol.
56
- */
57
- constructor(x, y) {
58
- super(x, y);
59
- this.x = x;
60
- this.y = y;
61
- }
62
- changeDirections(linkedDirections) {
63
- this.linkedDirections = linkedDirections;
64
- return this;
65
- }
66
- get id() {
67
- return `linkedDirection`;
68
- }
69
- get explanation() {
70
- return `Direction pointed by this symbol should *behave* the same.`;
71
- }
72
- get configs() {
73
- return DirectionLinkerSymbol.CONFIGS;
74
- }
75
- createExampleGrid() {
76
- return DirectionLinkerSymbol.EXAMPLE_GRID;
77
- }
78
- deltaCoordinate(c, direction) {
79
- return {
80
- x: c.x + DirectionLinkerSymbol.directionDeltas[direction].dx,
81
- y: c.y + DirectionLinkerSymbol.directionDeltas[direction].dy,
82
- };
83
- }
84
- validateSymbol(grid) {
85
- // A turtle is an object which have 2 coordinates
86
- // This turtle when activated will check the color of both the cells it is pointing to
87
- // If the color of one of the cell is gray, the turtle doesn't fire any other turtle
88
- // If one of the turtle's coordinate is out of the grid, consider it's color as opposite of the base color
89
- // If the color of both cells are different, return a State.Error
90
- // If the color of both are the same as the color of the turtle, the turtle fires another turtle in all the directions according to the linked directions except the one it came from and the directions where a turtle has already been fired
91
- // If the color of both are the opposite of the turtle, the turtle doesn't fire any other turtle
92
- // If no turtle remains, go to final state
93
- // Final state is State.Satisfied if no gray cell is found, State.Incomplete otherwise
94
- let checkedCouples = this.getInitialCheckedCouples(this.x, this.y, grid);
95
- if (checkedCouples.some(({ color1, color2 }) => (color1 === null && color2 !== null) ||
96
- (color1 !== null && color2 === null))) {
97
- return State.Error;
98
- }
99
- if (checkedCouples.some(({ color1, color2 }) => color1 === Color.Gray || color2 === Color.Gray)) {
100
- return State.Incomplete;
101
- }
102
- checkedCouples = checkedCouples.filter(({ color1, color2 }) => color1 !== null && color2 !== null);
103
- const queue = checkedCouples.slice();
104
- let grayFound = false;
105
- while (queue.length > 0) {
106
- const turtle = queue.shift();
107
- const { pos1, pos2, color1: baseColor1, color2: baseColor2 } = turtle;
108
- const color1 = getColor(pos1, grid);
109
- const color2 = getColor(pos2, grid);
110
- if (color1 === Color.Gray || color2 === Color.Gray) {
111
- grayFound = true;
112
- }
113
- else if (color1 === null || color2 === null) {
114
- if ((color1 === null && color2 === baseColor2) ||
115
- (color2 === null && color1 === baseColor1)) {
116
- return State.Error;
117
- }
118
- }
119
- else if (color1 !== baseColor1 || color2 !== baseColor2) {
120
- if (color1 === baseColor1 || color2 === baseColor2) {
121
- return State.Error;
122
- }
123
- }
124
- if (color1 === baseColor1) {
125
- const directions = Object.keys(this.linkedDirections);
126
- for (const direction of directions) {
127
- const newTurtle = {
128
- pos1: this.deltaCoordinate(pos1, direction),
129
- pos2: this.deltaCoordinate(pos2, this.linkedDirections[direction]),
130
- color1: baseColor1,
131
- color2: baseColor2,
132
- };
133
- const newArrTurtle = {
134
- pos1: grid.toArrayCoordinates(newTurtle.pos1.x, newTurtle.pos1.y),
135
- pos2: grid.toArrayCoordinates(newTurtle.pos2.x, newTurtle.pos2.y),
136
- color1: baseColor1,
137
- color2: baseColor2,
138
- };
139
- const newColor1 = getColor(newArrTurtle.pos1, grid);
140
- const newColor2 = getColor(newArrTurtle.pos2, grid);
141
- if (newColor1 !== baseColor1 &&
142
- newColor2 !== baseColor2 &&
143
- newColor1 !== Color.Gray &&
144
- newColor2 !== Color.Gray) {
145
- continue;
146
- }
147
- if (checkedCouples.some(({ pos1, pos2 }) => pos1.x === newArrTurtle.pos1.x &&
148
- pos1.y === newArrTurtle.pos1.y &&
149
- pos2.x === newArrTurtle.pos2.x &&
150
- pos2.y === newArrTurtle.pos2.y) ||
151
- (pos1.x === newArrTurtle.pos2.x &&
152
- pos1.y === newArrTurtle.pos2.y &&
153
- pos2.x === newArrTurtle.pos1.x &&
154
- pos2.y === newArrTurtle.pos1.y)) {
155
- continue;
156
- }
157
- checkedCouples.push(newArrTurtle);
158
- queue.push(newTurtle);
159
- }
160
- }
161
- }
162
- return grayFound ? State.Incomplete : State.Satisfied;
163
- }
164
- getInitialCheckedCouples(x, y, grid) {
165
- // 1x1
166
- if (x % 1 === 0 && y % 1 === 0) {
167
- return [makeTurtle({ x, y }, { x, y }, grid)];
168
- }
169
- // 1x2
170
- if (x % 1 === 0) {
171
- if (this.linkedDirections[Direction.Up] === Direction.Up &&
172
- this.linkedDirections[Direction.Down] === Direction.Down) {
173
- return [
174
- makeTurtle({ x, y: y - 0.5 }, { x, y: y - 0.5 }, grid),
175
- makeTurtle({ x, y: y + 0.5 }, { x, y: y + 0.5 }, grid),
176
- ];
177
- }
178
- else {
179
- return [makeTurtle({ x, y: y - 0.5 }, { x, y: y + 0.5 }, grid)];
180
- }
181
- }
182
- // 2x1
183
- if (y % 1 === 0) {
184
- if (this.linkedDirections[Direction.Left] === Direction.Left &&
185
- this.linkedDirections[Direction.Right] === Direction.Right) {
186
- return [
187
- makeTurtle({ x: x - 0.5, y }, { x: x - 0.5, y }, grid),
188
- makeTurtle({ x: x + 0.5, y }, { x: x + 0.5, y }, grid),
189
- ];
190
- }
191
- else {
192
- return [makeTurtle({ x: x - 0.5, y }, { x: x + 0.5, y }, grid)];
193
- }
194
- }
195
- // 2x2
196
- if (this.linkedDirections[Direction.Left] === Direction.Left &&
197
- this.linkedDirections[Direction.Right] === Direction.Right) {
198
- return [
199
- makeTurtle({ x: x - 0.5, y: y - 0.5 }, { x: x - 0.5, y: y + 0.5 }, grid),
200
- makeTurtle({ x: x + 0.5, y: y - 0.5 }, { x: x + 0.5, y: y + 0.5 }, grid),
201
- ];
202
- }
203
- if (this.linkedDirections[Direction.Up] === Direction.Up &&
204
- this.linkedDirections[Direction.Down] === Direction.Down) {
205
- return [
206
- makeTurtle({ x: x - 0.5, y: y - 0.5 }, { x: x + 0.5, y: y - 0.5 }, grid),
207
- makeTurtle({ x: x - 0.5, y: y + 0.5 }, { x: x + 0.5, y: y + 0.5 }, grid),
208
- ];
209
- }
210
- else if (this.linkedDirections[Direction.Up] === Direction.Left &&
211
- this.linkedDirections[Direction.Left] === Direction.Up) {
212
- return [
213
- makeTurtle({ x: x - 0.5, y: y - 0.5 }, { x: x - 0.5, y: y - 0.5 }, grid),
214
- makeTurtle({ x: x - 0.5, y: y + 0.5 }, { x: x + 0.5, y: y - 0.5 }, grid),
215
- makeTurtle({ x: x + 0.5, y: y + 0.5 }, { x: x + 0.5, y: y + 0.5 }, grid),
216
- ];
217
- }
218
- else if (this.linkedDirections[Direction.Up] === Direction.Right &&
219
- this.linkedDirections[Direction.Right] === Direction.Up) {
220
- return [
221
- makeTurtle({ x: x + 0.5, y: y - 0.5 }, { x: x + 0.5, y: y - 0.5 }, grid),
222
- makeTurtle({ x: x - 0.5, y: y - 0.5 }, { x: x + 0.5, y: y + 0.5 }, grid),
223
- makeTurtle({ x: x - 0.5, y: y + 0.5 }, { x: x - 0.5, y: y + 0.5 }, grid),
224
- ];
225
- }
226
- return [
227
- makeTurtle({ x: x - 0.5, y: y - 0.5 }, { x: x + 0.5, y: y + 0.5 }, grid),
228
- makeTurtle({ x: x - 0.5, y: y + 0.5 }, { x: x + 0.5, y: y - 0.5 }, grid),
229
- ];
230
- }
231
- }
232
- export const instance = undefined;
@@ -1,32 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { State } from '../primitives.js';
4
- import Symbol from './symbol.js';
5
- export default class EveryLetterSymbol extends Symbol {
6
- readonly x: number;
7
- readonly y: number;
8
- readonly letter: string;
9
- readonly title = "Hollow Letter";
10
- private static readonly CONFIGS;
11
- private static readonly EXAMPLE_GRID;
12
- /**
13
- * **Include each Hollow Letter once per region**
14
- *
15
- * @param x - The x-coordinate of the symbol.
16
- * @param y - The y-coordinate of the symbol.
17
- * @param letter - The letter of the symbol.
18
- */
19
- constructor(x: number, y: number, letter: string);
20
- get id(): string;
21
- get explanation(): string;
22
- get configs(): readonly AnyConfig[] | null;
23
- createExampleGrid(): GridData;
24
- validateSymbol(grid: GridData): State;
25
- copyWith({ x, y, letter, }: {
26
- x?: number;
27
- y?: number;
28
- letter?: string;
29
- }): this;
30
- withLetter(letter: string): this;
31
- }
32
- export declare const instance: EveryLetterSymbol;
@@ -1,119 +0,0 @@
1
- import { ConfigType } from '../config.js';
2
- import GridData from '../grid.js';
3
- import { array } from '../dataHelper.js';
4
- import { Color, State } from '../primitives.js';
5
- import Symbol from './symbol.js';
6
- export default class EveryLetterSymbol extends Symbol {
7
- x;
8
- y;
9
- letter;
10
- title = 'Hollow Letter';
11
- static CONFIGS = Object.freeze([
12
- {
13
- type: ConfigType.Number,
14
- default: 0,
15
- field: 'x',
16
- description: 'X',
17
- configurable: false,
18
- },
19
- {
20
- type: ConfigType.Number,
21
- default: 0,
22
- field: 'y',
23
- description: 'Y',
24
- configurable: false,
25
- },
26
- {
27
- type: ConfigType.String,
28
- default: 'a',
29
- field: 'letter',
30
- description: 'Letter',
31
- explanation: 'Use single lowercase letters by convention.',
32
- configurable: true,
33
- },
34
- ]);
35
- static EXAMPLE_GRID = Object.freeze(GridData.create(['bwwbw', 'bwbbw', 'wwbww', 'bbbwb'])
36
- .addSymbol(new EveryLetterSymbol(2, 0, 'b'))
37
- .addSymbol(new EveryLetterSymbol(4, 1, 'a'))
38
- .addSymbol(new EveryLetterSymbol(0, 2, 'a'))
39
- .addSymbol(new EveryLetterSymbol(3, 2, 'b')));
40
- /**
41
- * **Include each Hollow Letter once per region**
42
- *
43
- * @param x - The x-coordinate of the symbol.
44
- * @param y - The y-coordinate of the symbol.
45
- * @param letter - The letter of the symbol.
46
- */
47
- constructor(x, y, letter) {
48
- super(x, y);
49
- this.x = x;
50
- this.y = y;
51
- this.letter = letter;
52
- this.letter = letter;
53
- }
54
- get id() {
55
- return `every_letter`;
56
- }
57
- get explanation() {
58
- return 'Include each *Hollow Letter* once per region';
59
- }
60
- get configs() {
61
- return EveryLetterSymbol.CONFIGS;
62
- }
63
- createExampleGrid() {
64
- return EveryLetterSymbol.EXAMPLE_GRID;
65
- }
66
- validateSymbol(grid) {
67
- if (!this.validateSubtilePlacement(grid))
68
- return State.Error;
69
- const uniqueLetters = new Set(grid.symbols.get(this.id)?.map(s => s.letter));
70
- if (uniqueLetters.size === 0) {
71
- return State.Satisfied;
72
- }
73
- const possibleLetters = new Set(uniqueLetters);
74
- const thisX = Math.floor(this.x);
75
- const thisY = Math.floor(this.y);
76
- let complete = true;
77
- const visited = array(grid.width, grid.height, () => false);
78
- const connected = array(grid.width, grid.height, () => false);
79
- const color = grid.getTile(thisX, thisY).color;
80
- if (color !== Color.Gray) {
81
- grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === Color.Gray || tile.color === color, (tile, x, y) => {
82
- visited[y][x] = true;
83
- if (tile.color === Color.Gray)
84
- complete = false;
85
- });
86
- grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === color, (_, x, y) => {
87
- connected[y][x] = true;
88
- });
89
- }
90
- else {
91
- return State.Incomplete;
92
- }
93
- for (const symbol of grid.symbols.get(this.id) ?? []) {
94
- if (symbol instanceof EveryLetterSymbol) {
95
- const symbolX = Math.floor(symbol.x);
96
- const symbolY = Math.floor(symbol.y);
97
- if (visited[symbolY][symbolX]) {
98
- possibleLetters.delete(symbol.letter);
99
- }
100
- if (connected[symbolY][symbolX]) {
101
- if (!uniqueLetters.delete(symbol.letter)) {
102
- return State.Error;
103
- }
104
- }
105
- }
106
- }
107
- if (possibleLetters.size > 0) {
108
- return State.Error;
109
- }
110
- return complete ? State.Satisfied : State.Incomplete;
111
- }
112
- copyWith({ x, y, letter, }) {
113
- return new EveryLetterSymbol(x ?? this.x, y ?? this.y, letter ?? this.letter);
114
- }
115
- withLetter(letter) {
116
- return this.copyWith({ letter });
117
- }
118
- }
119
- export const instance = new EveryLetterSymbol(0, 0, 'a');
@@ -1,40 +0,0 @@
1
- import { AnyConfig } from '../config.js';
2
- import { SymbolMergeHandler } from '../events/onSymbolMerge.js';
3
- import GridData from '../grid.js';
4
- import NumberSymbol from './numberSymbol.js';
5
- import Symbol from './symbol.js';
6
- export default class FocusSymbol extends NumberSymbol implements SymbolMergeHandler {
7
- readonly deadEnd: boolean;
8
- get title(): string;
9
- private static readonly CONFIGS;
10
- private static readonly EXAMPLE_GRID;
11
- private static readonly EXAMPLE_GRID_DEAD_END;
12
- /**
13
- * **Focus Numbers count directly adjacent cells of the same color**
14
- * @param x - The x-coordinate of the symbol.
15
- * @param y - The y-coordinate of the symbol.
16
- * @param deadEnd - Whether this Focus Number is a Dead End.
17
- * @param number - The focus number.
18
- */
19
- constructor(x: number, y: number, deadEnd: boolean, number: number);
20
- get id(): string;
21
- get placementStep(): number;
22
- get explanation(): string;
23
- get configs(): readonly AnyConfig[] | null;
24
- createExampleGrid(): GridData;
25
- private countForColor;
26
- countTiles(grid: GridData): {
27
- completed: number;
28
- possible: number;
29
- };
30
- descriptionEquals(other: Symbol): boolean;
31
- copyWith({ x, y, deadEnd, number, }: {
32
- x?: number;
33
- y?: number;
34
- deadEnd?: boolean;
35
- number?: number;
36
- }): this;
37
- withNumber(number: number): this;
38
- withDeadEnd(deadEnd: boolean): this;
39
- }
40
- export declare const instance: FocusSymbol;