@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,49 @@
1
+ import { RegionConstrainer } from 'grilops';
2
+ export default class Z3SolverContext {
3
+ constructor(grid) {
4
+ Object.defineProperty(this, "grid", {
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true,
8
+ value: grid
9
+ });
10
+ Object.defineProperty(this, "_regionConstrainer", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: void 0
15
+ });
16
+ this.grid = grid;
17
+ }
18
+ get solver() {
19
+ return this.grid.solver;
20
+ }
21
+ get lattice() {
22
+ return this.grid.lattice;
23
+ }
24
+ get symbolSet() {
25
+ return this.grid.symbolSet;
26
+ }
27
+ get ctx() {
28
+ return this.grid.ctx.context;
29
+ }
30
+ get z3() {
31
+ return this.grid.ctx.z3;
32
+ }
33
+ get regionConstrainer() {
34
+ if (!this._regionConstrainer) {
35
+ this._regionConstrainer = new RegionConstrainer(this.grid.ctx, this.lattice, this.solver, true, false, 1);
36
+ for (const p of this.lattice.points) {
37
+ for (const np of this.lattice.edgeSharingNeighbors(this.grid.grid, p)) {
38
+ this.solver.add(this.grid
39
+ .cellAt(p)
40
+ .eq(this.grid.cellAt(np.location))
41
+ .eq(this._regionConstrainer.regionIdGrid
42
+ .get(p)
43
+ .eq(this._regionConstrainer.regionIdGrid.get(np.location))));
44
+ }
45
+ }
46
+ }
47
+ return this._regionConstrainer;
48
+ }
49
+ }
@@ -0,0 +1,30 @@
1
+ import { AnyConfig } from '../config';
2
+ import GridData from '../grid';
3
+ import NumberSymbol from './numberSymbol';
4
+ export default class AreaNumberSymbol extends NumberSymbol {
5
+ private static readonly CONFIGS;
6
+ private static readonly EXAMPLE_GRID;
7
+ /**
8
+ * **Area Numbers must equal region sizes**
9
+ *
10
+ * @param x - The x-coordinate of the symbol.
11
+ * @param y - The y-coordinate of the symbol.
12
+ * @param number - The area number.
13
+ */
14
+ constructor(x: number, y: number, number: number);
15
+ get id(): string;
16
+ get explanation(): string;
17
+ get configs(): readonly AnyConfig[] | null;
18
+ createExampleGrid(): GridData;
19
+ countTiles(grid: GridData): {
20
+ completed: number;
21
+ possible: number;
22
+ };
23
+ copyWith({ x, y, number, }: {
24
+ x?: number;
25
+ y?: number;
26
+ number?: number;
27
+ }): this;
28
+ withNumber(number: number): this;
29
+ }
30
+ export declare const instance: AreaNumberSymbol;
@@ -0,0 +1,88 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import { Color } from '../primitives';
4
+ import NumberSymbol from './numberSymbol';
5
+ class AreaNumberSymbol extends NumberSymbol {
6
+ /**
7
+ * **Area Numbers must equal region sizes**
8
+ *
9
+ * @param x - The x-coordinate of the symbol.
10
+ * @param y - The y-coordinate of the symbol.
11
+ * @param number - The area number.
12
+ */
13
+ constructor(x, y, number) {
14
+ super(x, y, number);
15
+ }
16
+ get id() {
17
+ return `number`;
18
+ }
19
+ get explanation() {
20
+ return `*Area Numbers* must equal region sizes`;
21
+ }
22
+ get configs() {
23
+ return AreaNumberSymbol.CONFIGS;
24
+ }
25
+ createExampleGrid() {
26
+ return AreaNumberSymbol.EXAMPLE_GRID;
27
+ }
28
+ countTiles(grid) {
29
+ const thisX = Math.floor(this.x);
30
+ const thisY = Math.floor(this.y);
31
+ const color = grid.getTile(thisX, thisY).color;
32
+ if (color === Color.Gray)
33
+ return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
34
+ let completeCount = 0;
35
+ let grayCount = 0;
36
+ grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === Color.Gray || tile.color === color, () => {
37
+ grayCount++;
38
+ });
39
+ grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === color, () => {
40
+ completeCount++;
41
+ });
42
+ return { completed: completeCount, possible: grayCount };
43
+ }
44
+ copyWith({ x, y, number, }) {
45
+ return new AreaNumberSymbol(x ?? this.x, y ?? this.y, number ?? this.number);
46
+ }
47
+ withNumber(number) {
48
+ return this.copyWith({ number });
49
+ }
50
+ }
51
+ Object.defineProperty(AreaNumberSymbol, "CONFIGS", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: Object.freeze([
56
+ {
57
+ type: ConfigType.Number,
58
+ default: 0,
59
+ field: 'x',
60
+ description: 'X',
61
+ configurable: false,
62
+ },
63
+ {
64
+ type: ConfigType.Number,
65
+ default: 0,
66
+ field: 'y',
67
+ description: 'Y',
68
+ configurable: false,
69
+ },
70
+ {
71
+ type: ConfigType.Number,
72
+ default: 1,
73
+ field: 'number',
74
+ description: 'Number',
75
+ configurable: true,
76
+ },
77
+ ])
78
+ });
79
+ Object.defineProperty(AreaNumberSymbol, "EXAMPLE_GRID", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: Object.freeze(GridData.create(['wbbbb', 'wbbwb', 'bbwwb', 'bbbbb'])
84
+ .addSymbol(new AreaNumberSymbol(2, 2, 3))
85
+ .addSymbol(new AreaNumberSymbol(0, 1, 2)))
86
+ });
87
+ export default AreaNumberSymbol;
88
+ export const instance = new AreaNumberSymbol(0, 0, 1);
@@ -0,0 +1,35 @@
1
+ import { AnyConfig } from '../config';
2
+ import GridData from '../grid';
3
+ import CustomSymbol from './customSymbol';
4
+ import type Md from 'react-icons/md';
5
+ export type IconString = keyof typeof Md;
6
+ export default class CustomIconSymbol extends CustomSymbol {
7
+ readonly icon: IconString;
8
+ readonly rotation: number;
9
+ private static readonly EXAMPLE_GRID;
10
+ private static readonly CONFIGS;
11
+ /**
12
+ * **A custom icon symbol**
13
+ *
14
+ * @param description - The description of the symbol. Leave this empty to hide the description.
15
+ * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
16
+ * @param x - The x-coordinate of the symbol.
17
+ * @param y - The y-coordinate of the symbol.
18
+ * @param icon - The icon to display. All available icons can be found at https://react-icons.github.io/react-icons/icons/md/
19
+ * @param rotation - The rotation of the icon in degrees.
20
+ */
21
+ constructor(description: string, grid: GridData, x: number, y: number, icon: IconString, rotation?: number);
22
+ get id(): string;
23
+ get configs(): readonly AnyConfig[] | null;
24
+ copyWith({ description, grid, x, y, icon, rotation, }: {
25
+ description?: string;
26
+ grid?: GridData;
27
+ x?: number;
28
+ y?: number;
29
+ icon?: IconString;
30
+ rotation?: number;
31
+ }): this;
32
+ withIcon(icon: IconString): this;
33
+ withRotation(rotation: number): this;
34
+ }
35
+ export declare const instance: CustomIconSymbol;
@@ -0,0 +1,105 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import CustomSymbol from './customSymbol';
4
+ class CustomIconSymbol extends CustomSymbol {
5
+ /**
6
+ * **A custom icon symbol**
7
+ *
8
+ * @param description - The description of the symbol. Leave this empty to hide the description.
9
+ * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
10
+ * @param x - The x-coordinate of the symbol.
11
+ * @param y - The y-coordinate of the symbol.
12
+ * @param icon - The icon to display. All available icons can be found at https://react-icons.github.io/react-icons/icons/md/
13
+ * @param rotation - The rotation of the icon in degrees.
14
+ */
15
+ constructor(description, grid, x, y, icon, rotation = 0) {
16
+ super(description, grid, x, y);
17
+ Object.defineProperty(this, "icon", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: icon
22
+ });
23
+ Object.defineProperty(this, "rotation", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: rotation
28
+ });
29
+ this.icon = icon;
30
+ this.rotation = rotation;
31
+ }
32
+ get id() {
33
+ return `custom_icon`;
34
+ }
35
+ get configs() {
36
+ return CustomIconSymbol.CONFIGS;
37
+ }
38
+ copyWith({ description, grid, x, y, icon, rotation, }) {
39
+ return new CustomIconSymbol(description ?? this.description, grid ?? this.grid, x ?? this.x, y ?? this.y, icon ?? this.icon, rotation ?? this.rotation);
40
+ }
41
+ withIcon(icon) {
42
+ return this.copyWith({ icon });
43
+ }
44
+ withRotation(rotation) {
45
+ return this.copyWith({ rotation });
46
+ }
47
+ }
48
+ Object.defineProperty(CustomIconSymbol, "EXAMPLE_GRID", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: Object.freeze(new GridData(5, 4))
53
+ });
54
+ Object.defineProperty(CustomIconSymbol, "CONFIGS", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: Object.freeze([
59
+ {
60
+ type: ConfigType.Number,
61
+ default: 0,
62
+ field: 'x',
63
+ description: 'X',
64
+ configurable: false,
65
+ },
66
+ {
67
+ type: ConfigType.Number,
68
+ default: 0,
69
+ field: 'y',
70
+ description: 'Y',
71
+ configurable: false,
72
+ },
73
+ {
74
+ type: ConfigType.String,
75
+ default: 'A *custom* text symbol',
76
+ placeholder: 'Enter description. Emphasize with *asterisks*.',
77
+ field: 'description',
78
+ description: 'Description',
79
+ configurable: true,
80
+ },
81
+ {
82
+ type: ConfigType.Grid,
83
+ default: CustomIconSymbol.EXAMPLE_GRID,
84
+ field: 'grid',
85
+ description: 'Thumbnail Grid',
86
+ configurable: true,
87
+ },
88
+ {
89
+ type: ConfigType.Icon,
90
+ default: 'MdQuestionMark',
91
+ field: 'icon',
92
+ description: 'Icon',
93
+ configurable: true,
94
+ },
95
+ {
96
+ type: ConfigType.Number,
97
+ default: 0,
98
+ field: 'rotation',
99
+ description: 'Rotation',
100
+ configurable: true,
101
+ },
102
+ ])
103
+ });
104
+ export default CustomIconSymbol;
105
+ export const instance = new CustomIconSymbol('A *custom* icon symbol', new GridData(5, 4), 0, 0, 'MdQuestionMark');
@@ -0,0 +1,23 @@
1
+ import GridData from '../grid';
2
+ import { State } from '../primitives';
3
+ import MultiEntrySymbol from './multiEntrySymbol';
4
+ export default abstract class CustomSymbol extends MultiEntrySymbol {
5
+ readonly description: string;
6
+ readonly grid: GridData;
7
+ /**
8
+ * **A custom symbol**
9
+ *
10
+ * @param description - The description of the symbol. Leave this empty to hide the description.
11
+ * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
12
+ * @param x - The x-coordinate of the symbol.
13
+ * @param y - The y-coordinate of the symbol.
14
+ */
15
+ constructor(description: string, grid: GridData, x: number, y: number);
16
+ get explanation(): string;
17
+ createExampleGrid(): GridData;
18
+ validateSymbol(_grid: GridData): State;
19
+ get validateWithSolution(): boolean;
20
+ withDescription(description: string): this;
21
+ withGrid(grid: GridData): this;
22
+ }
23
+ export declare const instance: undefined;
@@ -0,0 +1,48 @@
1
+ import { State } from '../primitives';
2
+ import MultiEntrySymbol from './multiEntrySymbol';
3
+ export default class CustomSymbol extends MultiEntrySymbol {
4
+ /**
5
+ * **A custom symbol**
6
+ *
7
+ * @param description - The description of the symbol. Leave this empty to hide the description.
8
+ * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
9
+ * @param x - The x-coordinate of the symbol.
10
+ * @param y - The y-coordinate of the symbol.
11
+ */
12
+ constructor(description, grid, x, y) {
13
+ super(x, y);
14
+ Object.defineProperty(this, "description", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: description
19
+ });
20
+ Object.defineProperty(this, "grid", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: grid
25
+ });
26
+ this.description = description;
27
+ this.grid = grid;
28
+ }
29
+ get explanation() {
30
+ return this.description;
31
+ }
32
+ createExampleGrid() {
33
+ return this.grid;
34
+ }
35
+ validateSymbol(_grid) {
36
+ return State.Incomplete;
37
+ }
38
+ get validateWithSolution() {
39
+ return true;
40
+ }
41
+ withDescription(description) {
42
+ return this.copyWith({ description });
43
+ }
44
+ withGrid(grid) {
45
+ return this.copyWith({ grid });
46
+ }
47
+ }
48
+ export const instance = undefined;
@@ -0,0 +1,33 @@
1
+ import { AnyConfig } from '../config';
2
+ import GridData from '../grid';
3
+ import CustomSymbol from './customSymbol';
4
+ export default class CustomTextSymbol extends CustomSymbol {
5
+ readonly text: string;
6
+ readonly rotation: number;
7
+ private static readonly EXAMPLE_GRID;
8
+ private static readonly CONFIGS;
9
+ /**
10
+ * **A custom text symbol**
11
+ *
12
+ * @param description - The description of the symbol. Leave this empty to hide the description.
13
+ * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
14
+ * @param x - The x-coordinate of the symbol.
15
+ * @param y - The y-coordinate of the symbol.
16
+ * @param text - The text to display.
17
+ * @param rotation - The rotation of the text in degrees.
18
+ */
19
+ constructor(description: string, grid: GridData, x: number, y: number, text: string, rotation?: number);
20
+ get id(): string;
21
+ get configs(): readonly AnyConfig[] | null;
22
+ copyWith({ description, grid, x, y, text, rotation, }: {
23
+ description?: string;
24
+ grid?: GridData;
25
+ x?: number;
26
+ y?: number;
27
+ text?: string;
28
+ rotation?: number;
29
+ }): this;
30
+ withText(text: string): this;
31
+ withRotation(rotation: number): this;
32
+ }
33
+ export declare const instance: CustomTextSymbol;
@@ -0,0 +1,106 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import CustomSymbol from './customSymbol';
4
+ class CustomTextSymbol extends CustomSymbol {
5
+ /**
6
+ * **A custom text symbol**
7
+ *
8
+ * @param description - The description of the symbol. Leave this empty to hide the description.
9
+ * @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
10
+ * @param x - The x-coordinate of the symbol.
11
+ * @param y - The y-coordinate of the symbol.
12
+ * @param text - The text to display.
13
+ * @param rotation - The rotation of the text in degrees.
14
+ */
15
+ constructor(description, grid, x, y, text, rotation = 0) {
16
+ super(description, grid, x, y);
17
+ Object.defineProperty(this, "text", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: text
22
+ });
23
+ Object.defineProperty(this, "rotation", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: rotation
28
+ });
29
+ this.text = text;
30
+ this.rotation = rotation;
31
+ }
32
+ get id() {
33
+ return `custom_text`;
34
+ }
35
+ get configs() {
36
+ return CustomTextSymbol.CONFIGS;
37
+ }
38
+ copyWith({ description, grid, x, y, text, rotation, }) {
39
+ return new CustomTextSymbol(description ?? this.description, grid ?? this.grid, x ?? this.x, y ?? this.y, text ?? this.text, rotation ?? this.rotation);
40
+ }
41
+ withText(text) {
42
+ return this.copyWith({ text });
43
+ }
44
+ withRotation(rotation) {
45
+ return this.copyWith({ rotation });
46
+ }
47
+ }
48
+ Object.defineProperty(CustomTextSymbol, "EXAMPLE_GRID", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: Object.freeze(new GridData(5, 4))
53
+ });
54
+ Object.defineProperty(CustomTextSymbol, "CONFIGS", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: Object.freeze([
59
+ {
60
+ type: ConfigType.Number,
61
+ default: 0,
62
+ field: 'x',
63
+ description: 'X',
64
+ configurable: false,
65
+ },
66
+ {
67
+ type: ConfigType.Number,
68
+ default: 0,
69
+ field: 'y',
70
+ description: 'Y',
71
+ configurable: false,
72
+ },
73
+ {
74
+ type: ConfigType.String,
75
+ default: 'A *custom* text symbol',
76
+ placeholder: 'Enter description. Emphasize with *asterisks*.',
77
+ field: 'description',
78
+ description: 'Description',
79
+ configurable: true,
80
+ },
81
+ {
82
+ type: ConfigType.Grid,
83
+ default: CustomTextSymbol.EXAMPLE_GRID,
84
+ field: 'grid',
85
+ description: 'Thumbnail Grid',
86
+ configurable: true,
87
+ },
88
+ {
89
+ type: ConfigType.String,
90
+ default: 'X',
91
+ placeholder: 'Short text to be displayed on the symbol',
92
+ field: 'text',
93
+ description: 'Text',
94
+ configurable: true,
95
+ },
96
+ {
97
+ type: ConfigType.Number,
98
+ default: 0,
99
+ field: 'rotation',
100
+ description: 'Rotation',
101
+ configurable: true,
102
+ },
103
+ ])
104
+ });
105
+ export default CustomTextSymbol;
106
+ export const instance = new CustomTextSymbol('A *custom* text symbol', new GridData(5, 4), 0, 0, 'X');
@@ -0,0 +1,35 @@
1
+ import { AnyConfig } from '../config';
2
+ import GridData from '../grid';
3
+ import { Orientation } from '../primitives';
4
+ import NumberSymbol from './numberSymbol';
5
+ export default class DartSymbol extends NumberSymbol {
6
+ readonly orientation: Orientation;
7
+ private static readonly CONFIGS;
8
+ private static readonly EXAMPLE_GRID;
9
+ /**
10
+ * **Darts count opposite color cells in that direction**
11
+ *
12
+ * @param x - The x-coordinate of the symbol.
13
+ * @param y - The y-coordinate of the symbol.
14
+ * @param number - The number of cells seen by the symbol.
15
+ * @param orientation - The orientation of the symbol.
16
+ */
17
+ constructor(x: number, y: number, number: number, orientation: Orientation);
18
+ get id(): string;
19
+ get placementStep(): number;
20
+ get explanation(): string;
21
+ get configs(): readonly AnyConfig[] | null;
22
+ createExampleGrid(): GridData;
23
+ countTiles(grid: GridData): {
24
+ completed: number;
25
+ possible: number;
26
+ };
27
+ copyWith({ x, y, number, orientation, }: {
28
+ x?: number;
29
+ y?: number;
30
+ number?: number;
31
+ orientation?: Orientation;
32
+ }): this;
33
+ withNumber(number: number): this;
34
+ }
35
+ export declare const instance: DartSymbol;
@@ -0,0 +1,110 @@
1
+ import { ConfigType } from '../config';
2
+ import GridData from '../grid';
3
+ import { Color, Orientation } from '../primitives';
4
+ import NumberSymbol from './numberSymbol';
5
+ class DartSymbol extends NumberSymbol {
6
+ /**
7
+ * **Darts count opposite color cells in that direction**
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
+ * @param orientation - The orientation of the symbol.
13
+ */
14
+ constructor(x, y, number, orientation) {
15
+ super(x, y, number);
16
+ Object.defineProperty(this, "orientation", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: orientation
21
+ });
22
+ this.orientation = orientation;
23
+ }
24
+ get id() {
25
+ return `dart`;
26
+ }
27
+ get placementStep() {
28
+ return 1;
29
+ }
30
+ get explanation() {
31
+ return `*Darts* count opposite color cells in that direction`;
32
+ }
33
+ get configs() {
34
+ return DartSymbol.CONFIGS;
35
+ }
36
+ createExampleGrid() {
37
+ return DartSymbol.EXAMPLE_GRID;
38
+ }
39
+ countTiles(grid) {
40
+ if (Math.floor(this.x) !== this.x || Math.floor(this.y) !== this.y)
41
+ return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
42
+ const color = grid.getTile(this.x, this.y).color;
43
+ if (color === Color.Gray)
44
+ return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
45
+ let gray = 0;
46
+ let opposite = 0;
47
+ grid.iterateDirectionAll({ x: this.x, y: this.y }, this.orientation, () => true, tile => {
48
+ if (!tile.exists)
49
+ return;
50
+ if (tile.color === Color.Gray)
51
+ gray++;
52
+ else if (tile.color !== color)
53
+ opposite++;
54
+ });
55
+ return { completed: opposite, possible: opposite + gray };
56
+ }
57
+ copyWith({ x, y, number, orientation, }) {
58
+ return new DartSymbol(x ?? this.x, y ?? this.y, number ?? this.number, orientation ?? this.orientation);
59
+ }
60
+ withNumber(number) {
61
+ return this.copyWith({ number });
62
+ }
63
+ }
64
+ Object.defineProperty(DartSymbol, "CONFIGS", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: Object.freeze([
69
+ {
70
+ type: ConfigType.Number,
71
+ default: 0,
72
+ field: 'x',
73
+ description: 'X',
74
+ configurable: false,
75
+ },
76
+ {
77
+ type: ConfigType.Number,
78
+ default: 0,
79
+ field: 'y',
80
+ description: 'Y',
81
+ configurable: false,
82
+ },
83
+ {
84
+ type: ConfigType.Number,
85
+ default: 1,
86
+ field: 'number',
87
+ description: 'Number',
88
+ configurable: true,
89
+ },
90
+ {
91
+ type: ConfigType.Orientation,
92
+ default: Orientation.Right,
93
+ field: 'orientation',
94
+ description: 'Orientation',
95
+ configurable: true,
96
+ },
97
+ ])
98
+ });
99
+ Object.defineProperty(DartSymbol, "EXAMPLE_GRID", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: Object.freeze(GridData.create(['wwbbw', 'wwwww', 'wbwbb', 'wwwww'])
104
+ .addSymbol(new DartSymbol(1, 0, 1, Orientation.Down))
105
+ .addSymbol(new DartSymbol(4, 0, 2, Orientation.Left))
106
+ .addSymbol(new DartSymbol(3, 1, 1, Orientation.Down))
107
+ .addSymbol(new DartSymbol(0, 2, 3, Orientation.Right)))
108
+ });
109
+ export default DartSymbol;
110
+ export const instance = new DartSymbol(0, 0, 1, Orientation.Right);