@logic-pad/core 0.9.0 → 0.10.1
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 +15 -2
- package/dist/data/solver/allSolvers.js +2 -0
- package/dist/data/solver/backtrack/backtrackSolver.d.ts +1 -1
- package/dist/data/solver/backtrack/backtrackSolver.js +2 -2
- package/dist/data/solver/cspuz/cspuzSolver.d.ts +12 -0
- package/dist/data/solver/cspuz/cspuzSolver.js +113 -0
- package/dist/data/solver/cspuz/cspuzWorker.d.ts +1 -0
- package/dist/data/solver/cspuz/cspuzWorker.js +44 -0
- package/dist/data/solver/cspuz/jsonify.d.ts +3 -0
- package/dist/data/solver/cspuz/jsonify.js +211 -0
- package/dist/data/solver/eventIteratingSolver.js +4 -1
- package/dist/data/solver/z3/z3Solver.d.ts +1 -1
- package/dist/data/solver/z3/z3Solver.js +1 -1
- package/dist/data/symbols/directionLinkerSymbol.js +20 -20
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ declare global {
|
|
|
9
9
|
// Generated by dts-bundle-generator v9.5.1
|
|
10
10
|
|
|
11
11
|
import { RegionConstrainer, SymbolGrid } from 'grilops';
|
|
12
|
+
import { PuzzleData } from 'logic-pad-solver-core';
|
|
12
13
|
import { Optimize, Solver as Solver$1, Z3LowLevel } from 'z3-solver';
|
|
13
14
|
import { z } from 'zod';
|
|
14
15
|
|
|
@@ -2120,7 +2121,7 @@ declare global {
|
|
|
2120
2121
|
readonly id = 'backtrack';
|
|
2121
2122
|
readonly author = 'ALaggyDev';
|
|
2122
2123
|
readonly description =
|
|
2123
|
-
'Solves puzzles using backtracking with optimizations
|
|
2124
|
+
'Solves puzzles pretty fast using backtracking with optimizations. Support most rules and symbols (including underclued).';
|
|
2124
2125
|
protected createWorker(): Worker;
|
|
2125
2126
|
isInstructionSupported(instructionId: string): boolean;
|
|
2126
2127
|
}
|
|
@@ -2629,6 +2630,18 @@ declare global {
|
|
|
2629
2630
|
constructor(instr: ViewpointSymbol);
|
|
2630
2631
|
checkGlobal(grid: BTGridData): CheckResult | false;
|
|
2631
2632
|
}
|
|
2633
|
+
export declare class CspuzSolver extends EventIteratingSolver {
|
|
2634
|
+
private static readonly supportedInstrs;
|
|
2635
|
+
readonly id = 'cspuz';
|
|
2636
|
+
readonly author = 'semiexp';
|
|
2637
|
+
readonly description =
|
|
2638
|
+
'A blazingly fast WebAssembly solver that supports most rules and symbols (including underclued). No uniqueness check yet.';
|
|
2639
|
+
protected createWorker(): Worker;
|
|
2640
|
+
isGridSupported(grid: GridData): boolean;
|
|
2641
|
+
isInstructionSupported(instructionId: string): boolean;
|
|
2642
|
+
isEnvironmentSupported(): Promise<boolean>;
|
|
2643
|
+
}
|
|
2644
|
+
export declare function gridToJson(grid: GridData): PuzzleData;
|
|
2632
2645
|
export declare class UniversalSolver extends EventIteratingSolver {
|
|
2633
2646
|
readonly id = 'universal';
|
|
2634
2647
|
readonly author = 'romain22222, Lysine';
|
|
@@ -2724,7 +2737,7 @@ declare global {
|
|
|
2724
2737
|
readonly id = 'z3';
|
|
2725
2738
|
readonly author = 'Lysine';
|
|
2726
2739
|
readonly description =
|
|
2727
|
-
'
|
|
2740
|
+
'(Obsolete) A WebAssembly solver that supports a limited set of rules and symbols.';
|
|
2728
2741
|
readonly supportsCancellation = false;
|
|
2729
2742
|
isEnvironmentSupported(): Promise<boolean>;
|
|
2730
2743
|
solve(grid: GridData): AsyncGenerator<GridData | null>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import UniversalSolver from './universal/universalSolver.js';
|
|
2
2
|
import BacktrackSolver from './backtrack/backtrackSolver.js';
|
|
3
3
|
import Z3Solver from './z3/z3Solver.js';
|
|
4
|
+
import CspuzSolver from './cspuz/cspuzSolver.js';
|
|
4
5
|
const allSolvers = new Map();
|
|
5
6
|
function register(prototype) {
|
|
6
7
|
allSolvers.set(prototype.id, prototype);
|
|
7
8
|
}
|
|
9
|
+
register(new CspuzSolver());
|
|
8
10
|
register(new BacktrackSolver());
|
|
9
11
|
register(new UniversalSolver());
|
|
10
12
|
register(new Z3Solver());
|
|
@@ -3,7 +3,7 @@ export default class BacktrackSolver extends EventIteratingSolver {
|
|
|
3
3
|
private static readonly supportedInstrs;
|
|
4
4
|
readonly id = "backtrack";
|
|
5
5
|
readonly author = "ALaggyDev";
|
|
6
|
-
readonly description = "Solves puzzles using backtracking with optimizations
|
|
6
|
+
readonly description = "Solves puzzles pretty fast using backtracking with optimizations. Support most rules and symbols (including underclued).";
|
|
7
7
|
protected createWorker(): Worker;
|
|
8
8
|
isInstructionSupported(instructionId: string): boolean;
|
|
9
9
|
}
|
|
@@ -14,7 +14,7 @@ import { instance as minesweeperInstance } from '../../symbols/minesweeperSymbol
|
|
|
14
14
|
import { instance as focusInstance } from '../../symbols/focusSymbol.js';
|
|
15
15
|
import { instance as myopiaInstance } from '../../symbols/myopiaSymbol.js';
|
|
16
16
|
import { instance as viewpointInstance } from '../../symbols/viewpointSymbol.js';
|
|
17
|
-
import { instance as connectAllInstance } from '
|
|
17
|
+
import { instance as connectAllInstance } from '../../rules/connectAllRule.js';
|
|
18
18
|
import EventIteratingSolver from '../eventIteratingSolver.js';
|
|
19
19
|
class BacktrackSolver extends EventIteratingSolver {
|
|
20
20
|
constructor() {
|
|
@@ -35,7 +35,7 @@ class BacktrackSolver extends EventIteratingSolver {
|
|
|
35
35
|
enumerable: true,
|
|
36
36
|
configurable: true,
|
|
37
37
|
writable: true,
|
|
38
|
-
value: 'Solves puzzles using backtracking with optimizations
|
|
38
|
+
value: 'Solves puzzles pretty fast using backtracking with optimizations. Support most rules and symbols (including underclued).'
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
createWorker() {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import EventIteratingSolver from '../eventIteratingSolver.js';
|
|
2
|
+
import GridData from '../../grid.js';
|
|
3
|
+
export default class CspuzSolver extends EventIteratingSolver {
|
|
4
|
+
private static readonly supportedInstrs;
|
|
5
|
+
readonly id = "cspuz";
|
|
6
|
+
readonly author = "semiexp";
|
|
7
|
+
readonly description = "A blazingly fast WebAssembly solver that supports most rules and symbols (including underclued). No uniqueness check yet.";
|
|
8
|
+
protected createWorker(): Worker;
|
|
9
|
+
isGridSupported(grid: GridData): boolean;
|
|
10
|
+
isInstructionSupported(instructionId: string): boolean;
|
|
11
|
+
isEnvironmentSupported(): Promise<boolean>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { 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 { 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
|
+
class CspuzSolver extends EventIteratingSolver {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
Object.defineProperty(this, "id", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: 'cspuz'
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "author", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: 'semiexp'
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "description", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: 'A blazingly fast WebAssembly solver that supports most rules and symbols (including underclued). No uniqueness check yet.'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
createWorker() {
|
|
43
|
+
return new Worker(new URL('./cspuzWorker.js', import.meta.url), {
|
|
44
|
+
type: 'module',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
isGridSupported(grid) {
|
|
48
|
+
if (!super.isGridSupported(grid)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// special handling for galaxies and lotuses since dual-color symbols are not supported yet
|
|
52
|
+
for (const [_, symbols] of grid.symbols) {
|
|
53
|
+
for (const symbol of symbols) {
|
|
54
|
+
if (symbol instanceof GalaxySymbol || symbol instanceof LotusSymbol) {
|
|
55
|
+
if (symbol.x % 1 !== 0 && symbol.y % 1 !== 0) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
else if (symbol.x % 1 !== 0 || symbol.y % 1 !== 0) {
|
|
59
|
+
const tile1 = grid.getTile(Math.floor(symbol.x), Math.floor(symbol.y));
|
|
60
|
+
const tile2 = grid.getTile(Math.ceil(symbol.x), Math.ceil(symbol.y));
|
|
61
|
+
if (!tile1.fixed || !tile2.fixed || tile1.color !== tile2.color) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// special handling for fixed gray tiles
|
|
69
|
+
if (grid.getTileCount(true, true, Color.Gray) > 0) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
isInstructionSupported(instructionId) {
|
|
75
|
+
return CspuzSolver.supportedInstrs.includes(instructionId);
|
|
76
|
+
}
|
|
77
|
+
async isEnvironmentSupported() {
|
|
78
|
+
try {
|
|
79
|
+
const abortController = new AbortController();
|
|
80
|
+
for await (const _ of this.solve(GridData.create(['.']), abortController.signal)) {
|
|
81
|
+
abortController.abort();
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
catch (ex) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
Object.defineProperty(CspuzSolver, "supportedInstrs", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: [
|
|
95
|
+
minesweeperInstance.id,
|
|
96
|
+
areaNumberInstance.id,
|
|
97
|
+
letterInstance.id,
|
|
98
|
+
dartInstance.id,
|
|
99
|
+
viewpointInstance.id,
|
|
100
|
+
lotusInstance.id,
|
|
101
|
+
galaxyInstance.id,
|
|
102
|
+
connectAllInstance.id,
|
|
103
|
+
banPatternInstance.id,
|
|
104
|
+
sameShapeInstance.id,
|
|
105
|
+
uniqueShapeInstance.id,
|
|
106
|
+
regionAreaInstance.id,
|
|
107
|
+
cellCountInstance.id,
|
|
108
|
+
offByXInstance.id,
|
|
109
|
+
undercluedInstance.id,
|
|
110
|
+
symbolsPerRegionInstance.id,
|
|
111
|
+
]
|
|
112
|
+
});
|
|
113
|
+
export default CspuzSolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
onmessage = e => {
|
|
18
|
+
const grid = Serializer.parseGrid(e.data);
|
|
19
|
+
const puzzleData = gridToJson(grid);
|
|
20
|
+
const solverResult = solveLogicPad(puzzleData, !!grid.findRule(r => r.id === undercluedInstance.id));
|
|
21
|
+
if (solverResult === null) {
|
|
22
|
+
postMessage(null);
|
|
23
|
+
}
|
|
24
|
+
else if ('error' in solverResult) {
|
|
25
|
+
throw new Error(solverResult.error);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const solution = grid.withTiles(tiles => {
|
|
29
|
+
for (const [y, row] of solverResult.entries()) {
|
|
30
|
+
for (const [x, color] of row.entries()) {
|
|
31
|
+
tiles[y][x] = tiles[y][x].withColor(stringToColor(color));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return tiles;
|
|
35
|
+
});
|
|
36
|
+
if (solution.resetTiles().colorEquals(solution)) {
|
|
37
|
+
postMessage(null);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
postMessage(Serializer.stringifyGrid(solution));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
postMessage(undefined);
|
|
44
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
}
|
|
@@ -22,6 +22,10 @@ export default class EventIteratingSolver extends Solver {
|
|
|
22
22
|
if (e.data) {
|
|
23
23
|
push(Serializer.parseGrid(e.data));
|
|
24
24
|
}
|
|
25
|
+
else if (e.data === null) {
|
|
26
|
+
push(null);
|
|
27
|
+
stop(); // Stop after the first signal for out of solutions
|
|
28
|
+
}
|
|
25
29
|
else {
|
|
26
30
|
stop();
|
|
27
31
|
}
|
|
@@ -34,7 +38,6 @@ export default class EventIteratingSolver extends Solver {
|
|
|
34
38
|
for await (const solution of iterator) {
|
|
35
39
|
yield solution;
|
|
36
40
|
}
|
|
37
|
-
yield null;
|
|
38
41
|
}
|
|
39
42
|
finally {
|
|
40
43
|
worker.terminate();
|
|
@@ -3,7 +3,7 @@ import Solver from '../solver.js';
|
|
|
3
3
|
export default class Z3Solver extends Solver {
|
|
4
4
|
readonly id = "z3";
|
|
5
5
|
readonly author = "Lysine";
|
|
6
|
-
readonly description = "
|
|
6
|
+
readonly description = "(Obsolete) A WebAssembly solver that supports a limited set of rules and symbols.";
|
|
7
7
|
readonly supportsCancellation = false;
|
|
8
8
|
isEnvironmentSupported(): Promise<boolean>;
|
|
9
9
|
solve(grid: GridData): AsyncGenerator<GridData | null>;
|
|
@@ -24,7 +24,7 @@ export default class Z3Solver extends Solver {
|
|
|
24
24
|
enumerable: true,
|
|
25
25
|
configurable: true,
|
|
26
26
|
writable: true,
|
|
27
|
-
value: '
|
|
27
|
+
value: '(Obsolete) A WebAssembly solver that supports a limited set of rules and symbols.'
|
|
28
28
|
});
|
|
29
29
|
Object.defineProperty(this, "supportsCancellation", {
|
|
30
30
|
enumerable: true,
|
|
@@ -153,29 +153,29 @@ class DirectionLinkerSymbol extends Symbol {
|
|
|
153
153
|
}
|
|
154
154
|
// 1x2
|
|
155
155
|
if (x % 1 === 0) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
y: y
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}, grid)
|
|
165
|
-
|
|
156
|
+
if (this.linkedDirections[Direction.Up] === Direction.Up &&
|
|
157
|
+
this.linkedDirections[Direction.Down] === Direction.Down) {
|
|
158
|
+
return [
|
|
159
|
+
makeTurtle({ x, y: y - 0.5 }, { x, y: y - 0.5 }, grid),
|
|
160
|
+
makeTurtle({ x, y: y + 0.5 }, { x, y: y + 0.5 }, grid),
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return [makeTurtle({ x, y: y - 0.5 }, { x, y: y + 0.5 }, grid)];
|
|
165
|
+
}
|
|
166
166
|
}
|
|
167
167
|
// 2x1
|
|
168
168
|
if (y % 1 === 0) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}, grid)
|
|
178
|
-
|
|
169
|
+
if (this.linkedDirections[Direction.Left] === Direction.Left &&
|
|
170
|
+
this.linkedDirections[Direction.Right] === Direction.Right) {
|
|
171
|
+
return [
|
|
172
|
+
makeTurtle({ x: x - 0.5, y }, { x: x - 0.5, y }, grid),
|
|
173
|
+
makeTurtle({ x: x + 0.5, y }, { x: x + 0.5, y }, grid),
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
return [makeTurtle({ x: x - 0.5, y }, { x: x + 0.5, y }, grid)];
|
|
178
|
+
}
|
|
179
179
|
}
|
|
180
180
|
// 2x2
|
|
181
181
|
if (this.linkedDirections[Direction.Left] === Direction.Left &&
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ import LotusBTModule from './data/solver/backtrack/symbols/lotus.js';
|
|
|
67
67
|
import MinesweeperBTModule from './data/solver/backtrack/symbols/minesweeper.js';
|
|
68
68
|
import MyopiaBTModule from './data/solver/backtrack/symbols/myopia.js';
|
|
69
69
|
import ViewpointBTModule from './data/solver/backtrack/symbols/viewpoint.js';
|
|
70
|
+
import CspuzSolver from './data/solver/cspuz/cspuzSolver.js';
|
|
71
|
+
import { gridToJson } from './data/solver/cspuz/jsonify.js';
|
|
70
72
|
import EventIteratingSolver from './data/solver/eventIteratingSolver.js';
|
|
71
73
|
import Solver from './data/solver/solver.js';
|
|
72
74
|
import UniversalSolver from './data/solver/universal/universalSolver.js';
|
|
@@ -104,4 +106,4 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
|
|
|
104
106
|
import TileData from './data/tile.js';
|
|
105
107
|
import TileConnections from './data/tileConnections.js';
|
|
106
108
|
import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
|
|
107
|
-
export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, shapeEquals, tilesToShape, allSolvers, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
|
|
109
|
+
export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, shapeEquals, tilesToShape, allSolvers, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,8 @@ import LotusBTModule from './data/solver/backtrack/symbols/lotus.js';
|
|
|
70
70
|
import MinesweeperBTModule from './data/solver/backtrack/symbols/minesweeper.js';
|
|
71
71
|
import MyopiaBTModule from './data/solver/backtrack/symbols/myopia.js';
|
|
72
72
|
import ViewpointBTModule from './data/solver/backtrack/symbols/viewpoint.js';
|
|
73
|
+
import CspuzSolver from './data/solver/cspuz/cspuzSolver.js';
|
|
74
|
+
import { gridToJson } from './data/solver/cspuz/jsonify.js';
|
|
73
75
|
import EventIteratingSolver from './data/solver/eventIteratingSolver.js';
|
|
74
76
|
import Solver from './data/solver/solver.js';
|
|
75
77
|
import UniversalSolver from './data/solver/universal/universalSolver.js';
|
|
@@ -107,4 +109,4 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
|
|
|
107
109
|
import TileData from './data/tile.js';
|
|
108
110
|
import TileConnections from './data/tileConnections.js';
|
|
109
111
|
import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
|
|
110
|
-
export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, shapeEquals, tilesToShape, allSolvers, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
|
|
112
|
+
export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerV0, getShapeVariants, normalizeShape, positionsToShape, shapeEquals, tilesToShape, allSolvers, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
|