@logic-pad/core 0.1.4 → 0.1.6
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.
- package/assets/logic-core.global.d.ts +1 -2
- package/dist/data/solver/backtrack/backtrackWorker.js +6 -7
- package/dist/data/solver/backtrack/rules/banPattern.d.ts +1 -1
- package/dist/data/solver/backtrack/rules/banPattern.js +18 -2
- package/dist/data/solver/backtrack/symbols/dart.d.ts +0 -1
- package/dist/data/solver/backtrack/symbols/dart.js +1 -9
- package/dist/data/solver/underclued/undercluedSolver.js +2 -2
- package/dist/data/solver/underclued/undercluedWorker.js +28 -24
- package/package.json +1 -1
|
@@ -1801,7 +1801,7 @@ declare global {
|
|
|
1801
1801
|
export declare class BanPatternBTModule extends BTModule {
|
|
1802
1802
|
instr: BanPatternRule;
|
|
1803
1803
|
constructor(instr: BanPatternRule);
|
|
1804
|
-
checkGlobal(
|
|
1804
|
+
checkGlobal(grid: BTGridData): CheckResult | false;
|
|
1805
1805
|
checkLocal(grid: BTGridData, positions: Position$1[]): CheckResult | false;
|
|
1806
1806
|
}
|
|
1807
1807
|
export declare class CellCountBTModule extends BTModule {
|
|
@@ -1939,7 +1939,6 @@ declare global {
|
|
|
1939
1939
|
}
|
|
1940
1940
|
export declare class DartBTModule extends BTModule {
|
|
1941
1941
|
instr: DartSymbol;
|
|
1942
|
-
private cachedCheckResult?;
|
|
1943
1942
|
constructor(instr: DartSymbol);
|
|
1944
1943
|
checkGlobal(grid: BTGridData): CheckResult | false;
|
|
1945
1944
|
private buildCheckAndRating;
|
|
@@ -218,13 +218,13 @@ function solveNormal(input, solutionFn) {
|
|
|
218
218
|
}
|
|
219
219
|
function solveUnderclued(input) {
|
|
220
220
|
let grid = input;
|
|
221
|
-
let count = 0;
|
|
221
|
+
// let count = 0;
|
|
222
222
|
const possibles = array(grid.width, grid.height, () => ({
|
|
223
223
|
dark: false,
|
|
224
224
|
light: false,
|
|
225
225
|
}));
|
|
226
226
|
function search(x, y, tile, color) {
|
|
227
|
-
count++;
|
|
227
|
+
// count++;
|
|
228
228
|
// console.log(`Trying (${x}, ${y}) with ${color}`);
|
|
229
229
|
const newGrid = grid.setTile(x, y, tile.withColor(color));
|
|
230
230
|
// Solve
|
|
@@ -263,7 +263,7 @@ function solveUnderclued(input) {
|
|
|
263
263
|
grid = grid.setTile(x, y, tile.withColor(Color.Light));
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
|
-
console.log(`Solve count: ${count}`);
|
|
266
|
+
// console.log(`Solve count: ${count}`);
|
|
267
267
|
return grid;
|
|
268
268
|
}
|
|
269
269
|
function solve(grid, solutionFn) {
|
|
@@ -278,16 +278,15 @@ function solve(grid, solutionFn) {
|
|
|
278
278
|
}
|
|
279
279
|
onmessage = e => {
|
|
280
280
|
const grid = Serializer.parseGrid(e.data);
|
|
281
|
-
console.time('Solve time');
|
|
281
|
+
// console.time('Solve time');
|
|
282
282
|
let count = 0;
|
|
283
283
|
solve(grid, solution => {
|
|
284
|
-
if (count === 0)
|
|
285
|
-
console.timeLog('Solve time', 'First solution');
|
|
284
|
+
// if (count === 0) console.timeLog('Solve time', 'First solution');
|
|
286
285
|
postMessage(Serializer.stringifyGrid(solution));
|
|
287
286
|
count += 1;
|
|
288
287
|
return count < 2;
|
|
289
288
|
});
|
|
290
|
-
console.timeEnd('Solve time');
|
|
289
|
+
// console.timeEnd('Solve time');
|
|
291
290
|
postMessage(null);
|
|
292
291
|
};
|
|
293
292
|
// make typescript happy
|
|
@@ -4,6 +4,6 @@ import BTModule, { BTGridData, CheckResult } from '../data.js';
|
|
|
4
4
|
export default class BanPatternBTModule extends BTModule {
|
|
5
5
|
instr: BanPatternRule;
|
|
6
6
|
constructor(instr: BanPatternRule);
|
|
7
|
-
checkGlobal(
|
|
7
|
+
checkGlobal(grid: BTGridData): CheckResult | false;
|
|
8
8
|
checkLocal(grid: BTGridData, positions: Position[]): CheckResult | false;
|
|
9
9
|
}
|
|
@@ -10,8 +10,24 @@ export default class BanPatternBTModule extends BTModule {
|
|
|
10
10
|
});
|
|
11
11
|
this.instr = instr;
|
|
12
12
|
}
|
|
13
|
-
checkGlobal(
|
|
14
|
-
|
|
13
|
+
checkGlobal(grid) {
|
|
14
|
+
for (const pattern of this.instr.cache) {
|
|
15
|
+
for (let y = 0; y <= grid.height - pattern.height; y++) {
|
|
16
|
+
for (let x = 0; x <= grid.width - pattern.width; x++) {
|
|
17
|
+
let match = true;
|
|
18
|
+
for (const tile of pattern.elements) {
|
|
19
|
+
const t = grid.getTile(x + tile.x, y + tile.y);
|
|
20
|
+
if (t !== colorToBTTile(tile.color)) {
|
|
21
|
+
match = false;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (match) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
15
31
|
return { tilesNeedCheck: null, ratings: null };
|
|
16
32
|
}
|
|
17
33
|
checkLocal(grid, positions) {
|
|
@@ -2,7 +2,6 @@ import DartSymbol from '../../../symbols/dartSymbol.js';
|
|
|
2
2
|
import BTModule, { BTGridData, CheckResult } from '../data.js';
|
|
3
3
|
export default class DartBTModule extends BTModule {
|
|
4
4
|
instr: DartSymbol;
|
|
5
|
-
private cachedCheckResult?;
|
|
6
5
|
constructor(instr: DartSymbol);
|
|
7
6
|
checkGlobal(grid: BTGridData): CheckResult | false;
|
|
8
7
|
private buildCheckAndRating;
|
|
@@ -9,12 +9,6 @@ export default class DartBTModule extends BTModule {
|
|
|
9
9
|
writable: true,
|
|
10
10
|
value: void 0
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(this, "cachedCheckResult", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
12
|
this.instr = instr;
|
|
19
13
|
}
|
|
20
14
|
checkGlobal(grid) {
|
|
@@ -38,9 +32,7 @@ export default class DartBTModule extends BTModule {
|
|
|
38
32
|
}
|
|
39
33
|
if (completed + empty < this.instr.number)
|
|
40
34
|
return false;
|
|
41
|
-
|
|
42
|
-
this.cachedCheckResult = this.buildCheckAndRating(grid);
|
|
43
|
-
return this.cachedCheckResult;
|
|
35
|
+
return this.buildCheckAndRating(grid);
|
|
44
36
|
}
|
|
45
37
|
buildCheckAndRating(grid) {
|
|
46
38
|
const tilesNeedCheck = IntArray2D.create(grid.width, grid.height);
|
|
@@ -26,14 +26,14 @@ export default class UndercluedSolver extends Solver {
|
|
|
26
26
|
const solved = await new Promise(resolve => {
|
|
27
27
|
worker.addEventListener('message', e => {
|
|
28
28
|
const solution = Serializer.parseGrid(e.data);
|
|
29
|
-
console.timeEnd('Solve time');
|
|
29
|
+
// console.timeEnd('Solve time');
|
|
30
30
|
if (solution.resetTiles().equals(solution))
|
|
31
31
|
resolve(null);
|
|
32
32
|
else
|
|
33
33
|
resolve(solution);
|
|
34
34
|
});
|
|
35
35
|
worker.postMessage(Serializer.stringifyGrid(grid));
|
|
36
|
-
console.time('Solve time');
|
|
36
|
+
// console.time('Solve time');
|
|
37
37
|
});
|
|
38
38
|
yield solved;
|
|
39
39
|
if (solved) {
|
|
@@ -70,18 +70,20 @@ function computeSolution(initialGrid) {
|
|
|
70
70
|
let anyNewGrid;
|
|
71
71
|
while (assumptions.length > 0 || lastValidGrid.length === 0) {
|
|
72
72
|
[currentGrid, assumptions, anyNewGrid] = getValidGrid(currentGrid, assumptions, canAssump);
|
|
73
|
-
console.log(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
// console.log(
|
|
74
|
+
// currentGrid.tiles
|
|
75
|
+
// .map(row =>
|
|
76
|
+
// row
|
|
77
|
+
// .map(t => {
|
|
78
|
+
// const color = t.color === Color.Light ? 'w' : 'b';
|
|
79
|
+
// if (t.color === Color.Gray) return 'n';
|
|
80
|
+
// if (!t.exists) return '.';
|
|
81
|
+
// return t.fixed ? color.toUpperCase() : color;
|
|
82
|
+
// })
|
|
83
|
+
// .join('')
|
|
84
|
+
// )
|
|
85
|
+
// .join('\n')
|
|
86
|
+
// );
|
|
85
87
|
if (!anyNewGrid) {
|
|
86
88
|
break;
|
|
87
89
|
}
|
|
@@ -105,18 +107,20 @@ function computeSolution(initialGrid) {
|
|
|
105
107
|
const coords = posToCoords(i, solutionGrid.width);
|
|
106
108
|
solutionGrid = solutionGrid.setTile(coords[0], coords[1], tile => tile.withColor(color));
|
|
107
109
|
});
|
|
108
|
-
console.log(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
// console.log(
|
|
111
|
+
// solutionGrid.tiles
|
|
112
|
+
// .map(row =>
|
|
113
|
+
// row
|
|
114
|
+
// .map(t => {
|
|
115
|
+
// const color = t.color === Color.Light ? 'w' : 'b';
|
|
116
|
+
// if (t.color === Color.Gray) return 'n';
|
|
117
|
+
// if (!t.exists) return '.';
|
|
118
|
+
// return t.fixed ? color.toUpperCase() : color;
|
|
119
|
+
// })
|
|
120
|
+
// .join('')
|
|
121
|
+
// )
|
|
122
|
+
// .join('\n')
|
|
123
|
+
// );
|
|
120
124
|
return solutionGrid;
|
|
121
125
|
}
|
|
122
126
|
onmessage = e => {
|