@logic-pad/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +19 -0
  3. package/assets/logic-core.global.d.ts +5865 -0
  4. package/assets/z3-built.js +14723 -0
  5. package/assets/z3-built.wasm +0 -0
  6. package/assets/z3-built.worker.js +206 -0
  7. package/dist/data/config.d.ts +101 -0
  8. package/dist/data/config.js +55 -0
  9. package/dist/data/configurable.d.ts +12 -0
  10. package/dist/data/configurable.js +26 -0
  11. package/dist/data/dataHelper.d.ts +77 -0
  12. package/dist/data/dataHelper.js +190 -0
  13. package/dist/data/events/eventHelper.d.ts +1 -0
  14. package/dist/data/events/eventHelper.js +6 -0
  15. package/dist/data/events/onFinalValidation.d.ts +14 -0
  16. package/dist/data/events/onFinalValidation.js +4 -0
  17. package/dist/data/events/onGridChange.d.ts +6 -0
  18. package/dist/data/events/onGridChange.js +4 -0
  19. package/dist/data/events/onGridResize.d.ts +9 -0
  20. package/dist/data/events/onGridResize.js +4 -0
  21. package/dist/data/events/onSetGrid.d.ts +6 -0
  22. package/dist/data/events/onSetGrid.js +4 -0
  23. package/dist/data/events/onSymbolValidation.d.ts +18 -0
  24. package/dist/data/events/onSymbolValidation.js +4 -0
  25. package/dist/data/grid.d.ts +362 -0
  26. package/dist/data/grid.js +886 -0
  27. package/dist/data/gridConnections.d.ts +38 -0
  28. package/dist/data/gridConnections.js +328 -0
  29. package/dist/data/instruction.d.ts +19 -0
  30. package/dist/data/instruction.js +23 -0
  31. package/dist/data/primitives.d.ts +85 -0
  32. package/dist/data/primitives.js +90 -0
  33. package/dist/data/puzzle.d.ts +86 -0
  34. package/dist/data/puzzle.js +22 -0
  35. package/dist/data/rules/banPatternRule.d.ts +29 -0
  36. package/dist/data/rules/banPatternRule.js +133 -0
  37. package/dist/data/rules/cellCountRule.d.ts +32 -0
  38. package/dist/data/rules/cellCountRule.js +166 -0
  39. package/dist/data/rules/completePatternRule.d.ts +22 -0
  40. package/dist/data/rules/completePatternRule.js +53 -0
  41. package/dist/data/rules/connectAllRule.d.ts +28 -0
  42. package/dist/data/rules/connectAllRule.js +113 -0
  43. package/dist/data/rules/customRule.d.ts +32 -0
  44. package/dist/data/rules/customRule.js +92 -0
  45. package/dist/data/rules/foresightRule.d.ts +30 -0
  46. package/dist/data/rules/foresightRule.js +107 -0
  47. package/dist/data/rules/index.d.ts +3 -0
  48. package/dist/data/rules/index.js +10 -0
  49. package/dist/data/rules/musicControlLine.d.ts +64 -0
  50. package/dist/data/rules/musicControlLine.js +178 -0
  51. package/dist/data/rules/musicGridRule.d.ts +46 -0
  52. package/dist/data/rules/musicGridRule.js +211 -0
  53. package/dist/data/rules/mysteryRule.d.ts +37 -0
  54. package/dist/data/rules/mysteryRule.js +164 -0
  55. package/dist/data/rules/offByXRule.d.ts +30 -0
  56. package/dist/data/rules/offByXRule.js +134 -0
  57. package/dist/data/rules/regionAreaRule.d.ts +33 -0
  58. package/dist/data/rules/regionAreaRule.js +182 -0
  59. package/dist/data/rules/regionShapeRule.d.ts +22 -0
  60. package/dist/data/rules/regionShapeRule.js +58 -0
  61. package/dist/data/rules/rule.d.ts +18 -0
  62. package/dist/data/rules/rule.js +19 -0
  63. package/dist/data/rules/rules.gen.d.ts +14 -0
  64. package/dist/data/rules/rules.gen.js +18 -0
  65. package/dist/data/rules/sameShapeRule.d.ts +27 -0
  66. package/dist/data/rules/sameShapeRule.js +88 -0
  67. package/dist/data/rules/symbolsPerRegionRule.d.ts +37 -0
  68. package/dist/data/rules/symbolsPerRegionRule.js +211 -0
  69. package/dist/data/rules/undercluedRule.d.ts +22 -0
  70. package/dist/data/rules/undercluedRule.js +60 -0
  71. package/dist/data/rules/uniqueShapeRule.d.ts +27 -0
  72. package/dist/data/rules/uniqueShapeRule.js +85 -0
  73. package/dist/data/serializer/allSerializers.d.ts +30 -0
  74. package/dist/data/serializer/allSerializers.js +64 -0
  75. package/dist/data/serializer/compressor/allCompressors.d.ts +14 -0
  76. package/dist/data/serializer/compressor/allCompressors.js +43 -0
  77. package/dist/data/serializer/compressor/compressorBase.d.ts +16 -0
  78. package/dist/data/serializer/compressor/compressorBase.js +2 -0
  79. package/dist/data/serializer/compressor/deflateCompressor.d.ts +7 -0
  80. package/dist/data/serializer/compressor/deflateCompressor.js +17 -0
  81. package/dist/data/serializer/compressor/gzipCompressor.d.ts +5 -0
  82. package/dist/data/serializer/compressor/gzipCompressor.js +9 -0
  83. package/dist/data/serializer/compressor/streamCompressor.d.ts +6 -0
  84. package/dist/data/serializer/compressor/streamCompressor.js +36 -0
  85. package/dist/data/serializer/serializerBase.d.ts +27 -0
  86. package/dist/data/serializer/serializerBase.js +2 -0
  87. package/dist/data/serializer/serializer_v0.d.ts +36 -0
  88. package/dist/data/serializer/serializer_v0.js +426 -0
  89. package/dist/data/shapes.d.ts +17 -0
  90. package/dist/data/shapes.js +117 -0
  91. package/dist/data/solver/allSolvers.d.ts +3 -0
  92. package/dist/data/solver/allSolvers.js +11 -0
  93. package/dist/data/solver/backtrack/backtrackSolver.d.ts +9 -0
  94. package/dist/data/solver/backtrack/backtrackSolver.js +92 -0
  95. package/dist/data/solver/backtrack/backtrackWorker.d.ts +2 -0
  96. package/dist/data/solver/backtrack/backtrackWorker.js +295 -0
  97. package/dist/data/solver/backtrack/data.d.ts +46 -0
  98. package/dist/data/solver/backtrack/data.js +140 -0
  99. package/dist/data/solver/backtrack/rules/banPattern.d.ts +9 -0
  100. package/dist/data/solver/backtrack/rules/banPattern.js +66 -0
  101. package/dist/data/solver/backtrack/rules/cellCount.d.ts +7 -0
  102. package/dist/data/solver/backtrack/rules/cellCount.js +30 -0
  103. package/dist/data/solver/backtrack/rules/connectAll.d.ts +7 -0
  104. package/dist/data/solver/backtrack/rules/connectAll.js +49 -0
  105. package/dist/data/solver/backtrack/rules/regionArea.d.ts +8 -0
  106. package/dist/data/solver/backtrack/rules/regionArea.js +76 -0
  107. package/dist/data/solver/backtrack/rules/regionShape.d.ts +8 -0
  108. package/dist/data/solver/backtrack/rules/regionShape.js +62 -0
  109. package/dist/data/solver/backtrack/rules/sameShape.d.ts +8 -0
  110. package/dist/data/solver/backtrack/rules/sameShape.js +19 -0
  111. package/dist/data/solver/backtrack/rules/symbolsPerRegion.d.ts +10 -0
  112. package/dist/data/solver/backtrack/rules/symbolsPerRegion.js +92 -0
  113. package/dist/data/solver/backtrack/rules/uniqueShape.d.ts +8 -0
  114. package/dist/data/solver/backtrack/rules/uniqueShape.js +19 -0
  115. package/dist/data/solver/backtrack/symbols/areaNumber.d.ts +9 -0
  116. package/dist/data/solver/backtrack/symbols/areaNumber.js +77 -0
  117. package/dist/data/solver/backtrack/symbols/dart.d.ts +9 -0
  118. package/dist/data/solver/backtrack/symbols/dart.js +58 -0
  119. package/dist/data/solver/backtrack/symbols/directionLinker.d.ts +9 -0
  120. package/dist/data/solver/backtrack/symbols/directionLinker.js +50 -0
  121. package/dist/data/solver/backtrack/symbols/galaxy.d.ts +9 -0
  122. package/dist/data/solver/backtrack/symbols/galaxy.js +19 -0
  123. package/dist/data/solver/backtrack/symbols/letter.d.ts +9 -0
  124. package/dist/data/solver/backtrack/symbols/letter.js +100 -0
  125. package/dist/data/solver/backtrack/symbols/lotus.d.ts +9 -0
  126. package/dist/data/solver/backtrack/symbols/lotus.js +36 -0
  127. package/dist/data/solver/backtrack/symbols/minesweeper.d.ts +9 -0
  128. package/dist/data/solver/backtrack/symbols/minesweeper.js +55 -0
  129. package/dist/data/solver/backtrack/symbols/myopia.d.ts +7 -0
  130. package/dist/data/solver/backtrack/symbols/myopia.js +79 -0
  131. package/dist/data/solver/backtrack/symbols/viewpoint.d.ts +7 -0
  132. package/dist/data/solver/backtrack/symbols/viewpoint.js +56 -0
  133. package/dist/data/solver/solver.d.ts +61 -0
  134. package/dist/data/solver/solver.js +55 -0
  135. package/dist/data/solver/underclued/undercluedSolver.d.ts +8 -0
  136. package/dist/data/solver/underclued/undercluedSolver.js +55 -0
  137. package/dist/data/solver/underclued/undercluedWorker.d.ts +2 -0
  138. package/dist/data/solver/underclued/undercluedWorker.js +131 -0
  139. package/dist/data/solver/z3/modules/areaNumberModule.d.ts +9 -0
  140. package/dist/data/solver/z3/modules/areaNumberModule.js +35 -0
  141. package/dist/data/solver/z3/modules/cellCountModule.d.ts +9 -0
  142. package/dist/data/solver/z3/modules/cellCountModule.js +59 -0
  143. package/dist/data/solver/z3/modules/connectAllModule.d.ts +9 -0
  144. package/dist/data/solver/z3/modules/connectAllModule.js +32 -0
  145. package/dist/data/solver/z3/modules/dartModule.d.ts +9 -0
  146. package/dist/data/solver/z3/modules/dartModule.js +69 -0
  147. package/dist/data/solver/z3/modules/index.d.ts +3 -0
  148. package/dist/data/solver/z3/modules/index.js +10 -0
  149. package/dist/data/solver/z3/modules/letterModule.d.ts +9 -0
  150. package/dist/data/solver/z3/modules/letterModule.js +41 -0
  151. package/dist/data/solver/z3/modules/modules.gen.d.ts +8 -0
  152. package/dist/data/solver/z3/modules/modules.gen.js +12 -0
  153. package/dist/data/solver/z3/modules/myopiaModule.d.ts +9 -0
  154. package/dist/data/solver/z3/modules/myopiaModule.js +64 -0
  155. package/dist/data/solver/z3/modules/regionAreaModule.d.ts +9 -0
  156. package/dist/data/solver/z3/modules/regionAreaModule.js +48 -0
  157. package/dist/data/solver/z3/modules/viewpointModule.d.ts +9 -0
  158. package/dist/data/solver/z3/modules/viewpointModule.js +37 -0
  159. package/dist/data/solver/z3/modules/z3Module.d.ts +7 -0
  160. package/dist/data/solver/z3/modules/z3Module.js +3 -0
  161. package/dist/data/solver/z3/utils.d.ts +2 -0
  162. package/dist/data/solver/z3/utils.js +26 -0
  163. package/dist/data/solver/z3/z3Solver.d.ts +10 -0
  164. package/dist/data/solver/z3/z3Solver.js +134 -0
  165. package/dist/data/solver/z3/z3SolverContext.d.ts +808 -0
  166. package/dist/data/solver/z3/z3SolverContext.js +49 -0
  167. package/dist/data/symbols/areaNumberSymbol.d.ts +30 -0
  168. package/dist/data/symbols/areaNumberSymbol.js +88 -0
  169. package/dist/data/symbols/customIconSymbol.d.ts +35 -0
  170. package/dist/data/symbols/customIconSymbol.js +105 -0
  171. package/dist/data/symbols/customSymbol.d.ts +23 -0
  172. package/dist/data/symbols/customSymbol.js +48 -0
  173. package/dist/data/symbols/customTextSymbol.d.ts +33 -0
  174. package/dist/data/symbols/customTextSymbol.js +106 -0
  175. package/dist/data/symbols/dartSymbol.d.ts +35 -0
  176. package/dist/data/symbols/dartSymbol.js +110 -0
  177. package/dist/data/symbols/directionLinkerSymbol.d.ts +36 -0
  178. package/dist/data/symbols/directionLinkerSymbol.js +259 -0
  179. package/dist/data/symbols/galaxySymbol.d.ts +26 -0
  180. package/dist/data/symbols/galaxySymbol.js +74 -0
  181. package/dist/data/symbols/index.d.ts +3 -0
  182. package/dist/data/symbols/index.js +10 -0
  183. package/dist/data/symbols/letterSymbol.d.ts +31 -0
  184. package/dist/data/symbols/letterSymbol.js +137 -0
  185. package/dist/data/symbols/lotusSymbol.d.ts +29 -0
  186. package/dist/data/symbols/lotusSymbol.js +132 -0
  187. package/dist/data/symbols/minesweeperSymbol.d.ts +31 -0
  188. package/dist/data/symbols/minesweeperSymbol.js +100 -0
  189. package/dist/data/symbols/multiEntrySymbol.d.ts +11 -0
  190. package/dist/data/symbols/multiEntrySymbol.js +14 -0
  191. package/dist/data/symbols/myopiaSymbol.d.ts +34 -0
  192. package/dist/data/symbols/myopiaSymbol.js +187 -0
  193. package/dist/data/symbols/numberSymbol.d.ts +19 -0
  194. package/dist/data/symbols/numberSymbol.js +41 -0
  195. package/dist/data/symbols/symbol.d.ts +16 -0
  196. package/dist/data/symbols/symbol.js +51 -0
  197. package/dist/data/symbols/symbols.gen.d.ts +10 -0
  198. package/dist/data/symbols/symbols.gen.js +14 -0
  199. package/dist/data/symbols/viewpointSymbol.d.ts +31 -0
  200. package/dist/data/symbols/viewpointSymbol.js +106 -0
  201. package/dist/data/tile.d.ts +26 -0
  202. package/dist/data/tile.js +68 -0
  203. package/dist/data/tileConnections.d.ts +25 -0
  204. package/dist/data/tileConnections.js +74 -0
  205. package/dist/data/validate.d.ts +5 -0
  206. package/dist/data/validate.js +131 -0
  207. package/dist/index.d.ts +96 -0
  208. package/dist/index.js +100 -0
  209. package/dist/polyfill/streamPolyfill.d.ts +2 -0
  210. package/dist/polyfill/streamPolyfill.js +1 -0
  211. package/package.json +75 -0
@@ -0,0 +1,132 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import { Direction, Orientation } from '../primitives';
4
+ import DirectionLinkerSymbol from './directionLinkerSymbol';
5
+ class LotusSymbol extends DirectionLinkerSymbol {
6
+ /**
7
+ * **Areas containing this symbol must be symmetrical**
8
+ *
9
+ * @param x - The x-coordinate of the symbol.
10
+ * @param y - The y-coordinate of the symbol.
11
+ * @param orientation - The orientation of the symbol.
12
+ */
13
+ constructor(x, y, orientation) {
14
+ super(x, y);
15
+ Object.defineProperty(this, "x", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: x
20
+ });
21
+ Object.defineProperty(this, "y", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: y
26
+ });
27
+ Object.defineProperty(this, "orientation", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: orientation
32
+ });
33
+ super.changeDirections(LotusSymbol.linkedDirectionsFromOrientation[orientation]);
34
+ }
35
+ get id() {
36
+ return `lotus`;
37
+ }
38
+ get explanation() {
39
+ return `Areas containing this symbol must be *symmetrical*`;
40
+ }
41
+ get configs() {
42
+ return Object.freeze([
43
+ {
44
+ type: ConfigType.Number,
45
+ default: 0,
46
+ field: 'x',
47
+ description: 'X',
48
+ configurable: false,
49
+ },
50
+ {
51
+ type: ConfigType.Number,
52
+ default: 0,
53
+ field: 'y',
54
+ description: 'Y',
55
+ configurable: false,
56
+ },
57
+ {
58
+ type: ConfigType.Orientation,
59
+ default: Orientation.Up,
60
+ field: 'orientation',
61
+ description: 'Orientation',
62
+ configurable: true,
63
+ },
64
+ ]);
65
+ }
66
+ createExampleGrid() {
67
+ return Object.freeze(GridData.create(['wwbww', 'bwbwb', 'bwwwb', 'bwwwb']).addSymbol(new LotusSymbol(2, 2, Orientation.Up)));
68
+ }
69
+ validateSymbol(grid) {
70
+ return super.validateSymbol(grid);
71
+ }
72
+ copyWith({ x, y, orientation, }) {
73
+ return new LotusSymbol(x ?? this.x, y ?? this.y, orientation ?? this.orientation);
74
+ }
75
+ }
76
+ Object.defineProperty(LotusSymbol, "linkedDirectionsFromOrientation", {
77
+ enumerable: true,
78
+ configurable: true,
79
+ writable: true,
80
+ value: {
81
+ [Orientation.Up]: {
82
+ [Direction.Left]: Direction.Right,
83
+ [Direction.Up]: Direction.Up,
84
+ [Direction.Right]: Direction.Left,
85
+ [Direction.Down]: Direction.Down,
86
+ },
87
+ [Orientation.UpRight]: {
88
+ [Direction.Left]: Direction.Down,
89
+ [Direction.Up]: Direction.Right,
90
+ [Direction.Right]: Direction.Up,
91
+ [Direction.Down]: Direction.Left,
92
+ },
93
+ [Orientation.Right]: {
94
+ [Direction.Left]: Direction.Left,
95
+ [Direction.Up]: Direction.Down,
96
+ [Direction.Right]: Direction.Right,
97
+ [Direction.Down]: Direction.Up,
98
+ },
99
+ [Orientation.DownRight]: {
100
+ [Direction.Left]: Direction.Up,
101
+ [Direction.Up]: Direction.Left,
102
+ [Direction.Right]: Direction.Down,
103
+ [Direction.Down]: Direction.Right,
104
+ },
105
+ [Orientation.Down]: {
106
+ [Direction.Left]: Direction.Right,
107
+ [Direction.Up]: Direction.Up,
108
+ [Direction.Right]: Direction.Left,
109
+ [Direction.Down]: Direction.Down,
110
+ },
111
+ [Orientation.DownLeft]: {
112
+ [Direction.Left]: Direction.Down,
113
+ [Direction.Up]: Direction.Right,
114
+ [Direction.Right]: Direction.Up,
115
+ [Direction.Down]: Direction.Left,
116
+ },
117
+ [Orientation.Left]: {
118
+ [Direction.Left]: Direction.Left,
119
+ [Direction.Up]: Direction.Down,
120
+ [Direction.Right]: Direction.Right,
121
+ [Direction.Down]: Direction.Up,
122
+ },
123
+ [Orientation.UpLeft]: {
124
+ [Direction.Left]: Direction.Up,
125
+ [Direction.Up]: Direction.Left,
126
+ [Direction.Right]: Direction.Down,
127
+ [Direction.Down]: Direction.Right,
128
+ },
129
+ }
130
+ });
131
+ export default LotusSymbol;
132
+ export const instance = new LotusSymbol(0, 0, Orientation.Up);
@@ -0,0 +1,31 @@
1
+ import { AnyConfig } from '../config';
2
+ import GridData from '../grid';
3
+ import NumberSymbol from './numberSymbol';
4
+ export default class MinesweeperSymbol extends NumberSymbol {
5
+ private static readonly CONFIGS;
6
+ private static readonly EXAMPLE_GRID;
7
+ /**
8
+ * **Minesweeper numbers count opposite cells in 8 adjacent spaces**
9
+ *
10
+ * @param x - The x-coordinate of the symbol.
11
+ * @param y - The y-coordinate of the symbol.
12
+ * @param number - The number of cells seen by the symbol.
13
+ */
14
+ constructor(x: number, y: number, number: number);
15
+ get id(): string;
16
+ get placementStep(): number;
17
+ get explanation(): string;
18
+ get configs(): readonly AnyConfig[] | null;
19
+ createExampleGrid(): GridData;
20
+ countTiles(grid: GridData): {
21
+ completed: number;
22
+ possible: number;
23
+ };
24
+ copyWith({ x, y, number, }: {
25
+ x?: number;
26
+ y?: number;
27
+ number?: number;
28
+ }): this;
29
+ withNumber(number: number): this;
30
+ }
31
+ export declare const instance: MinesweeperSymbol;
@@ -0,0 +1,100 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import { Color } from '../primitives';
4
+ import NumberSymbol from './numberSymbol';
5
+ class MinesweeperSymbol extends NumberSymbol {
6
+ /**
7
+ * **Minesweeper numbers count opposite cells in 8 adjacent spaces**
8
+ *
9
+ * @param x - The x-coordinate of the symbol.
10
+ * @param y - The y-coordinate of the symbol.
11
+ * @param number - The number of cells seen by the symbol.
12
+ */
13
+ constructor(x, y, number) {
14
+ super(x, y, number);
15
+ }
16
+ get id() {
17
+ return `minesweeper`;
18
+ }
19
+ get placementStep() {
20
+ return 1;
21
+ }
22
+ get explanation() {
23
+ return `*Minesweeper numbers* count opposite cells in 8 adjacent spaces`;
24
+ }
25
+ get configs() {
26
+ return MinesweeperSymbol.CONFIGS;
27
+ }
28
+ createExampleGrid() {
29
+ return MinesweeperSymbol.EXAMPLE_GRID;
30
+ }
31
+ countTiles(grid) {
32
+ if (Math.floor(this.x) !== this.x || Math.floor(this.y) !== this.y)
33
+ return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
34
+ const color = grid.getTile(this.x, this.y).color;
35
+ if (color === Color.Gray)
36
+ return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
37
+ let gray = 0;
38
+ let opposite = 0;
39
+ for (let y = this.y - 1; y <= this.y + 1; y++) {
40
+ for (let x = this.x - 1; x <= this.x + 1; x++) {
41
+ if (x === this.x && y === this.y)
42
+ continue;
43
+ const tile = grid.getTile(x, y);
44
+ if (!tile.exists)
45
+ continue;
46
+ if (tile.color === Color.Gray)
47
+ gray++;
48
+ else if (tile.color !== color)
49
+ opposite++;
50
+ }
51
+ }
52
+ return { completed: opposite, possible: opposite + gray };
53
+ }
54
+ copyWith({ x, y, number, }) {
55
+ return new MinesweeperSymbol(x ?? this.x, y ?? this.y, number ?? this.number);
56
+ }
57
+ withNumber(number) {
58
+ return this.copyWith({ number });
59
+ }
60
+ }
61
+ Object.defineProperty(MinesweeperSymbol, "CONFIGS", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: Object.freeze([
66
+ {
67
+ type: ConfigType.Number,
68
+ default: 0,
69
+ field: 'x',
70
+ description: 'X',
71
+ configurable: false,
72
+ },
73
+ {
74
+ type: ConfigType.Number,
75
+ default: 0,
76
+ field: 'y',
77
+ description: 'Y',
78
+ configurable: false,
79
+ },
80
+ {
81
+ type: ConfigType.Number,
82
+ default: 1,
83
+ field: 'number',
84
+ description: 'Number',
85
+ configurable: true,
86
+ },
87
+ ])
88
+ });
89
+ Object.defineProperty(MinesweeperSymbol, "EXAMPLE_GRID", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: Object.freeze(GridData.create(['wwbww', 'wwbwb', 'wwbwb', 'bwwww'])
94
+ .addSymbol(new MinesweeperSymbol(1, 1, 3))
95
+ .addSymbol(new MinesweeperSymbol(3, 1, 5))
96
+ .addSymbol(new MinesweeperSymbol(4, 1, 4))
97
+ .addSymbol(new MinesweeperSymbol(2, 3, 1)))
98
+ });
99
+ export default MinesweeperSymbol;
100
+ export const instance = new MinesweeperSymbol(0, 0, 1);
@@ -0,0 +1,11 @@
1
+ import Instruction from '../instruction';
2
+ import Symbol from './symbol';
3
+ export default abstract class MultiEntrySymbol extends Symbol {
4
+ /**
5
+ * Determines if the description of two MultiEntrySymbols can be merged when displayed in the UI.
6
+ * @param other - The other MultiEntrySymbol to compare to.
7
+ * @returns Whether the two MultiEntrySymbols have the same description.
8
+ */
9
+ descriptionEquals(other: Instruction): boolean;
10
+ }
11
+ export declare const instance: undefined;
@@ -0,0 +1,14 @@
1
+ import Symbol from './symbol';
2
+ export default class MultiEntrySymbol extends Symbol {
3
+ /**
4
+ * Determines if the description of two MultiEntrySymbols can be merged when displayed in the UI.
5
+ * @param other - The other MultiEntrySymbol to compare to.
6
+ * @returns Whether the two MultiEntrySymbols have the same description.
7
+ */
8
+ descriptionEquals(other) {
9
+ return (this.id === other.id &&
10
+ this.explanation === other.explanation &&
11
+ this.createExampleGrid().equals(other.createExampleGrid()));
12
+ }
13
+ }
14
+ export const instance = undefined;
@@ -0,0 +1,34 @@
1
+ import { AnyConfig } from '../config';
2
+ import GridData from '../grid';
3
+ import { OrientationToggle, State } from '../primitives';
4
+ import MultiEntrySymbol from './multiEntrySymbol';
5
+ export default class MyopiaSymbol extends MultiEntrySymbol {
6
+ readonly diagonals: boolean;
7
+ readonly directions: OrientationToggle;
8
+ private static readonly CONFIGS;
9
+ private static readonly EXAMPLE_GRID;
10
+ private static readonly EXAMPLE_DIAGONAL_GRID;
11
+ /**
12
+ * **Viewpoint Numbers count visible cells in the four directions**
13
+ * @param x - The x-coordinate of the symbol.
14
+ * @param y - The y-coordinate of the symbol.
15
+ * @param diagonals - Whether the symbol should consider diagonal directions.
16
+ * @param directions - The directions in which an arrow is pointing.
17
+ */
18
+ constructor(x: number, y: number, diagonals: boolean, directions: OrientationToggle);
19
+ get id(): string;
20
+ get placementStep(): number;
21
+ get explanation(): string;
22
+ get configs(): readonly AnyConfig[] | null;
23
+ createExampleGrid(): GridData;
24
+ validateSymbol(grid: GridData): State;
25
+ copyWith({ x, y, diagonals, directions, }: {
26
+ x?: number;
27
+ y?: number;
28
+ diagonals?: boolean;
29
+ directions?: OrientationToggle;
30
+ }): this;
31
+ withDirections(directions: OrientationToggle): this;
32
+ withDiagonals(diagonals: boolean): this;
33
+ }
34
+ export declare const instance: MyopiaSymbol;
@@ -0,0 +1,187 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import { Color, ORIENTATIONS, Orientation, State, orientationToggle, } from '../primitives';
4
+ import MultiEntrySymbol from './multiEntrySymbol';
5
+ class MyopiaSymbol extends MultiEntrySymbol {
6
+ /**
7
+ * **Viewpoint Numbers count visible cells in the four directions**
8
+ * @param x - The x-coordinate of the symbol.
9
+ * @param y - The y-coordinate of the symbol.
10
+ * @param diagonals - Whether the symbol should consider diagonal directions.
11
+ * @param directions - The directions in which an arrow is pointing.
12
+ */
13
+ constructor(x, y, diagonals, directions) {
14
+ super(x, y);
15
+ Object.defineProperty(this, "diagonals", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: diagonals
20
+ });
21
+ Object.defineProperty(this, "directions", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: directions
26
+ });
27
+ this.directions = directions;
28
+ this.diagonals =
29
+ directions[Orientation.DownLeft] ||
30
+ directions[Orientation.DownRight] ||
31
+ directions[Orientation.UpLeft] ||
32
+ directions[Orientation.UpRight]
33
+ ? true
34
+ : diagonals;
35
+ }
36
+ get id() {
37
+ return `myopia`;
38
+ }
39
+ get placementStep() {
40
+ return 1;
41
+ }
42
+ get explanation() {
43
+ return this.diagonals
44
+ ? '*Framed myopia arrows* point to *all* the closest opposite cells in 8 directions'
45
+ : '*Myopia arrows* point to *all* the closest cells of the opposite color';
46
+ }
47
+ get configs() {
48
+ return MyopiaSymbol.CONFIGS;
49
+ }
50
+ createExampleGrid() {
51
+ return this.diagonals
52
+ ? MyopiaSymbol.EXAMPLE_DIAGONAL_GRID
53
+ : MyopiaSymbol.EXAMPLE_GRID;
54
+ }
55
+ validateSymbol(grid) {
56
+ const tile = grid.getTile(this.x, this.y);
57
+ if (!tile.exists || tile.color === Color.Gray)
58
+ return State.Incomplete;
59
+ const allDirections = this.diagonals
60
+ ? ORIENTATIONS
61
+ : [Orientation.Up, Orientation.Down, Orientation.Left, Orientation.Right];
62
+ const map = {
63
+ up: { min: 0, max: 0, complete: true },
64
+ down: { min: 0, max: 0, complete: true },
65
+ left: { min: 0, max: 0, complete: true },
66
+ right: { min: 0, max: 0, complete: true },
67
+ 'up-left': { min: 0, max: 0, complete: true },
68
+ 'up-right': { min: 0, max: 0, complete: true },
69
+ 'down-left': { min: 0, max: 0, complete: true },
70
+ 'down-right': { min: 0, max: 0, complete: true },
71
+ };
72
+ const pos = { x: this.x, y: this.y };
73
+ allDirections.forEach(direction => {
74
+ grid.iterateDirectionAll(pos, direction, t => !t.exists || t.color === tile.color, () => {
75
+ map[direction].min++;
76
+ });
77
+ let stopped = false;
78
+ grid.iterateDirectionAll(pos, direction, t => {
79
+ if (!t.exists)
80
+ return true;
81
+ if (t.color === tile.color || t.color === Color.Gray)
82
+ return true;
83
+ stopped = true;
84
+ return false;
85
+ }, t => {
86
+ map[direction].max++;
87
+ if (t.exists && t.color === Color.Gray)
88
+ map[direction].complete = false;
89
+ });
90
+ if (!stopped)
91
+ map[direction].max = Number.MAX_SAFE_INTEGER;
92
+ });
93
+ const pointedDirections = allDirections.filter(d => this.directions[d]);
94
+ const otherDirections = allDirections.filter(d => !this.directions[d]);
95
+ for (let i = 0; i < pointedDirections.length; i++) {
96
+ const direction1 = pointedDirections[i];
97
+ for (let j = i + 1; j < pointedDirections.length; j++) {
98
+ const direction2 = pointedDirections[j];
99
+ if (map[direction1].min > map[direction2].max)
100
+ return State.Error;
101
+ if (map[direction2].min > map[direction1].max)
102
+ return State.Error;
103
+ }
104
+ }
105
+ if (Math.min(...otherDirections.map(d => map[d].max)) <=
106
+ Math.max(...pointedDirections.map(d => map[d].min)))
107
+ return State.Error;
108
+ if (pointedDirections.length === 0 &&
109
+ otherDirections.some(d => map[d].max !== Number.MAX_SAFE_INTEGER))
110
+ return State.Error;
111
+ if (pointedDirections.some(d => map[d].complete && map[d].max === Number.MAX_SAFE_INTEGER))
112
+ return State.Error;
113
+ if (pointedDirections.length > 0 &&
114
+ otherDirections.length > 0 &&
115
+ pointedDirections.every(d => map[d].complete) &&
116
+ Math.max(...pointedDirections.map(d => map[d].max)) <
117
+ Math.min(...otherDirections.map(d => map[d].min)))
118
+ return State.Satisfied;
119
+ if (allDirections.every(d => map[d].complete))
120
+ return State.Satisfied;
121
+ return State.Incomplete;
122
+ }
123
+ copyWith({ x, y, diagonals, directions, }) {
124
+ return new MyopiaSymbol(x ?? this.x, y ?? this.y, diagonals ?? this.diagonals, directions ?? this.directions);
125
+ }
126
+ withDirections(directions) {
127
+ return this.copyWith({ directions });
128
+ }
129
+ withDiagonals(diagonals) {
130
+ return this.copyWith({ diagonals });
131
+ }
132
+ }
133
+ Object.defineProperty(MyopiaSymbol, "CONFIGS", {
134
+ enumerable: true,
135
+ configurable: true,
136
+ writable: true,
137
+ value: Object.freeze([
138
+ {
139
+ type: ConfigType.Number,
140
+ default: 0,
141
+ field: 'x',
142
+ description: 'X',
143
+ configurable: false,
144
+ },
145
+ {
146
+ type: ConfigType.Number,
147
+ default: 0,
148
+ field: 'y',
149
+ description: 'Y',
150
+ configurable: false,
151
+ },
152
+ {
153
+ type: ConfigType.Boolean,
154
+ default: false,
155
+ field: 'diagonals',
156
+ description: 'Include diagonal directions',
157
+ configurable: true,
158
+ },
159
+ {
160
+ type: ConfigType.OrientationToggle,
161
+ default: orientationToggle(Orientation.Up, Orientation.Right),
162
+ field: 'directions',
163
+ description: 'Directions',
164
+ configurable: true,
165
+ },
166
+ ])
167
+ });
168
+ Object.defineProperty(MyopiaSymbol, "EXAMPLE_GRID", {
169
+ enumerable: true,
170
+ configurable: true,
171
+ writable: true,
172
+ value: Object.freeze(GridData.create(['wbwww', 'bwwwb', 'wwwww', 'wbwww']).withSymbols([
173
+ new MyopiaSymbol(1, 1, false, orientationToggle(Orientation.Up, Orientation.Left)),
174
+ new MyopiaSymbol(4, 3, false, orientationToggle(Orientation.Up)),
175
+ ]))
176
+ });
177
+ Object.defineProperty(MyopiaSymbol, "EXAMPLE_DIAGONAL_GRID", {
178
+ enumerable: true,
179
+ configurable: true,
180
+ writable: true,
181
+ value: Object.freeze(GridData.create(['wbwww', 'bwwwb', 'wwwww', 'wbwww']).withSymbols([
182
+ new MyopiaSymbol(1, 2, true, orientationToggle(Orientation.UpLeft, Orientation.Down)),
183
+ new MyopiaSymbol(3, 2, true, orientationToggle(Orientation.UpRight)),
184
+ ]))
185
+ });
186
+ export default MyopiaSymbol;
187
+ export const instance = new MyopiaSymbol(0, 0, false, orientationToggle(Orientation.Up, Orientation.Right));
@@ -0,0 +1,19 @@
1
+ import GridData from '../grid';
2
+ import { State } from '../primitives';
3
+ import Symbol from './symbol';
4
+ /**
5
+ * All symbols which contain a number should extend this class to be compatible with off by X rules.
6
+ */
7
+ export default abstract class NumberSymbol extends Symbol {
8
+ readonly x: number;
9
+ readonly y: number;
10
+ readonly number: number;
11
+ constructor(x: number, y: number, number: number);
12
+ abstract countTiles(grid: GridData): {
13
+ completed: number;
14
+ possible: number;
15
+ };
16
+ validateSymbol(grid: GridData): State;
17
+ withNumber(number: number): this;
18
+ }
19
+ export declare const instance: undefined;
@@ -0,0 +1,41 @@
1
+ import { State } from '../primitives';
2
+ import Symbol from './symbol';
3
+ /**
4
+ * All symbols which contain a number should extend this class to be compatible with off by X rules.
5
+ */
6
+ export default class NumberSymbol extends Symbol {
7
+ constructor(x, y, number) {
8
+ super(x, y);
9
+ Object.defineProperty(this, "x", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: x
14
+ });
15
+ Object.defineProperty(this, "y", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: y
20
+ });
21
+ Object.defineProperty(this, "number", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: number
26
+ });
27
+ this.number = number;
28
+ }
29
+ validateSymbol(grid) {
30
+ const { completed, possible } = this.countTiles(grid);
31
+ if (completed > this.number || possible < this.number)
32
+ return State.Error;
33
+ if (completed === this.number && possible === this.number)
34
+ return State.Satisfied;
35
+ return State.Incomplete;
36
+ }
37
+ withNumber(number) {
38
+ return this.copyWith({ number });
39
+ }
40
+ }
41
+ export const instance = undefined;
@@ -0,0 +1,16 @@
1
+ import { GridResizeHandler } from '../events/onGridResize';
2
+ import GridData from '../grid';
3
+ import Instruction from '../instruction';
4
+ import { State } from '../primitives';
5
+ export default abstract class Symbol extends Instruction implements GridResizeHandler {
6
+ readonly x: number;
7
+ readonly y: number;
8
+ constructor(x: number, y: number);
9
+ abstract validateSymbol(grid: GridData): State;
10
+ onGridResize(_grid: GridData, mode: 'insert' | 'remove', direction: 'row' | 'column', index: number): this | null;
11
+ get placementStep(): number;
12
+ withX(x: number): this;
13
+ withY(y: number): this;
14
+ withPosition(x: number, y: number): this;
15
+ }
16
+ export declare const instance: undefined;
@@ -0,0 +1,51 @@
1
+ import Instruction from '../instruction';
2
+ export default class Symbol extends Instruction {
3
+ constructor(x, y) {
4
+ super();
5
+ Object.defineProperty(this, "x", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: x
10
+ });
11
+ Object.defineProperty(this, "y", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: y
16
+ });
17
+ this.x = x;
18
+ this.y = y;
19
+ }
20
+ onGridResize(_grid, mode, direction, index) {
21
+ if (mode === 'insert') {
22
+ return this.copyWith({
23
+ x: direction === 'column' && this.x >= index ? this.x + 1 : this.x,
24
+ y: direction === 'row' && this.y >= index ? this.y + 1 : this.y,
25
+ });
26
+ }
27
+ else {
28
+ if (direction === 'column' && this.x === index)
29
+ return null;
30
+ if (direction === 'row' && this.y === index)
31
+ return null;
32
+ return this.copyWith({
33
+ x: direction === 'column' && this.x > index ? this.x - 1 : this.x,
34
+ y: direction === 'row' && this.y > index ? this.y - 1 : this.y,
35
+ });
36
+ }
37
+ }
38
+ get placementStep() {
39
+ return 0.5;
40
+ }
41
+ withX(x) {
42
+ return this.copyWith({ x });
43
+ }
44
+ withY(y) {
45
+ return this.copyWith({ y });
46
+ }
47
+ withPosition(x, y) {
48
+ return this.copyWith({ x, y });
49
+ }
50
+ }
51
+ export const instance = undefined;
@@ -0,0 +1,10 @@
1
+ export { instance as AreaNumberSymbol } from './areaNumberSymbol';
2
+ export { instance as CustomIconSymbol } from './customIconSymbol';
3
+ export { instance as CustomTextSymbol } from './customTextSymbol';
4
+ export { instance as DartSymbol } from './dartSymbol';
5
+ export { instance as GalaxySymbol } from './galaxySymbol';
6
+ export { instance as LetterSymbol } from './letterSymbol';
7
+ export { instance as LotusSymbol } from './lotusSymbol';
8
+ export { instance as MinesweeperSymbol } from './minesweeperSymbol';
9
+ export { instance as MyopiaSymbol } from './myopiaSymbol';
10
+ export { instance as ViewpointSymbol } from './viewpointSymbol';
@@ -0,0 +1,14 @@
1
+ /* prettier-ignore-start */
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ // noinspection JSUnusedGlobalSymbols
5
+ export { instance as AreaNumberSymbol } from './areaNumberSymbol';
6
+ export { instance as CustomIconSymbol } from './customIconSymbol';
7
+ export { instance as CustomTextSymbol } from './customTextSymbol';
8
+ export { instance as DartSymbol } from './dartSymbol';
9
+ export { instance as GalaxySymbol } from './galaxySymbol';
10
+ export { instance as LetterSymbol } from './letterSymbol';
11
+ export { instance as LotusSymbol } from './lotusSymbol';
12
+ export { instance as MinesweeperSymbol } from './minesweeperSymbol';
13
+ export { instance as MyopiaSymbol } from './myopiaSymbol';
14
+ export { instance as ViewpointSymbol } from './viewpointSymbol';