@logic-pad/core 0.26.0 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +31 -31
  2. package/assets/logic-core.global.d.ts +3264 -3247
  3. package/package.json +4 -1
  4. package/dist/benchmark/helper.d.ts +0 -21
  5. package/dist/benchmark/helper.js +0 -34
  6. package/dist/benchmark/prepareBench.d.ts +0 -1
  7. package/dist/benchmark/prepareBench.js +0 -140
  8. package/dist/benchmark/runBench.d.ts +0 -1
  9. package/dist/benchmark/runBench.js +0 -206
  10. package/dist/src/data/config.d.ts +0 -119
  11. package/dist/src/data/config.js +0 -72
  12. package/dist/src/data/configurable.d.ts +0 -14
  13. package/dist/src/data/configurable.js +0 -26
  14. package/dist/src/data/dataHelper.d.ts +0 -92
  15. package/dist/src/data/dataHelper.js +0 -217
  16. package/dist/src/data/events/eventHelper.d.ts +0 -1
  17. package/dist/src/data/events/eventHelper.js +0 -6
  18. package/dist/src/data/events/onFinalValidation.d.ts +0 -14
  19. package/dist/src/data/events/onFinalValidation.js +0 -4
  20. package/dist/src/data/events/onGetTile.d.ts +0 -7
  21. package/dist/src/data/events/onGetTile.js +0 -4
  22. package/dist/src/data/events/onGridChange.d.ts +0 -6
  23. package/dist/src/data/events/onGridChange.js +0 -4
  24. package/dist/src/data/events/onGridResize.d.ts +0 -9
  25. package/dist/src/data/events/onGridResize.js +0 -4
  26. package/dist/src/data/events/onSetGrid.d.ts +0 -7
  27. package/dist/src/data/events/onSetGrid.js +0 -19
  28. package/dist/src/data/events/onSymbolDisplay.d.ts +0 -16
  29. package/dist/src/data/events/onSymbolDisplay.js +0 -4
  30. package/dist/src/data/events/onSymbolMerge.d.ts +0 -10
  31. package/dist/src/data/events/onSymbolMerge.js +0 -4
  32. package/dist/src/data/events/onSymbolValidation.d.ts +0 -18
  33. package/dist/src/data/events/onSymbolValidation.js +0 -4
  34. package/dist/src/data/grid.d.ts +0 -410
  35. package/dist/src/data/grid.js +0 -1106
  36. package/dist/src/data/gridConnections.d.ts +0 -25
  37. package/dist/src/data/gridConnections.js +0 -309
  38. package/dist/src/data/gridZones.d.ts +0 -26
  39. package/dist/src/data/gridZones.js +0 -117
  40. package/dist/src/data/instruction.d.ts +0 -26
  41. package/dist/src/data/instruction.js +0 -29
  42. package/dist/src/data/primitives.d.ts +0 -138
  43. package/dist/src/data/primitives.js +0 -177
  44. package/dist/src/data/puzzle.d.ts +0 -73
  45. package/dist/src/data/puzzle.js +0 -105
  46. package/dist/src/data/rules/banPatternRule.d.ts +0 -30
  47. package/dist/src/data/rules/banPatternRule.js +0 -125
  48. package/dist/src/data/rules/cellCountPerZoneRule.d.ts +0 -23
  49. package/dist/src/data/rules/cellCountPerZoneRule.js +0 -39
  50. package/dist/src/data/rules/cellCountRule.d.ts +0 -33
  51. package/dist/src/data/rules/cellCountRule.js +0 -138
  52. package/dist/src/data/rules/completePatternRule.d.ts +0 -24
  53. package/dist/src/data/rules/completePatternRule.js +0 -46
  54. package/dist/src/data/rules/connectAllRule.d.ts +0 -29
  55. package/dist/src/data/rules/connectAllRule.js +0 -88
  56. package/dist/src/data/rules/connectZonesRule.d.ts +0 -29
  57. package/dist/src/data/rules/connectZonesRule.js +0 -111
  58. package/dist/src/data/rules/containsShapeRule.d.ts +0 -34
  59. package/dist/src/data/rules/containsShapeRule.js +0 -125
  60. package/dist/src/data/rules/customRule.d.ts +0 -34
  61. package/dist/src/data/rules/customRule.js +0 -74
  62. package/dist/src/data/rules/differentCountPerZoneRule.d.ts +0 -30
  63. package/dist/src/data/rules/differentCountPerZoneRule.js +0 -96
  64. package/dist/src/data/rules/exactCountPerZoneRule.d.ts +0 -33
  65. package/dist/src/data/rules/exactCountPerZoneRule.js +0 -99
  66. package/dist/src/data/rules/foresightRule.d.ts +0 -36
  67. package/dist/src/data/rules/foresightRule.js +0 -107
  68. package/dist/src/data/rules/index.d.ts +0 -3
  69. package/dist/src/data/rules/index.js +0 -10
  70. package/dist/src/data/rules/lyingSymbolRule.d.ts +0 -31
  71. package/dist/src/data/rules/lyingSymbolRule.js +0 -207
  72. package/dist/src/data/rules/musicControlLine.d.ts +0 -82
  73. package/dist/src/data/rules/musicControlLine.js +0 -167
  74. package/dist/src/data/rules/musicGridRule.d.ts +0 -51
  75. package/dist/src/data/rules/musicGridRule.js +0 -212
  76. package/dist/src/data/rules/mysteryRule.d.ts +0 -39
  77. package/dist/src/data/rules/mysteryRule.js +0 -146
  78. package/dist/src/data/rules/noLoopsRule.d.ts +0 -29
  79. package/dist/src/data/rules/noLoopsRule.js +0 -218
  80. package/dist/src/data/rules/offByXRule.d.ts +0 -32
  81. package/dist/src/data/rules/offByXRule.js +0 -124
  82. package/dist/src/data/rules/perfectionRule.d.ts +0 -45
  83. package/dist/src/data/rules/perfectionRule.js +0 -158
  84. package/dist/src/data/rules/regionAreaRule.d.ts +0 -34
  85. package/dist/src/data/rules/regionAreaRule.js +0 -149
  86. package/dist/src/data/rules/regionShapeRule.d.ts +0 -22
  87. package/dist/src/data/rules/regionShapeRule.js +0 -58
  88. package/dist/src/data/rules/rule.d.ts +0 -18
  89. package/dist/src/data/rules/rule.js +0 -19
  90. package/dist/src/data/rules/rules.gen.d.ts +0 -23
  91. package/dist/src/data/rules/rules.gen.js +0 -27
  92. package/dist/src/data/rules/sameCountPerZoneRule.d.ts +0 -30
  93. package/dist/src/data/rules/sameCountPerZoneRule.js +0 -95
  94. package/dist/src/data/rules/sameShapeRule.d.ts +0 -28
  95. package/dist/src/data/rules/sameShapeRule.js +0 -68
  96. package/dist/src/data/rules/symbolsPerRegionRule.d.ts +0 -38
  97. package/dist/src/data/rules/symbolsPerRegionRule.js +0 -181
  98. package/dist/src/data/rules/undercluedRule.d.ts +0 -24
  99. package/dist/src/data/rules/undercluedRule.js +0 -53
  100. package/dist/src/data/rules/uniqueShapeRule.d.ts +0 -28
  101. package/dist/src/data/rules/uniqueShapeRule.js +0 -65
  102. package/dist/src/data/rules/wrapAroundRule.d.ts +0 -36
  103. package/dist/src/data/rules/wrapAroundRule.js +0 -241
  104. package/dist/src/data/serializer/allSerializers.d.ts +0 -32
  105. package/dist/src/data/serializer/allSerializers.js +0 -71
  106. package/dist/src/data/serializer/compressor/allCompressors.d.ts +0 -14
  107. package/dist/src/data/serializer/compressor/allCompressors.js +0 -43
  108. package/dist/src/data/serializer/compressor/checksumCompressor.d.ts +0 -6
  109. package/dist/src/data/serializer/compressor/checksumCompressor.js +0 -21
  110. package/dist/src/data/serializer/compressor/compressorBase.d.ts +0 -16
  111. package/dist/src/data/serializer/compressor/compressorBase.js +0 -2
  112. package/dist/src/data/serializer/compressor/deflateCompressor.d.ts +0 -7
  113. package/dist/src/data/serializer/compressor/deflateCompressor.js +0 -17
  114. package/dist/src/data/serializer/compressor/gzipCompressor.d.ts +0 -5
  115. package/dist/src/data/serializer/compressor/gzipCompressor.js +0 -9
  116. package/dist/src/data/serializer/compressor/streamCompressor.d.ts +0 -6
  117. package/dist/src/data/serializer/compressor/streamCompressor.js +0 -41
  118. package/dist/src/data/serializer/serializerBase.d.ts +0 -32
  119. package/dist/src/data/serializer/serializerBase.js +0 -2
  120. package/dist/src/data/serializer/serializer_checksum.d.ts +0 -35
  121. package/dist/src/data/serializer/serializer_checksum.js +0 -179
  122. package/dist/src/data/serializer/serializer_v0.d.ts +0 -55
  123. package/dist/src/data/serializer/serializer_v0.js +0 -484
  124. package/dist/src/data/shapes.d.ts +0 -19
  125. package/dist/src/data/shapes.js +0 -137
  126. package/dist/src/data/solver/allSolvers.d.ts +0 -3
  127. package/dist/src/data/solver/allSolvers.js +0 -13
  128. package/dist/src/data/solver/auto/autoSolver.d.ts +0 -18
  129. package/dist/src/data/solver/auto/autoSolver.js +0 -153
  130. package/dist/src/data/solver/backtrack/backtrackSolver.d.ts +0 -11
  131. package/dist/src/data/solver/backtrack/backtrackSolver.js +0 -52
  132. package/dist/src/data/solver/backtrack/backtrackWorker.d.ts +0 -1
  133. package/dist/src/data/solver/backtrack/backtrackWorker.js +0 -308
  134. package/dist/src/data/solver/backtrack/data.d.ts +0 -47
  135. package/dist/src/data/solver/backtrack/data.js +0 -151
  136. package/dist/src/data/solver/backtrack/rules/banPattern.d.ts +0 -9
  137. package/dist/src/data/solver/backtrack/rules/banPattern.js +0 -77
  138. package/dist/src/data/solver/backtrack/rules/cellCount.d.ts +0 -7
  139. package/dist/src/data/solver/backtrack/rules/cellCount.js +0 -25
  140. package/dist/src/data/solver/backtrack/rules/connectAll.d.ts +0 -7
  141. package/dist/src/data/solver/backtrack/rules/connectAll.js +0 -44
  142. package/dist/src/data/solver/backtrack/rules/regionArea.d.ts +0 -8
  143. package/dist/src/data/solver/backtrack/rules/regionArea.js +0 -71
  144. package/dist/src/data/solver/backtrack/rules/regionShape.d.ts +0 -8
  145. package/dist/src/data/solver/backtrack/rules/regionShape.js +0 -57
  146. package/dist/src/data/solver/backtrack/rules/sameShape.d.ts +0 -8
  147. package/dist/src/data/solver/backtrack/rules/sameShape.js +0 -14
  148. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.d.ts +0 -10
  149. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.js +0 -82
  150. package/dist/src/data/solver/backtrack/rules/uniqueShape.d.ts +0 -8
  151. package/dist/src/data/solver/backtrack/rules/uniqueShape.js +0 -14
  152. package/dist/src/data/solver/backtrack/symbols/areaNumber.d.ts +0 -9
  153. package/dist/src/data/solver/backtrack/symbols/areaNumber.js +0 -75
  154. package/dist/src/data/solver/backtrack/symbols/dart.d.ts +0 -8
  155. package/dist/src/data/solver/backtrack/symbols/dart.js +0 -45
  156. package/dist/src/data/solver/backtrack/symbols/directionLinker.d.ts +0 -11
  157. package/dist/src/data/solver/backtrack/symbols/directionLinker.js +0 -121
  158. package/dist/src/data/solver/backtrack/symbols/focus.d.ts +0 -9
  159. package/dist/src/data/solver/backtrack/symbols/focus.js +0 -48
  160. package/dist/src/data/solver/backtrack/symbols/galaxy.d.ts +0 -9
  161. package/dist/src/data/solver/backtrack/symbols/galaxy.js +0 -14
  162. package/dist/src/data/solver/backtrack/symbols/letter.d.ts +0 -9
  163. package/dist/src/data/solver/backtrack/symbols/letter.js +0 -93
  164. package/dist/src/data/solver/backtrack/symbols/lotus.d.ts +0 -11
  165. package/dist/src/data/solver/backtrack/symbols/lotus.js +0 -55
  166. package/dist/src/data/solver/backtrack/symbols/minesweeper.d.ts +0 -9
  167. package/dist/src/data/solver/backtrack/symbols/minesweeper.js +0 -44
  168. package/dist/src/data/solver/backtrack/symbols/myopia.d.ts +0 -7
  169. package/dist/src/data/solver/backtrack/symbols/myopia.js +0 -73
  170. package/dist/src/data/solver/backtrack/symbols/viewpoint.d.ts +0 -7
  171. package/dist/src/data/solver/backtrack/symbols/viewpoint.js +0 -51
  172. package/dist/src/data/solver/cspuz/cspuzSolver.d.ts +0 -13
  173. package/dist/src/data/solver/cspuz/cspuzSolver.js +0 -117
  174. package/dist/src/data/solver/cspuz/cspuzWorker.d.ts +0 -1
  175. package/dist/src/data/solver/cspuz/cspuzWorker.js +0 -82
  176. package/dist/src/data/solver/cspuz/jsonify.d.ts +0 -3
  177. package/dist/src/data/solver/cspuz/jsonify.js +0 -211
  178. package/dist/src/data/solver/eventIteratingSolver.d.ts +0 -8
  179. package/dist/src/data/solver/eventIteratingSolver.js +0 -54
  180. package/dist/src/data/solver/solver.d.ts +0 -77
  181. package/dist/src/data/solver/solver.js +0 -59
  182. package/dist/src/data/solver/universal/universalSolver.d.ts +0 -7
  183. package/dist/src/data/solver/universal/universalSolver.js +0 -13
  184. package/dist/src/data/solver/universal/universalWorker.d.ts +0 -1
  185. package/dist/src/data/solver/universal/universalWorker.js +0 -128
  186. package/dist/src/data/symbols/areaNumberSymbol.d.ts +0 -31
  187. package/dist/src/data/symbols/areaNumberSymbol.js +0 -80
  188. package/dist/src/data/symbols/customIconSymbol.d.ts +0 -35
  189. package/dist/src/data/symbols/customIconSymbol.js +0 -94
  190. package/dist/src/data/symbols/customSymbol.d.ts +0 -25
  191. package/dist/src/data/symbols/customSymbol.js +0 -45
  192. package/dist/src/data/symbols/customTextSymbol.d.ts +0 -35
  193. package/dist/src/data/symbols/customTextSymbol.js +0 -95
  194. package/dist/src/data/symbols/dartSymbol.d.ts +0 -36
  195. package/dist/src/data/symbols/dartSymbol.js +0 -96
  196. package/dist/src/data/symbols/directionLinkerSymbol.d.ts +0 -29
  197. package/dist/src/data/symbols/directionLinkerSymbol.js +0 -232
  198. package/dist/src/data/symbols/everyLetterSymbol.d.ts +0 -32
  199. package/dist/src/data/symbols/everyLetterSymbol.js +0 -119
  200. package/dist/src/data/symbols/focusSymbol.d.ts +0 -40
  201. package/dist/src/data/symbols/focusSymbol.js +0 -159
  202. package/dist/src/data/symbols/galaxySymbol.d.ts +0 -27
  203. package/dist/src/data/symbols/galaxySymbol.js +0 -61
  204. package/dist/src/data/symbols/hiddenSymbol.d.ts +0 -38
  205. package/dist/src/data/symbols/hiddenSymbol.js +0 -113
  206. package/dist/src/data/symbols/houseSymbol.d.ts +0 -33
  207. package/dist/src/data/symbols/houseSymbol.js +0 -104
  208. package/dist/src/data/symbols/index.d.ts +0 -3
  209. package/dist/src/data/symbols/index.js +0 -10
  210. package/dist/src/data/symbols/letterSymbol.d.ts +0 -32
  211. package/dist/src/data/symbols/letterSymbol.js +0 -118
  212. package/dist/src/data/symbols/lotusSymbol.d.ts +0 -30
  213. package/dist/src/data/symbols/lotusSymbol.js +0 -132
  214. package/dist/src/data/symbols/minesweeperSymbol.d.ts +0 -33
  215. package/dist/src/data/symbols/minesweeperSymbol.js +0 -106
  216. package/dist/src/data/symbols/myopiaSymbol.d.ts +0 -37
  217. package/dist/src/data/symbols/myopiaSymbol.js +0 -182
  218. package/dist/src/data/symbols/numberSymbol.d.ts +0 -19
  219. package/dist/src/data/symbols/numberSymbol.js +0 -32
  220. package/dist/src/data/symbols/symbol.d.ts +0 -29
  221. package/dist/src/data/symbols/symbol.js +0 -87
  222. package/dist/src/data/symbols/symbols.gen.d.ts +0 -14
  223. package/dist/src/data/symbols/symbols.gen.js +0 -18
  224. package/dist/src/data/symbols/viewpointSymbol.d.ts +0 -32
  225. package/dist/src/data/symbols/viewpointSymbol.js +0 -95
  226. package/dist/src/data/tile.d.ts +0 -26
  227. package/dist/src/data/tile.js +0 -56
  228. package/dist/src/data/tileConnections.d.ts +0 -25
  229. package/dist/src/data/tileConnections.js +0 -74
  230. package/dist/src/data/validate.d.ts +0 -5
  231. package/dist/src/data/validate.js +0 -131
  232. package/dist/src/data/validateAsync.d.ts +0 -15
  233. package/dist/src/data/validateAsync.js +0 -71
  234. package/dist/src/data/validateAsyncWorker.d.ts +0 -1
  235. package/dist/src/data/validateAsyncWorker.js +0 -9
  236. package/dist/src/index.d.ts +0 -108
  237. package/dist/src/index.js +0 -111
  238. package/dist/src/polyfill/streamPolyfill.d.ts +0 -2
  239. package/dist/src/polyfill/streamPolyfill.js +0 -1
@@ -1,51 +0,0 @@
1
- import BTModule, { BTTile, IntArray2D, createOneTileResult, getOppositeColor, } from '../data.js';
2
- export default class ViewpointBTModule extends BTModule {
3
- instr;
4
- constructor(instr) {
5
- super();
6
- this.instr = instr;
7
- }
8
- checkGlobal(grid) {
9
- const tile = grid.getTile(this.instr.x, this.instr.y);
10
- if (tile === BTTile.Empty)
11
- return createOneTileResult(grid, { x: this.instr.x, y: this.instr.y });
12
- const tilesNeedCheck = IntArray2D.create(grid.width, grid.height);
13
- const ratings = [];
14
- let completed = 1;
15
- let possible = 1;
16
- const traverse = (dirX, dirY) => {
17
- let connected = true;
18
- let x = this.instr.x + dirX;
19
- let y = this.instr.y + dirY;
20
- while (grid.isInBound(x, y)) {
21
- const curTile = grid.getTile(x, y);
22
- if (connected) {
23
- if (tile === curTile) {
24
- completed += 1;
25
- if (completed > this.instr.number)
26
- return true;
27
- }
28
- else {
29
- if (curTile === BTTile.Empty) {
30
- tilesNeedCheck.set(x, y, 1);
31
- ratings.push({ pos: { x, y }, score: 1 });
32
- }
33
- connected = false;
34
- }
35
- }
36
- if (getOppositeColor(tile) === curTile ||
37
- curTile === BTTile.NonExist)
38
- break;
39
- possible += 1;
40
- x += dirX;
41
- y += dirY;
42
- }
43
- return false;
44
- };
45
- if (traverse(-1, 0) || traverse(1, 0) || traverse(0, -1) || traverse(0, 1))
46
- return false;
47
- if (possible < this.instr.number)
48
- return false;
49
- return { tilesNeedCheck, ratings };
50
- }
51
- }
@@ -1,13 +0,0 @@
1
- import EventIteratingSolver from '../eventIteratingSolver.js';
2
- import GridData from '../../grid.js';
3
- import Instruction from '../../instruction.js';
4
- export default class CspuzSolver extends EventIteratingSolver {
5
- private static readonly supportedInstrs;
6
- readonly id = "cspuz";
7
- readonly author = "semiexp";
8
- readonly description = "A blazingly fast WebAssembly solver that supports most rules and symbols (including underclued).";
9
- protected createWorker(): Worker;
10
- isGridSupported(grid: GridData): boolean;
11
- isInstructionSupported(grid: GridData, instruction: Instruction): boolean;
12
- isEnvironmentSupported(): Promise<boolean>;
13
- }
@@ -1,117 +0,0 @@
1
- import { instance as banPatternInstance } from '../../rules/banPatternRule.js';
2
- import { instance as cellCountInstance } from '../../rules/cellCountRule.js';
3
- import { instance as regionAreaInstance } from '../../rules/regionAreaRule.js';
4
- import { instance as sameShapeInstance } from '../../rules/sameShapeRule.js';
5
- import { instance as symbolsPerRegionInstance } from '../../rules/symbolsPerRegionRule.js';
6
- import { instance as undercluedInstance } from '../../rules/undercluedRule.js';
7
- import { instance as uniqueShapeInstance } from '../../rules/uniqueShapeRule.js';
8
- import { instance as offByXInstance } from '../../rules/offByXRule.js';
9
- import AreaNumberSymbol, { instance as areaNumberInstance, } from '../../symbols/areaNumberSymbol.js';
10
- import { instance as dartInstance } from '../../symbols/dartSymbol.js';
11
- import GalaxySymbol, { instance as galaxyInstance, } from '../../symbols/galaxySymbol.js';
12
- import LetterSymbol, { instance as letterInstance, } from '../../symbols/letterSymbol.js';
13
- import LotusSymbol, { instance as lotusInstance, } from '../../symbols/lotusSymbol.js';
14
- import { instance as minesweeperInstance } from '../../symbols/minesweeperSymbol.js';
15
- import { instance as viewpointInstance } from '../../symbols/viewpointSymbol.js';
16
- import { instance as connectAllInstance } from '../../rules/connectAllRule.js';
17
- import EventIteratingSolver from '../eventIteratingSolver.js';
18
- import GridData from '../../grid.js';
19
- import { Color } from '../../primitives.js';
20
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
21
- ('vite-apply-code-mod');
22
- export default class CspuzSolver extends EventIteratingSolver {
23
- static supportedInstrs = [
24
- minesweeperInstance.id,
25
- areaNumberInstance.id,
26
- letterInstance.id,
27
- dartInstance.id,
28
- viewpointInstance.id,
29
- lotusInstance.id,
30
- galaxyInstance.id,
31
- connectAllInstance.id,
32
- banPatternInstance.id,
33
- sameShapeInstance.id,
34
- uniqueShapeInstance.id,
35
- regionAreaInstance.id,
36
- cellCountInstance.id,
37
- offByXInstance.id,
38
- undercluedInstance.id,
39
- symbolsPerRegionInstance.id,
40
- ];
41
- id = 'cspuz';
42
- author = 'semiexp';
43
- description = 'A blazingly fast WebAssembly solver that supports most rules and symbols (including underclued).';
44
- createWorker() {
45
- return new Worker(new URL('./cspuzWorker.js', import.meta.url), {
46
- type: 'module',
47
- });
48
- }
49
- isGridSupported(grid) {
50
- if (!super.isGridSupported(grid)) {
51
- return false;
52
- }
53
- // special handling for fixed gray tiles
54
- if (grid.getTileCount(true, true, Color.Gray) > 0) {
55
- return false;
56
- }
57
- return true;
58
- }
59
- isInstructionSupported(grid, instruction) {
60
- if (instruction instanceof LotusSymbol ||
61
- instruction instanceof GalaxySymbol) {
62
- if (instruction.x % 1 !== 0 && instruction.y % 1 !== 0) {
63
- return false;
64
- }
65
- }
66
- if (instruction instanceof LotusSymbol ||
67
- instruction instanceof GalaxySymbol ||
68
- instruction instanceof AreaNumberSymbol ||
69
- instruction instanceof LetterSymbol) {
70
- if (instruction.x % 1 !== 0 || instruction.y % 1 !== 0) {
71
- const minX = Math.floor(instruction.x);
72
- const minY = Math.floor(instruction.y);
73
- const maxX = Math.ceil(instruction.x);
74
- const maxY = Math.ceil(instruction.y);
75
- const connectedTiles = grid.connections.getConnectedTiles({
76
- x: minX,
77
- y: minY,
78
- });
79
- if (connectedTiles.some(tile => tile.x === minX && tile.y === maxY) &&
80
- connectedTiles.some(tile => tile.x === maxX && tile.y === minY) &&
81
- connectedTiles.some(tile => tile.x === maxX && tile.y === maxY)) {
82
- return true;
83
- }
84
- let color = Color.Gray;
85
- for (let i = 0; i < 4; i++) {
86
- const x = i % 2 === 0 ? minX : maxX;
87
- const y = i < 2 ? minY : maxY;
88
- const tile = grid.getTile(x, y);
89
- if (!tile.fixed || !tile.exists) {
90
- return false;
91
- }
92
- if (tile.color !== Color.Gray) {
93
- if (color === Color.Gray) {
94
- color = tile.color;
95
- }
96
- else if (color !== tile.color) {
97
- return false;
98
- }
99
- }
100
- }
101
- return true;
102
- }
103
- }
104
- return CspuzSolver.supportedInstrs.includes(instruction.id);
105
- }
106
- async isEnvironmentSupported() {
107
- try {
108
- for await (const _ of this.solve(GridData.create(['.']))) {
109
- // do nothing
110
- }
111
- return true;
112
- }
113
- catch (_ex) {
114
- return false;
115
- }
116
- }
117
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,82 +0,0 @@
1
- import { solveLogicPad } from 'logic-pad-solver-core';
2
- import { Serializer } from '../../serializer/allSerializers.js';
3
- import { gridToJson } from './jsonify.js';
4
- import { instance as undercluedInstance } from '../../rules/undercluedRule.js';
5
- import { Color } from '../../primitives.js';
6
- function stringToColor(str) {
7
- if (str === 'dark') {
8
- return Color.Dark;
9
- }
10
- else if (str === 'light') {
11
- return Color.Light;
12
- }
13
- else {
14
- return Color.Gray;
15
- }
16
- }
17
- function postSolution(grid, solverResult) {
18
- if (solverResult === null) {
19
- postMessage(null);
20
- }
21
- else if ('error' in solverResult) {
22
- throw new Error(solverResult.error);
23
- }
24
- else {
25
- const solution = grid.withTiles(tiles => {
26
- for (const [y, row] of solverResult.entries()) {
27
- for (const [x, color] of row.entries()) {
28
- tiles[y][x] = tiles[y][x].withColor(stringToColor(color));
29
- }
30
- }
31
- return tiles;
32
- });
33
- postMessage(Serializer.stringifyGrid(solution));
34
- }
35
- }
36
- onmessage = e => {
37
- const grid = Serializer.parseGrid(e.data);
38
- const isUnderclued = !!grid.findRule(r => r.id === undercluedInstance.id);
39
- const puzzleData = gridToJson(grid);
40
- const solverResult = solveLogicPad(puzzleData, isUnderclued);
41
- postSolution(grid, solverResult);
42
- if (isUnderclued) {
43
- postMessage(null);
44
- return;
45
- }
46
- // Make use of the underclued mode to determine solution uniqueness
47
- if (solverResult !== null && !('error' in solverResult) && !isUnderclued) {
48
- const undercluedResult = solveLogicPad(puzzleData, true);
49
- if (undercluedResult === null) {
50
- postMessage(undefined); // Shouldn't happen because underclued grids should always be solvable
51
- }
52
- else if ('error' in undercluedResult) {
53
- throw new Error(undercluedResult.error);
54
- }
55
- else if (undercluedResult.every((row, y) => row.every((cell, x) => cell !== null || !grid.getTile(x, y).exists))) {
56
- postMessage(null);
57
- }
58
- else {
59
- let tweaked = false;
60
- for (const [y, row] of undercluedResult.entries()) {
61
- for (const [x, color] of row.entries()) {
62
- if (color !== null) {
63
- puzzleData.tiles[y][x].fixed = true;
64
- puzzleData.tiles[y][x].color = color;
65
- }
66
- else if (!tweaked && puzzleData.tiles[y][x].exists) {
67
- const positions = grid.connections.getConnectedTiles({ x, y });
68
- const newColor = solverResult[y][x] === 'dark' ? 'light' : 'dark';
69
- positions.forEach(({ x: px, y: py }) => {
70
- puzzleData.tiles[py][px].fixed = true;
71
- puzzleData.tiles[py][px].color = newColor;
72
- });
73
- tweaked = true;
74
- }
75
- }
76
- }
77
- const secondResult = solveLogicPad(puzzleData, false);
78
- postSolution(grid, secondResult);
79
- }
80
- }
81
- postMessage(undefined);
82
- };
@@ -1,3 +0,0 @@
1
- import { PuzzleData } from 'logic-pad-solver-core';
2
- import GridData from '../../grid.js';
3
- export declare function gridToJson(grid: GridData): PuzzleData;
@@ -1,211 +0,0 @@
1
- import { Color, Comparison } from '../../primitives.js';
2
- import BanPatternRule from '../../rules/banPatternRule.js';
3
- import CellCountRule from '../../rules/cellCountRule.js';
4
- import ConnectAllRule from '../../rules/connectAllRule.js';
5
- import OffByXRule from '../../rules/offByXRule.js';
6
- import RegionAreaRule from '../../rules/regionAreaRule.js';
7
- import SameShapeRule from '../../rules/sameShapeRule.js';
8
- import SymbolsPerRegionRule from '../../rules/symbolsPerRegionRule.js';
9
- import UndercluedRule from '../../rules/undercluedRule.js';
10
- import UniqueShapeRule from '../../rules/uniqueShapeRule.js';
11
- import { instance as areaNumberInstance, } from '../../symbols/areaNumberSymbol.js';
12
- import { instance as dartInstance, } from '../../symbols/dartSymbol.js';
13
- import { instance as galaxyInstance, } from '../../symbols/galaxySymbol.js';
14
- import { instance as letterInstance, } from '../../symbols/letterSymbol.js';
15
- import { instance as lotusInstance, } from '../../symbols/lotusSymbol.js';
16
- import { instance as minesweeperInstance, } from '../../symbols/minesweeperSymbol.js';
17
- import { instance as viewpointInstance, } from '../../symbols/viewpointSymbol.js';
18
- import TileData from '../../tile.js';
19
- function canonizeTiles(tileData) {
20
- const ret = [];
21
- for (const row of tileData) {
22
- const newRow = [];
23
- for (const tile of row) {
24
- if (tile.exists) {
25
- newRow.push(tile);
26
- }
27
- else {
28
- newRow.push(new TileData(true, false, Color.Gray));
29
- }
30
- }
31
- ret.push(newRow);
32
- }
33
- return ret;
34
- }
35
- export function gridToJson(grid) {
36
- const rules = [];
37
- for (const rule of grid.rules) {
38
- if (rule instanceof ConnectAllRule) {
39
- rules.push({
40
- type: 'connectAll',
41
- color: rule.color,
42
- });
43
- }
44
- else if (rule instanceof BanPatternRule) {
45
- rules.push({
46
- type: 'forbiddenPattern',
47
- pattern: canonizeTiles(rule.pattern.tiles),
48
- });
49
- }
50
- else if (rule instanceof SameShapeRule) {
51
- rules.push({
52
- type: 'sameShape',
53
- color: rule.color,
54
- });
55
- }
56
- else if (rule instanceof UniqueShapeRule) {
57
- rules.push({
58
- type: 'uniqueShape',
59
- color: rule.color,
60
- });
61
- }
62
- else if (rule instanceof RegionAreaRule) {
63
- rules.push({
64
- type: 'regionArea',
65
- color: rule.color,
66
- size: rule.size,
67
- });
68
- }
69
- else if (rule instanceof CellCountRule) {
70
- rules.push({
71
- type: 'cellCount',
72
- color: rule.color,
73
- count: rule.count,
74
- });
75
- }
76
- else if (rule instanceof OffByXRule) {
77
- rules.push({
78
- type: 'offByX',
79
- number: rule.number,
80
- });
81
- }
82
- else if (rule instanceof UndercluedRule) {
83
- continue;
84
- }
85
- else if (rule instanceof SymbolsPerRegionRule) {
86
- let kind;
87
- if (rule.comparison === Comparison.Equal) {
88
- kind = 'exactly';
89
- }
90
- else if (rule.comparison === Comparison.AtLeast) {
91
- kind = 'atLeast';
92
- }
93
- else if (rule.comparison === Comparison.AtMost) {
94
- kind = 'atMost';
95
- }
96
- else {
97
- throw new Error(`Unknown comparison (${rule.comparison})`);
98
- }
99
- rules.push({
100
- type: 'symbolCount',
101
- number: rule.count,
102
- kind,
103
- color: rule.color,
104
- });
105
- }
106
- else if (rule.necessaryForCompletion) {
107
- throw new Error(`Unknown rule type (${rule.explanation})`);
108
- }
109
- }
110
- for (const [rule, symbols] of grid.symbols) {
111
- if (rule === minesweeperInstance.id) {
112
- rules.push({
113
- type: 'minesweeper',
114
- tiles: symbols.map(s => ({
115
- x: Math.floor(s.x),
116
- y: Math.floor(s.y),
117
- number: s.number,
118
- })),
119
- });
120
- }
121
- else if (rule === areaNumberInstance.id) {
122
- rules.push({
123
- type: 'number',
124
- tiles: symbols.map(s => ({
125
- x: Math.floor(s.x),
126
- y: Math.floor(s.y),
127
- number: s.number,
128
- })),
129
- });
130
- }
131
- else if (rule === letterInstance.id) {
132
- rules.push({
133
- type: 'letter',
134
- tiles: symbols.map(s => ({
135
- x: Math.floor(s.x),
136
- y: Math.floor(s.y),
137
- letter: s.letter,
138
- })),
139
- });
140
- }
141
- else if (rule === dartInstance.id) {
142
- rules.push({
143
- type: 'dart',
144
- tiles: symbols.map(s => ({
145
- x: Math.floor(s.x),
146
- y: Math.floor(s.y),
147
- orientation: s.orientation,
148
- number: s.number,
149
- })),
150
- });
151
- }
152
- else if (rule === viewpointInstance.id) {
153
- rules.push({
154
- type: 'viewpoint',
155
- tiles: symbols.map(s => ({
156
- x: Math.floor(s.x),
157
- y: Math.floor(s.y),
158
- number: s.number,
159
- })),
160
- });
161
- }
162
- else if (rule === lotusInstance.id) {
163
- const tiles = symbols.map(s => ({
164
- x: Math.round(s.x * 2),
165
- y: Math.round(s.y * 2),
166
- orientation: s.orientation,
167
- }));
168
- rules.push({
169
- type: 'lotus',
170
- tiles,
171
- });
172
- }
173
- else if (rule === galaxyInstance.id) {
174
- const tiles = symbols.map(s => ({
175
- x: Math.round(s.x * 2),
176
- y: Math.round(s.y * 2),
177
- }));
178
- rules.push({
179
- type: 'galaxy',
180
- tiles,
181
- });
182
- }
183
- else if (symbols.some(s => s.necessaryForCompletion)) {
184
- throw new Error(`Unknown symbol type: ${rule}`);
185
- }
186
- }
187
- const connections = grid.connections.edges.map(edge => {
188
- return {
189
- x1: edge.x1,
190
- y1: edge.y1,
191
- x2: edge.x2,
192
- y2: edge.y2,
193
- };
194
- });
195
- const tiles = grid.tiles.map(row => {
196
- return row.map(tile => {
197
- return {
198
- exists: tile.exists,
199
- fixed: tile.fixed,
200
- color: tile.color,
201
- };
202
- });
203
- });
204
- return {
205
- width: grid.width,
206
- height: grid.height,
207
- connections,
208
- tiles,
209
- rules,
210
- };
211
- }
@@ -1,8 +0,0 @@
1
- import GridData from '../grid.js';
2
- import Solver from './solver.js';
3
- export default abstract class EventIteratingSolver extends Solver {
4
- readonly supportsCancellation = true;
5
- protected abstract createWorker(): Worker;
6
- protected isEnvironmentSupported(): Promise<boolean>;
7
- solve(grid: GridData, abortSignal?: AbortSignal): AsyncGenerator<GridData | null>;
8
- }
@@ -1,54 +0,0 @@
1
- import { Serializer } from '../serializer/allSerializers.js';
2
- import Solver from './solver.js';
3
- import { EventIterator } from 'event-iterator';
4
- export default class EventIteratingSolver extends Solver {
5
- supportsCancellation = true;
6
- isEnvironmentSupported() {
7
- try {
8
- const worker = this.createWorker();
9
- worker.terminate();
10
- return Promise.resolve(true);
11
- }
12
- catch (_ex) {
13
- return Promise.resolve(false);
14
- }
15
- }
16
- async *solve(grid, abortSignal) {
17
- const worker = this.createWorker();
18
- let terminateHandler;
19
- try {
20
- const iterator = new EventIterator(({ push, stop, fail }) => {
21
- terminateHandler = () => {
22
- worker.terminate();
23
- stop();
24
- };
25
- abortSignal?.addEventListener('abort', terminateHandler);
26
- worker.postMessage(Serializer.stringifyGrid(grid.resetTiles()));
27
- worker.addEventListener('message', (e) => {
28
- if (e.data) {
29
- push(Serializer.parseGrid(e.data));
30
- }
31
- else if (e.data === null) {
32
- push(null);
33
- stop(); // Stop after the first signal for out of solutions
34
- }
35
- else {
36
- stop();
37
- }
38
- });
39
- worker.addEventListener('error', (e) => {
40
- alert(`Error while solving!\n${e.message}`);
41
- fail(e);
42
- });
43
- });
44
- for await (const solution of iterator) {
45
- yield solution;
46
- }
47
- }
48
- finally {
49
- worker.terminate();
50
- if (terminateHandler)
51
- abortSignal?.removeEventListener('abort', terminateHandler);
52
- }
53
- }
54
- }
@@ -1,77 +0,0 @@
1
- import { CachedAccess } from '../dataHelper.js';
2
- import GridData from '../grid.js';
3
- import { Instruction } from '../../index.js';
4
- /**
5
- * Base class that all solvers must extend.
6
- */
7
- export default abstract class Solver {
8
- /**
9
- * The unique identifier of the solver.
10
- *
11
- * This is also displayed to the user when selecting a solver.
12
- */
13
- abstract get id(): string;
14
- /**
15
- * The author(s) of the solver.
16
- */
17
- abstract get author(): string;
18
- /**
19
- * A short paragraph describing when the user should use this solver.
20
- */
21
- abstract get description(): string;
22
- /**
23
- * Whether the solver supports cancellation. If `true`, the solver must respond to the abort signal if it is provided.
24
- */
25
- abstract get supportsCancellation(): boolean;
26
- /**
27
- * Solve the given grid. The implementation should delegate long-running tasks to a worker thread and yield solutions
28
- * asynchronously.
29
- *
30
- * The solver must yield at least once, otherwise the UI will not update.
31
- *
32
- * If the solver finds no solution other than those already yielded, it should yield `null`. Yielding `null` on the
33
- * first iteration indicates that the grid is unsolvable. Yielding `null` on the second iteration indicates that the
34
- * solution is unique.
35
- *
36
- * If the solve finds the trivial solution of not filling any tiles, such as in the case of an underclued grid with
37
- * too many alternate solutions, it must yield the solution instead of yielding `null`.
38
- *
39
- * In the current UI implementation, the solver will be terminated after yielding `null`, or after 2 iterations if
40
- * `null` is never yielded. The solver should perform any necessary cleanup in the `finally` block of the generator.
41
- *
42
- * @param grid The grid to solve. The provided grid is guaranteed to be supported by the solver. Some tiles in the
43
- * grid may already be filled by the user. It is up to the solver to decide whether to respect these tiles or not.
44
- * @param abortSignal An optional signal that the solver should subscribe to in order to cancel the operation. If the
45
- * solver does not support cancellation, it should ignore this parameter.
46
- */
47
- abstract solve(grid: GridData, abortSignal?: AbortSignal): AsyncGenerator<GridData | null>;
48
- /**
49
- * Check if the solver supports the current browser environment. This method is called once when the user first clicks
50
- * the "Solve" button, and the result is cached for the duration of the editor session.
51
- *
52
- * The `solve` method will not be called if this method returns `false`, and a message will be displayed to the user
53
- * indicating that the solver is not supported.
54
- *
55
- * @returns A promise that resolves to `true` if the environment is supported, or `false` otherwise.
56
- */
57
- protected isEnvironmentSupported(): Promise<boolean>;
58
- readonly environmentCheck: CachedAccess<Promise<boolean>>;
59
- /**
60
- * Check if the solver supports the given instruction. This is used to render a small indication in the UI for each
61
- * instruction in the editor.
62
- *
63
- * @param instructionId The unique identifier of the instruction.
64
- */
65
- isInstructionSupported(_grid: GridData, instruction: Instruction): boolean;
66
- /**
67
- * Check if the solver supports the given grid. This methid is frequently called when the user changes the grid, and
68
- * the result is used to enable or disable the "Solve" button.
69
- *
70
- * The `solve` method will not be called if this method returns `false`, and a message will be displayed to the user
71
- * indicating that the grid is not supported by this solver.
72
- *
73
- * @param grid The grid to check.
74
- * @returns `true` if the grid is supported, or `false` otherwise.
75
- */
76
- isGridSupported(grid: GridData): boolean;
77
- }
@@ -1,59 +0,0 @@
1
- import { CachedAccess } from '../dataHelper.js';
2
- import { allRules } from '../rules/index.js';
3
- import { allSymbols } from '../symbols/index.js';
4
- import { instance as undercluedInstance } from '../rules/undercluedRule.js';
5
- /**
6
- * Base class that all solvers must extend.
7
- */
8
- export default class Solver {
9
- /**
10
- * Check if the solver supports the current browser environment. This method is called once when the user first clicks
11
- * the "Solve" button, and the result is cached for the duration of the editor session.
12
- *
13
- * The `solve` method will not be called if this method returns `false`, and a message will be displayed to the user
14
- * indicating that the solver is not supported.
15
- *
16
- * @returns A promise that resolves to `true` if the environment is supported, or `false` otherwise.
17
- */
18
- isEnvironmentSupported() {
19
- return Promise.resolve(true);
20
- }
21
- environmentCheck = CachedAccess.of(() => this.isEnvironmentSupported());
22
- /**
23
- * Check if the solver supports the given instruction. This is used to render a small indication in the UI for each
24
- * instruction in the editor.
25
- *
26
- * @param instructionId The unique identifier of the instruction.
27
- */
28
- isInstructionSupported(_grid, instruction) {
29
- const symbol = allSymbols.get(instruction.id);
30
- if (symbol) {
31
- return !symbol.validateWithSolution;
32
- }
33
- const rule = allRules.get(instruction.id);
34
- if (rule) {
35
- return !rule.validateWithSolution || rule.id === undercluedInstance.id;
36
- }
37
- return false;
38
- }
39
- /**
40
- * Check if the solver supports the given grid. This methid is frequently called when the user changes the grid, and
41
- * the result is used to enable or disable the "Solve" button.
42
- *
43
- * The `solve` method will not be called if this method returns `false`, and a message will be displayed to the user
44
- * indicating that the grid is not supported by this solver.
45
- *
46
- * @param grid The grid to check.
47
- * @returns `true` if the grid is supported, or `false` otherwise.
48
- */
49
- isGridSupported(grid) {
50
- if (grid.rules.some(rule => rule.necessaryForCompletion &&
51
- !this.isInstructionSupported(grid, rule))) {
52
- return false;
53
- }
54
- if ([...grid.symbols.values()].some(symbols => symbols.some(s => s.necessaryForCompletion && !this.isInstructionSupported(grid, s)))) {
55
- return false;
56
- }
57
- return true;
58
- }
59
- }