@logic-pad/core 0.26.2 → 0.26.3

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 (240) hide show
  1. package/assets/logic-core.global.d.ts +3264 -3264
  2. package/dist/benchmark/helper.d.ts +21 -0
  3. package/dist/benchmark/helper.js +34 -0
  4. package/dist/benchmark/prepareBench.d.ts +1 -0
  5. package/dist/benchmark/prepareBench.js +140 -0
  6. package/dist/benchmark/runBench.d.ts +1 -0
  7. package/dist/benchmark/runBench.js +206 -0
  8. package/dist/src/data/config.d.ts +119 -0
  9. package/dist/src/data/config.js +72 -0
  10. package/dist/src/data/configurable.d.ts +14 -0
  11. package/dist/src/data/configurable.js +26 -0
  12. package/dist/src/data/dataHelper.d.ts +92 -0
  13. package/dist/src/data/dataHelper.js +217 -0
  14. package/dist/src/data/events/eventHelper.d.ts +1 -0
  15. package/dist/src/data/events/eventHelper.js +6 -0
  16. package/dist/src/data/events/onFinalValidation.d.ts +14 -0
  17. package/dist/src/data/events/onFinalValidation.js +4 -0
  18. package/dist/src/data/events/onGetTile.d.ts +7 -0
  19. package/dist/src/data/events/onGetTile.js +4 -0
  20. package/dist/src/data/events/onGridChange.d.ts +6 -0
  21. package/dist/src/data/events/onGridChange.js +4 -0
  22. package/dist/src/data/events/onGridResize.d.ts +9 -0
  23. package/dist/src/data/events/onGridResize.js +4 -0
  24. package/dist/src/data/events/onSetGrid.d.ts +7 -0
  25. package/dist/src/data/events/onSetGrid.js +19 -0
  26. package/dist/src/data/events/onSymbolDisplay.d.ts +16 -0
  27. package/dist/src/data/events/onSymbolDisplay.js +4 -0
  28. package/dist/src/data/events/onSymbolMerge.d.ts +10 -0
  29. package/dist/src/data/events/onSymbolMerge.js +4 -0
  30. package/dist/src/data/events/onSymbolValidation.d.ts +18 -0
  31. package/dist/src/data/events/onSymbolValidation.js +4 -0
  32. package/dist/src/data/grid.d.ts +410 -0
  33. package/dist/src/data/grid.js +1106 -0
  34. package/dist/src/data/gridConnections.d.ts +25 -0
  35. package/dist/src/data/gridConnections.js +309 -0
  36. package/dist/src/data/gridZones.d.ts +26 -0
  37. package/dist/src/data/gridZones.js +117 -0
  38. package/dist/src/data/instruction.d.ts +26 -0
  39. package/dist/src/data/instruction.js +29 -0
  40. package/dist/src/data/primitives.d.ts +138 -0
  41. package/dist/src/data/primitives.js +177 -0
  42. package/dist/src/data/puzzle.d.ts +73 -0
  43. package/dist/src/data/puzzle.js +105 -0
  44. package/dist/src/data/rules/banPatternRule.d.ts +30 -0
  45. package/dist/src/data/rules/banPatternRule.js +125 -0
  46. package/dist/src/data/rules/cellCountPerZoneRule.d.ts +23 -0
  47. package/dist/src/data/rules/cellCountPerZoneRule.js +39 -0
  48. package/dist/src/data/rules/cellCountRule.d.ts +33 -0
  49. package/dist/src/data/rules/cellCountRule.js +138 -0
  50. package/dist/src/data/rules/completePatternRule.d.ts +24 -0
  51. package/dist/src/data/rules/completePatternRule.js +46 -0
  52. package/dist/src/data/rules/connectAllRule.d.ts +29 -0
  53. package/dist/src/data/rules/connectAllRule.js +88 -0
  54. package/dist/src/data/rules/connectZonesRule.d.ts +29 -0
  55. package/dist/src/data/rules/connectZonesRule.js +111 -0
  56. package/dist/src/data/rules/containsShapeRule.d.ts +34 -0
  57. package/dist/src/data/rules/containsShapeRule.js +125 -0
  58. package/dist/src/data/rules/customRule.d.ts +34 -0
  59. package/dist/src/data/rules/customRule.js +74 -0
  60. package/dist/src/data/rules/differentCountPerZoneRule.d.ts +30 -0
  61. package/dist/src/data/rules/differentCountPerZoneRule.js +96 -0
  62. package/dist/src/data/rules/exactCountPerZoneRule.d.ts +33 -0
  63. package/dist/src/data/rules/exactCountPerZoneRule.js +99 -0
  64. package/dist/src/data/rules/foresightRule.d.ts +36 -0
  65. package/dist/src/data/rules/foresightRule.js +107 -0
  66. package/dist/src/data/rules/index.d.ts +3 -0
  67. package/dist/src/data/rules/index.js +10 -0
  68. package/dist/src/data/rules/lyingSymbolRule.d.ts +31 -0
  69. package/dist/src/data/rules/lyingSymbolRule.js +207 -0
  70. package/dist/src/data/rules/musicControlLine.d.ts +82 -0
  71. package/dist/src/data/rules/musicControlLine.js +167 -0
  72. package/dist/src/data/rules/musicGridRule.d.ts +51 -0
  73. package/dist/src/data/rules/musicGridRule.js +212 -0
  74. package/dist/src/data/rules/mysteryRule.d.ts +39 -0
  75. package/dist/src/data/rules/mysteryRule.js +146 -0
  76. package/dist/src/data/rules/noLoopsRule.d.ts +29 -0
  77. package/dist/src/data/rules/noLoopsRule.js +218 -0
  78. package/dist/src/data/rules/offByXRule.d.ts +32 -0
  79. package/dist/src/data/rules/offByXRule.js +124 -0
  80. package/dist/src/data/rules/perfectionRule.d.ts +45 -0
  81. package/dist/src/data/rules/perfectionRule.js +158 -0
  82. package/dist/src/data/rules/regionAreaRule.d.ts +34 -0
  83. package/dist/src/data/rules/regionAreaRule.js +149 -0
  84. package/dist/src/data/rules/regionShapeRule.d.ts +22 -0
  85. package/dist/src/data/rules/regionShapeRule.js +58 -0
  86. package/dist/src/data/rules/rule.d.ts +18 -0
  87. package/dist/src/data/rules/rule.js +19 -0
  88. package/dist/src/data/rules/rules.gen.d.ts +23 -0
  89. package/dist/src/data/rules/rules.gen.js +27 -0
  90. package/dist/src/data/rules/sameCountPerZoneRule.d.ts +30 -0
  91. package/dist/src/data/rules/sameCountPerZoneRule.js +95 -0
  92. package/dist/src/data/rules/sameShapeRule.d.ts +28 -0
  93. package/dist/src/data/rules/sameShapeRule.js +68 -0
  94. package/dist/src/data/rules/symbolsPerRegionRule.d.ts +38 -0
  95. package/dist/src/data/rules/symbolsPerRegionRule.js +181 -0
  96. package/dist/src/data/rules/undercluedRule.d.ts +24 -0
  97. package/dist/src/data/rules/undercluedRule.js +53 -0
  98. package/dist/src/data/rules/uniqueShapeRule.d.ts +28 -0
  99. package/dist/src/data/rules/uniqueShapeRule.js +65 -0
  100. package/dist/src/data/rules/wrapAroundRule.d.ts +36 -0
  101. package/dist/src/data/rules/wrapAroundRule.js +241 -0
  102. package/dist/src/data/serializer/allSerializers.d.ts +35 -0
  103. package/dist/src/data/serializer/allSerializers.js +78 -0
  104. package/dist/src/data/serializer/compressor/allCompressors.d.ts +14 -0
  105. package/dist/src/data/serializer/compressor/allCompressors.js +43 -0
  106. package/dist/src/data/serializer/compressor/checksumCompressor.d.ts +6 -0
  107. package/dist/src/data/serializer/compressor/checksumCompressor.js +21 -0
  108. package/dist/src/data/serializer/compressor/compressorBase.d.ts +16 -0
  109. package/dist/src/data/serializer/compressor/compressorBase.js +2 -0
  110. package/dist/src/data/serializer/compressor/deflateCompressor.d.ts +7 -0
  111. package/dist/src/data/serializer/compressor/deflateCompressor.js +17 -0
  112. package/dist/src/data/serializer/compressor/gzipCompressor.d.ts +5 -0
  113. package/dist/src/data/serializer/compressor/gzipCompressor.js +9 -0
  114. package/dist/src/data/serializer/compressor/streamCompressor.d.ts +6 -0
  115. package/dist/src/data/serializer/compressor/streamCompressor.js +41 -0
  116. package/dist/src/data/serializer/serializerBase.d.ts +32 -0
  117. package/dist/src/data/serializer/serializerBase.js +2 -0
  118. package/dist/src/data/serializer/serializer_checksum.d.ts +35 -0
  119. package/dist/src/data/serializer/serializer_checksum.js +179 -0
  120. package/dist/src/data/serializer/serializer_v0.d.ts +55 -0
  121. package/dist/src/data/serializer/serializer_v0.js +484 -0
  122. package/dist/src/data/shapes.d.ts +19 -0
  123. package/dist/src/data/shapes.js +137 -0
  124. package/dist/src/data/solver/allSolvers.d.ts +3 -0
  125. package/dist/src/data/solver/allSolvers.js +13 -0
  126. package/dist/src/data/solver/auto/autoSolver.d.ts +18 -0
  127. package/dist/src/data/solver/auto/autoSolver.js +156 -0
  128. package/dist/src/data/solver/backtrack/backtrackSolver.d.ts +11 -0
  129. package/dist/src/data/solver/backtrack/backtrackSolver.js +54 -0
  130. package/dist/src/data/solver/backtrack/backtrackWorker.d.ts +1 -0
  131. package/dist/src/data/solver/backtrack/backtrackWorker.js +312 -0
  132. package/dist/src/data/solver/backtrack/data.d.ts +47 -0
  133. package/dist/src/data/solver/backtrack/data.js +151 -0
  134. package/dist/src/data/solver/backtrack/rules/banPattern.d.ts +9 -0
  135. package/dist/src/data/solver/backtrack/rules/banPattern.js +77 -0
  136. package/dist/src/data/solver/backtrack/rules/cellCount.d.ts +7 -0
  137. package/dist/src/data/solver/backtrack/rules/cellCount.js +25 -0
  138. package/dist/src/data/solver/backtrack/rules/connectAll.d.ts +7 -0
  139. package/dist/src/data/solver/backtrack/rules/connectAll.js +44 -0
  140. package/dist/src/data/solver/backtrack/rules/regionArea.d.ts +8 -0
  141. package/dist/src/data/solver/backtrack/rules/regionArea.js +71 -0
  142. package/dist/src/data/solver/backtrack/rules/regionShape.d.ts +8 -0
  143. package/dist/src/data/solver/backtrack/rules/regionShape.js +57 -0
  144. package/dist/src/data/solver/backtrack/rules/sameShape.d.ts +8 -0
  145. package/dist/src/data/solver/backtrack/rules/sameShape.js +14 -0
  146. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.d.ts +10 -0
  147. package/dist/src/data/solver/backtrack/rules/symbolsPerRegion.js +82 -0
  148. package/dist/src/data/solver/backtrack/rules/uniqueShape.d.ts +8 -0
  149. package/dist/src/data/solver/backtrack/rules/uniqueShape.js +14 -0
  150. package/dist/src/data/solver/backtrack/symbols/areaNumber.d.ts +9 -0
  151. package/dist/src/data/solver/backtrack/symbols/areaNumber.js +75 -0
  152. package/dist/src/data/solver/backtrack/symbols/dart.d.ts +8 -0
  153. package/dist/src/data/solver/backtrack/symbols/dart.js +45 -0
  154. package/dist/src/data/solver/backtrack/symbols/directionLinker.d.ts +11 -0
  155. package/dist/src/data/solver/backtrack/symbols/directionLinker.js +121 -0
  156. package/dist/src/data/solver/backtrack/symbols/focus.d.ts +9 -0
  157. package/dist/src/data/solver/backtrack/symbols/focus.js +48 -0
  158. package/dist/src/data/solver/backtrack/symbols/galaxy.d.ts +9 -0
  159. package/dist/src/data/solver/backtrack/symbols/galaxy.js +14 -0
  160. package/dist/src/data/solver/backtrack/symbols/letter.d.ts +9 -0
  161. package/dist/src/data/solver/backtrack/symbols/letter.js +95 -0
  162. package/dist/src/data/solver/backtrack/symbols/lotus.d.ts +11 -0
  163. package/dist/src/data/solver/backtrack/symbols/lotus.js +55 -0
  164. package/dist/src/data/solver/backtrack/symbols/minesweeper.d.ts +9 -0
  165. package/dist/src/data/solver/backtrack/symbols/minesweeper.js +44 -0
  166. package/dist/src/data/solver/backtrack/symbols/myopia.d.ts +7 -0
  167. package/dist/src/data/solver/backtrack/symbols/myopia.js +73 -0
  168. package/dist/src/data/solver/backtrack/symbols/viewpoint.d.ts +7 -0
  169. package/dist/src/data/solver/backtrack/symbols/viewpoint.js +51 -0
  170. package/dist/src/data/solver/cspuz/cspuzSolver.d.ts +13 -0
  171. package/dist/src/data/solver/cspuz/cspuzSolver.js +124 -0
  172. package/dist/src/data/solver/cspuz/cspuzWorker.d.ts +1 -0
  173. package/dist/src/data/solver/cspuz/cspuzWorker.js +82 -0
  174. package/dist/src/data/solver/cspuz/jsonify.d.ts +3 -0
  175. package/dist/src/data/solver/cspuz/jsonify.js +215 -0
  176. package/dist/src/data/solver/eventIteratingSolver.d.ts +8 -0
  177. package/dist/src/data/solver/eventIteratingSolver.js +54 -0
  178. package/dist/src/data/solver/solver.d.ts +77 -0
  179. package/dist/src/data/solver/solver.js +59 -0
  180. package/dist/src/data/solver/universal/universalSolver.d.ts +7 -0
  181. package/dist/src/data/solver/universal/universalSolver.js +13 -0
  182. package/dist/src/data/solver/universal/universalWorker.d.ts +1 -0
  183. package/dist/src/data/solver/universal/universalWorker.js +128 -0
  184. package/dist/src/data/symbols/areaNumberSymbol.d.ts +31 -0
  185. package/dist/src/data/symbols/areaNumberSymbol.js +80 -0
  186. package/dist/src/data/symbols/customIconSymbol.d.ts +35 -0
  187. package/dist/src/data/symbols/customIconSymbol.js +94 -0
  188. package/dist/src/data/symbols/customSymbol.d.ts +25 -0
  189. package/dist/src/data/symbols/customSymbol.js +45 -0
  190. package/dist/src/data/symbols/customTextSymbol.d.ts +35 -0
  191. package/dist/src/data/symbols/customTextSymbol.js +95 -0
  192. package/dist/src/data/symbols/dartSymbol.d.ts +36 -0
  193. package/dist/src/data/symbols/dartSymbol.js +96 -0
  194. package/dist/src/data/symbols/directionLinkerSymbol.d.ts +29 -0
  195. package/dist/src/data/symbols/directionLinkerSymbol.js +232 -0
  196. package/dist/src/data/symbols/everyLetterSymbol.d.ts +32 -0
  197. package/dist/src/data/symbols/everyLetterSymbol.js +119 -0
  198. package/dist/src/data/symbols/focusSymbol.d.ts +40 -0
  199. package/dist/src/data/symbols/focusSymbol.js +159 -0
  200. package/dist/src/data/symbols/galaxySymbol.d.ts +27 -0
  201. package/dist/src/data/symbols/galaxySymbol.js +61 -0
  202. package/dist/src/data/symbols/hiddenSymbol.d.ts +38 -0
  203. package/dist/src/data/symbols/hiddenSymbol.js +113 -0
  204. package/dist/src/data/symbols/houseSymbol.d.ts +33 -0
  205. package/dist/src/data/symbols/houseSymbol.js +104 -0
  206. package/dist/src/data/symbols/index.d.ts +3 -0
  207. package/dist/src/data/symbols/index.js +10 -0
  208. package/dist/src/data/symbols/letterSymbol.d.ts +32 -0
  209. package/dist/src/data/symbols/letterSymbol.js +118 -0
  210. package/dist/src/data/symbols/lotusSymbol.d.ts +30 -0
  211. package/dist/src/data/symbols/lotusSymbol.js +132 -0
  212. package/dist/src/data/symbols/minesweeperSymbol.d.ts +33 -0
  213. package/dist/src/data/symbols/minesweeperSymbol.js +106 -0
  214. package/dist/src/data/symbols/myopiaSymbol.d.ts +37 -0
  215. package/dist/src/data/symbols/myopiaSymbol.js +182 -0
  216. package/dist/src/data/symbols/numberSymbol.d.ts +19 -0
  217. package/dist/src/data/symbols/numberSymbol.js +32 -0
  218. package/dist/src/data/symbols/symbol.d.ts +29 -0
  219. package/dist/src/data/symbols/symbol.js +87 -0
  220. package/dist/src/data/symbols/symbols.gen.d.ts +15 -0
  221. package/dist/src/data/symbols/symbols.gen.js +19 -0
  222. package/dist/src/data/symbols/unsupportedSymbol.d.ts +23 -0
  223. package/dist/src/data/symbols/unsupportedSymbol.js +47 -0
  224. package/dist/src/data/symbols/viewpointSymbol.d.ts +32 -0
  225. package/dist/src/data/symbols/viewpointSymbol.js +95 -0
  226. package/dist/src/data/tile.d.ts +26 -0
  227. package/dist/src/data/tile.js +56 -0
  228. package/dist/src/data/tileConnections.d.ts +25 -0
  229. package/dist/src/data/tileConnections.js +74 -0
  230. package/dist/src/data/validate.d.ts +5 -0
  231. package/dist/src/data/validate.js +131 -0
  232. package/dist/src/data/validateAsync.d.ts +15 -0
  233. package/dist/src/data/validateAsync.js +71 -0
  234. package/dist/src/data/validateAsyncWorker.d.ts +1 -0
  235. package/dist/src/data/validateAsyncWorker.js +9 -0
  236. package/dist/src/index.d.ts +109 -0
  237. package/dist/src/index.js +112 -0
  238. package/dist/src/polyfill/streamPolyfill.d.ts +2 -0
  239. package/dist/src/polyfill/streamPolyfill.js +1 -0
  240. package/package.json +1 -1
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Major rules are frequently referenced in grids to provide additional UI.
3
+ */
4
+ export var MajorRule;
5
+ (function (MajorRule) {
6
+ MajorRule["MusicGrid"] = "music";
7
+ MajorRule["CompletePattern"] = "complete_pattern";
8
+ MajorRule["Underclued"] = "underclued";
9
+ MajorRule["WrapAround"] = "wrap_around";
10
+ })(MajorRule || (MajorRule = {}));
11
+ /**
12
+ * General puzzle types for categorization. One puzzle can have multiple types.
13
+ */
14
+ export var PuzzleType;
15
+ (function (PuzzleType) {
16
+ PuzzleType["Logic"] = "logic";
17
+ PuzzleType["Underclued"] = "underclued";
18
+ PuzzleType["Pattern"] = "pattern";
19
+ PuzzleType["Music"] = "music";
20
+ })(PuzzleType || (PuzzleType = {}));
21
+ export var State;
22
+ (function (State) {
23
+ /**
24
+ * Describes the violation of a rule.
25
+ */
26
+ State["Error"] = "error";
27
+ /**
28
+ * Describes that a rule is satisfied and complete in the current grid.
29
+ */
30
+ State["Satisfied"] = "satisfied";
31
+ /**
32
+ * Describes that a rule is not violated, but is not yet complete in the current grid.
33
+ */
34
+ State["Incomplete"] = "incomplete";
35
+ /**
36
+ * Describes that a rule is violated but ignored due to the effect of another rule.
37
+ */
38
+ State["Ignored"] = "ignored";
39
+ })(State || (State = {}));
40
+ // eslint-disable-next-line @typescript-eslint/no-namespace
41
+ (function (State) {
42
+ function isSatisfied(state) {
43
+ return state === State.Satisfied || state === State.Ignored;
44
+ }
45
+ State.isSatisfied = isSatisfied;
46
+ })(State || (State = {}));
47
+ export var Color;
48
+ (function (Color) {
49
+ Color["Dark"] = "dark";
50
+ Color["Light"] = "light";
51
+ Color["Gray"] = "gray";
52
+ })(Color || (Color = {}));
53
+ export var Comparison;
54
+ (function (Comparison) {
55
+ Comparison["Equal"] = "eq";
56
+ Comparison["AtLeast"] = "ge";
57
+ Comparison["AtMost"] = "le";
58
+ })(Comparison || (Comparison = {}));
59
+ export const COMPARISONS = [
60
+ Comparison.Equal,
61
+ Comparison.AtLeast,
62
+ Comparison.AtMost,
63
+ ];
64
+ export var Wrapping;
65
+ (function (Wrapping) {
66
+ Wrapping["None"] = "none";
67
+ Wrapping["Wrap"] = "wrap";
68
+ Wrapping["WrapReverse"] = "wrap-reverse";
69
+ Wrapping["ReflectReverse"] = "reflect-reverse";
70
+ })(Wrapping || (Wrapping = {}));
71
+ export const WRAPPINGS = [
72
+ Wrapping.None,
73
+ Wrapping.Wrap,
74
+ Wrapping.WrapReverse,
75
+ Wrapping.ReflectReverse,
76
+ ];
77
+ export var Direction;
78
+ (function (Direction) {
79
+ Direction["Up"] = "up";
80
+ Direction["Down"] = "down";
81
+ Direction["Left"] = "left";
82
+ Direction["Right"] = "right";
83
+ })(Direction || (Direction = {}));
84
+ export const DIRECTIONS = [
85
+ Direction.Up,
86
+ Direction.Down,
87
+ Direction.Left,
88
+ Direction.Right,
89
+ ];
90
+ export function directionToggle(...directions) {
91
+ const result = {
92
+ up: false,
93
+ down: false,
94
+ left: false,
95
+ right: false,
96
+ };
97
+ for (const direction of directions) {
98
+ result[direction] = true;
99
+ }
100
+ return result;
101
+ }
102
+ export var Orientation;
103
+ (function (Orientation) {
104
+ Orientation["Up"] = "up";
105
+ Orientation["UpRight"] = "up-right";
106
+ Orientation["Right"] = "right";
107
+ Orientation["DownRight"] = "down-right";
108
+ Orientation["Down"] = "down";
109
+ Orientation["DownLeft"] = "down-left";
110
+ Orientation["Left"] = "left";
111
+ Orientation["UpLeft"] = "up-left";
112
+ })(Orientation || (Orientation = {}));
113
+ export const ORIENTATIONS = [
114
+ Orientation.Up,
115
+ Orientation.UpRight,
116
+ Orientation.Right,
117
+ Orientation.DownRight,
118
+ Orientation.Down,
119
+ Orientation.DownLeft,
120
+ Orientation.Left,
121
+ Orientation.UpLeft,
122
+ ];
123
+ export function orientationToggle(...orientations) {
124
+ const result = {
125
+ up: false,
126
+ 'up-right': false,
127
+ right: false,
128
+ 'down-right': false,
129
+ down: false,
130
+ 'down-left': false,
131
+ left: false,
132
+ 'up-left': false,
133
+ };
134
+ for (const orientation of orientations) {
135
+ result[orientation] = true;
136
+ }
137
+ return result;
138
+ }
139
+ export var Mode;
140
+ (function (Mode) {
141
+ Mode["Create"] = "create";
142
+ Mode["Solve"] = "solve";
143
+ Mode["Perfection"] = "perfection";
144
+ })(Mode || (Mode = {}));
145
+ export var Instrument;
146
+ (function (Instrument) {
147
+ Instrument["Piano"] = "piano";
148
+ Instrument["Drum"] = "drum";
149
+ Instrument["Violin"] = "violin";
150
+ Instrument["Xylophone"] = "xylophone";
151
+ Instrument["GuitarAcoustic"] = "guitar-acoustic";
152
+ Instrument["GuitarElectric"] = "guitar-electric";
153
+ Instrument["Flute"] = "flute";
154
+ Instrument["Trumpet"] = "trumpet";
155
+ })(Instrument || (Instrument = {}));
156
+ export const INSTRUMENTS = [
157
+ Instrument.Piano,
158
+ Instrument.Drum,
159
+ Instrument.Violin,
160
+ Instrument.Xylophone,
161
+ Instrument.GuitarAcoustic,
162
+ Instrument.GuitarElectric,
163
+ Instrument.Flute,
164
+ Instrument.Trumpet,
165
+ ];
166
+ export const DRUM_SAMPLES = [
167
+ 'snare',
168
+ 'kick',
169
+ 'hihat',
170
+ 'hihat-open',
171
+ 'crash',
172
+ 'tom',
173
+ 'rim',
174
+ ];
175
+ export function isDrumSample(note) {
176
+ return DRUM_SAMPLES.includes(note);
177
+ }
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod';
2
+ import GridData from './grid.js';
3
+ import { GridState, PuzzleType } from './primitives.js';
4
+ export type PuzzleMetadata = {
5
+ /**
6
+ * The title of the puzzle. (required)
7
+ */
8
+ title: string;
9
+ /**
10
+ * The author of the puzzle. (required)
11
+ */
12
+ author: string;
13
+ /**
14
+ * A description of the puzzle. (can be empty)
15
+ */
16
+ description: string;
17
+ /**
18
+ * The difficulty of the puzzle, from 0 to 10. (required)
19
+ *
20
+ * 0 represents an unrated puzzle, 6-10 represent star difficulties.
21
+ */
22
+ difficulty: number;
23
+ };
24
+ export declare const MetadataSchema: z.ZodObject<{
25
+ title: z.ZodString;
26
+ author: z.ZodString;
27
+ description: z.ZodString;
28
+ difficulty: z.ZodNumber;
29
+ }, z.core.$strict>;
30
+ export declare const PuzzleSchema: z.ZodObject<{
31
+ title: z.ZodString;
32
+ author: z.ZodString;
33
+ description: z.ZodString;
34
+ difficulty: z.ZodNumber;
35
+ grid: z.ZodCustom<GridData, GridData>;
36
+ solution: z.ZodNullable<z.ZodCustom<GridData, GridData>>;
37
+ }, z.core.$strict>;
38
+ export type PuzzleData = {
39
+ /**
40
+ * The grid of the puzzle. (required)
41
+ *
42
+ * You must fix all given cells in the grid. The rest of the cells will be cleared.
43
+ */
44
+ grid: GridData;
45
+ /**
46
+ * The solution to the puzzle. (optional)
47
+ *
48
+ * You should provide a solution if a rule requires it. Otherwise, the rule can never be satisfied.
49
+ *
50
+ * If there are no rules that require a solution, this field will be ignored.
51
+ */
52
+ solution: GridData | null;
53
+ };
54
+ export type Puzzle = PuzzleMetadata & PuzzleData;
55
+ /**
56
+ * Checks if two puzzles are equal.
57
+ */
58
+ export declare function puzzleEquals(a: Puzzle, b: Puzzle): boolean;
59
+ /**
60
+ * Get the types of a puzzle based on its grid properties. The returned types are ordered by their priority.
61
+ * The first type is the most important one.
62
+ */
63
+ export declare function getPuzzleTypes(grid: GridData): PuzzleType[];
64
+ export interface PuzzleChecklistItem {
65
+ id: string;
66
+ success: boolean;
67
+ mandatory: boolean;
68
+ }
69
+ export interface PuzzleChecklist {
70
+ items: PuzzleChecklistItem[];
71
+ isValid: boolean;
72
+ }
73
+ export declare function validatePuzzleChecklist(metadata: PuzzleMetadata, gridWithSolution: GridData, state: GridState): PuzzleChecklist;
@@ -0,0 +1,105 @@
1
+ import { z } from 'zod';
2
+ import GridData from './grid.js';
3
+ import { Color, PuzzleType, State } from './primitives.js';
4
+ export const MetadataSchema = z.strictObject({
5
+ title: z.string('Title must be a string').min(1, 'Title must not be empty'),
6
+ author: z
7
+ .string('Author must be a string')
8
+ .min(1, 'Author must not be empty'),
9
+ description: z.string('Description must be a string'),
10
+ difficulty: z
11
+ .number('Difficulty must be a number')
12
+ .int('Difficulty must be an integer')
13
+ .min(0, 'Difficulty must be at least 0')
14
+ .max(10, 'Difficulty must be at most 10'),
15
+ }, 'Data must be an object');
16
+ export const PuzzleSchema = MetadataSchema.extend({
17
+ grid: z.instanceof(GridData, { error: 'Grid must be a GridData instance' }),
18
+ solution: z
19
+ .instanceof(GridData, { error: 'Solution must be a GridData instance' })
20
+ .nullable(),
21
+ }).strict();
22
+ /**
23
+ * Checks if two puzzles are equal.
24
+ */
25
+ export function puzzleEquals(a, b) {
26
+ return (a.title === b.title &&
27
+ a.author === b.author &&
28
+ a.description === b.description &&
29
+ a.difficulty === b.difficulty &&
30
+ a.grid.equals(b.grid) &&
31
+ ((a.solution === null && b.solution === null) ||
32
+ (!!a.solution && !!b.solution && a.solution.equals(b.solution))));
33
+ }
34
+ /**
35
+ * Get the types of a puzzle based on its grid properties. The returned types are ordered by their priority.
36
+ * The first type is the most important one.
37
+ */
38
+ export function getPuzzleTypes(grid) {
39
+ const types = [];
40
+ let logic = true;
41
+ if (grid.musicGrid.value) {
42
+ types.push(PuzzleType.Music);
43
+ logic = false;
44
+ }
45
+ if (grid.completePattern.value) {
46
+ types.push(PuzzleType.Pattern);
47
+ logic = false;
48
+ }
49
+ if (grid.underclued.value) {
50
+ types.push(PuzzleType.Underclued);
51
+ }
52
+ if (logic) {
53
+ types.push(PuzzleType.Logic);
54
+ }
55
+ return types;
56
+ }
57
+ export function validatePuzzleChecklist(metadata, gridWithSolution, state) {
58
+ const checklist = {
59
+ items: [],
60
+ isValid: true,
61
+ };
62
+ checklist.items.push({
63
+ id: 'metadataValid',
64
+ success: MetadataSchema.safeParse(metadata).success,
65
+ mandatory: true,
66
+ });
67
+ checklist.items.push({
68
+ id: 'gridValid',
69
+ success: gridWithSolution.width > 0 && gridWithSolution.height > 0,
70
+ mandatory: true,
71
+ });
72
+ if (gridWithSolution.requireSolution()) {
73
+ checklist.items.push({
74
+ id: 'autoValidation',
75
+ success: false,
76
+ mandatory: false,
77
+ });
78
+ checklist.items.push({
79
+ id: 'solutionIsNotEmpty',
80
+ success: gridWithSolution.musicGrid.value
81
+ ? gridWithSolution.tiles.some(row => row.some(tile => !tile.fixed && tile.color === Color.Dark))
82
+ : gridWithSolution.tiles.some(row => row.some(tile => !tile.fixed && tile.color !== Color.Gray)),
83
+ mandatory: true,
84
+ });
85
+ }
86
+ else {
87
+ checklist.items.push({
88
+ id: 'autoValidation',
89
+ success: true,
90
+ mandatory: false,
91
+ });
92
+ checklist.items.push({
93
+ id: 'solutionIsComplete',
94
+ success: gridWithSolution.isComplete(),
95
+ mandatory: true,
96
+ });
97
+ checklist.items.push({
98
+ id: 'solutionIsValid',
99
+ success: state.final !== State.Error,
100
+ mandatory: true,
101
+ });
102
+ }
103
+ checklist.isValid = !checklist.items.some(x => !x.success && x.mandatory);
104
+ return checklist;
105
+ }
@@ -0,0 +1,30 @@
1
+ import { AnyConfig } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import { RuleState } from '../primitives.js';
4
+ import { Shape } from '../shapes.js';
5
+ import Rule, { SearchVariant } from './rule.js';
6
+ export default class BanPatternRule extends Rule {
7
+ readonly title = "Ban Pattern";
8
+ private static readonly EXAMPLE_GRID;
9
+ private static readonly CONFIGS;
10
+ private static readonly SEARCH_VARIANTS;
11
+ readonly pattern: GridData;
12
+ readonly cache: Shape[];
13
+ /**
14
+ * **Don't make this pattern**
15
+ *
16
+ * @param pattern - GridData representing the banned pattern. Only non-gray tiles are considered.
17
+ */
18
+ constructor(pattern: GridData);
19
+ get id(): string;
20
+ get explanation(): string;
21
+ get configs(): readonly AnyConfig[] | null;
22
+ createExampleGrid(): GridData;
23
+ get searchVariants(): SearchVariant[];
24
+ validateGrid(grid: GridData): RuleState;
25
+ copyWith({ pattern }: {
26
+ pattern?: GridData;
27
+ }): this;
28
+ withPattern(pattern: GridData): this;
29
+ }
30
+ export declare const instance: BanPatternRule;
@@ -0,0 +1,125 @@
1
+ import { ConfigType } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import { array } from '../dataHelper.js';
4
+ import { Color, State } from '../primitives.js';
5
+ import { getShapeVariants, sanitizePatternGrid, tilesToShape, } from '../shapes.js';
6
+ import Rule from './rule.js';
7
+ export default class BanPatternRule extends Rule {
8
+ title = 'Ban Pattern';
9
+ static EXAMPLE_GRID = Object.freeze(GridData.create(['nnnnn', 'nnnnn', 'wwwwn', 'nnnnn', 'nnnnn']));
10
+ static CONFIGS = Object.freeze([
11
+ {
12
+ type: ConfigType.Shape,
13
+ default: BanPatternRule.EXAMPLE_GRID,
14
+ resizable: true,
15
+ field: 'pattern',
16
+ description: 'Pattern',
17
+ explanation: 'The pattern to be banned. Can be a mix of dark and light tiles.',
18
+ configurable: true,
19
+ },
20
+ ]);
21
+ static SEARCH_VARIANTS = [
22
+ new BanPatternRule(BanPatternRule.EXAMPLE_GRID).searchVariant(),
23
+ ];
24
+ pattern;
25
+ cache;
26
+ /**
27
+ * **Don't make this pattern**
28
+ *
29
+ * @param pattern - GridData representing the banned pattern. Only non-gray tiles are considered.
30
+ */
31
+ constructor(pattern) {
32
+ super();
33
+ this.pattern = sanitizePatternGrid(pattern);
34
+ this.cache = getShapeVariants(tilesToShape(this.pattern.tiles));
35
+ }
36
+ get id() {
37
+ return `ban_pattern`;
38
+ }
39
+ get explanation() {
40
+ return `Don't make this pattern`;
41
+ }
42
+ get configs() {
43
+ return BanPatternRule.CONFIGS;
44
+ }
45
+ createExampleGrid() {
46
+ let minX = Number.POSITIVE_INFINITY;
47
+ let minY = Number.POSITIVE_INFINITY;
48
+ let maxX = Number.NEGATIVE_INFINITY;
49
+ let maxY = Number.NEGATIVE_INFINITY;
50
+ this.pattern.forEach((tile, x, y) => {
51
+ if (tile.color !== Color.Gray && tile.exists) {
52
+ minX = Math.min(minX, x);
53
+ minY = Math.min(minY, y);
54
+ maxX = Math.max(maxX, x);
55
+ maxY = Math.max(maxY, y);
56
+ }
57
+ });
58
+ const width = maxX - minX + 1;
59
+ const height = maxY - minY + 1;
60
+ if (!Number.isFinite(width) || !Number.isFinite(height)) {
61
+ return GridData.create(0, 0);
62
+ }
63
+ const tiles = array(width, height, (x, y) => {
64
+ const tile = this.pattern.getTile(x + minX, y + minY);
65
+ if (!tile.exists || tile.color !== Color.Gray)
66
+ return tile;
67
+ return tile.withExists(false);
68
+ });
69
+ return GridData.create(width, height, tiles);
70
+ }
71
+ get searchVariants() {
72
+ return BanPatternRule.SEARCH_VARIANTS;
73
+ }
74
+ validateGrid(grid) {
75
+ for (const pattern of this.cache) {
76
+ let startX, startY, endX, endY;
77
+ if (grid.wrapAround.value) {
78
+ startX = -pattern.width;
79
+ startY = -pattern.height;
80
+ endX = grid.width - 1;
81
+ endY = grid.height - 1;
82
+ }
83
+ else {
84
+ startX = 0;
85
+ startY = 0;
86
+ endX = grid.width - pattern.width;
87
+ endY = grid.height - pattern.height;
88
+ }
89
+ for (let y = startY; y <= endY; y++) {
90
+ for (let x = startX; x <= endX; x++) {
91
+ let match = true;
92
+ const visited = [];
93
+ for (const tile of pattern.elements) {
94
+ const pos = grid.toArrayCoordinates(x + tile.x, y + tile.y);
95
+ if (grid.wrapAround.value && // optimization: no need to check visited if wrapAround is disabled
96
+ visited.some(p => p.x === pos.x && p.y === pos.y)) {
97
+ match = false;
98
+ break;
99
+ }
100
+ visited.push(pos);
101
+ const t = grid.getTile(x + tile.x, y + tile.y);
102
+ if (!t.exists || t.color !== tile.color) {
103
+ match = false;
104
+ break;
105
+ }
106
+ }
107
+ if (match) {
108
+ return {
109
+ state: State.Error,
110
+ positions: pattern.elements.map(tile => grid.toArrayCoordinates(x + tile.x, y + tile.y)),
111
+ };
112
+ }
113
+ }
114
+ }
115
+ }
116
+ return { state: grid.isComplete() ? State.Satisfied : State.Incomplete };
117
+ }
118
+ copyWith({ pattern }) {
119
+ return new BanPatternRule(pattern ?? this.pattern);
120
+ }
121
+ withPattern(pattern) {
122
+ return this.copyWith({ pattern });
123
+ }
124
+ }
125
+ export const instance = new BanPatternRule(GridData.create([]));
@@ -0,0 +1,23 @@
1
+ import GridData from '../grid.js';
2
+ import { Color, Position } from '../primitives.js';
3
+ import Rule from './rule.js';
4
+ export interface Zone {
5
+ positions: Position[];
6
+ completed: number;
7
+ possible: number;
8
+ }
9
+ export type ZoneCounts = {
10
+ zones: Zone[];
11
+ complete: boolean;
12
+ };
13
+ export default abstract class CellCountPerZoneRule extends Rule {
14
+ readonly color: Color;
15
+ get configExplanation(): string;
16
+ /**
17
+ * @param color - The color of the cells to count.
18
+ */
19
+ constructor(color: Color);
20
+ protected getZoneCounts(grid: GridData): ZoneCounts;
21
+ withColor(color: Color): this;
22
+ }
23
+ export declare const instance: undefined;
@@ -0,0 +1,39 @@
1
+ import { Color } from '../primitives.js';
2
+ import Rule from './rule.js';
3
+ export default class CellCountPerZoneRule extends Rule {
4
+ color;
5
+ get configExplanation() {
6
+ return 'Use the zone tool to define areas on the grid.';
7
+ }
8
+ /**
9
+ * @param color - The color of the cells to count.
10
+ */
11
+ constructor(color) {
12
+ super();
13
+ this.color = color;
14
+ this.color = color;
15
+ }
16
+ getZoneCounts(grid) {
17
+ let complete = true;
18
+ const zones = grid.reduceByZone((zone, tile, x, y) => {
19
+ zone.positions.push({ x, y });
20
+ if (tile.color === this.color) {
21
+ zone.completed++;
22
+ }
23
+ else if (tile.color === Color.Gray) {
24
+ zone.possible++;
25
+ complete = false;
26
+ }
27
+ return zone;
28
+ }, () => ({
29
+ positions: [],
30
+ completed: 0,
31
+ possible: 0,
32
+ }));
33
+ return { zones, complete };
34
+ }
35
+ withColor(color) {
36
+ return this.copyWith({ color });
37
+ }
38
+ }
39
+ export const instance = undefined;
@@ -0,0 +1,33 @@
1
+ import { AnyConfig } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import { Color, RuleState } from '../primitives.js';
4
+ import Rule, { SearchVariant } from './rule.js';
5
+ export default class CellCountRule extends Rule {
6
+ readonly color: Color;
7
+ readonly count: number;
8
+ readonly title = "Total Count";
9
+ private static readonly CONFIGS;
10
+ private static readonly EXAMPLE_GRID_LIGHT;
11
+ private static readonly EXAMPLE_GRID_DARK;
12
+ private static readonly SEARCH_VARIANTS;
13
+ /**
14
+ * **There are &lt;count&gt; &lt;color&gt; cells in total**
15
+ *
16
+ * @param color - The color of the cells to count.
17
+ * @param count - The total number of cells of the given color.
18
+ */
19
+ constructor(color: Color, count: number);
20
+ get id(): string;
21
+ get explanation(): string;
22
+ get configs(): readonly AnyConfig[] | null;
23
+ createExampleGrid(): GridData;
24
+ get searchVariants(): SearchVariant[];
25
+ validateGrid(grid: GridData): RuleState;
26
+ copyWith({ color, count }: {
27
+ color?: Color;
28
+ count?: number;
29
+ }): this;
30
+ withColor(color: Color): this;
31
+ withCount(count: number): this;
32
+ }
33
+ export declare const instance: CellCountRule;