@logic-pad/core 0.26.1 → 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.
- package/README.md +31 -31
- package/assets/logic-core.global.d.ts +2 -0
- package/dist/benchmark/prepareBench.js +19 -19
- package/dist/benchmark/runBench.js +21 -21
- package/dist/src/data/serializer/allSerializers.d.ts +3 -0
- package/dist/src/data/serializer/allSerializers.js +7 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# @logic-pad/core
|
|
2
|
-
|
|
3
|
-
The core API of Logic Pad.
|
|
4
|
-
|
|
5
|
-
## Developing Logic Core
|
|
6
|
-
|
|
7
|
-
This package is part of Logic Pad. [Bun >=v1.1.0](https://bun.sh/) is required for this package.
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# 1. Clone this repository
|
|
11
|
-
git clone https://github.com/logic-pad/logic-pad.git
|
|
12
|
-
|
|
13
|
-
# 2. Restore dependencies
|
|
14
|
-
cd logic-pad
|
|
15
|
-
bun install
|
|
16
|
-
cd packages/logic-core
|
|
17
|
-
bun install
|
|
18
|
-
|
|
19
|
-
# 3. Build the library
|
|
20
|
-
bun build
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
To test your changes in realtime in Logic Pad, simply run Logic Pad using the Vite dev server.
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
# In the logic-pad directory
|
|
27
|
-
bun run dev
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Note that Logic Pad bundles the `src` directory of this package directly with Vite instead of using the transpiled
|
|
31
|
-
code in the `dist` output folder, which is for publishing only.
|
|
1
|
+
# @logic-pad/core
|
|
2
|
+
|
|
3
|
+
The core API of Logic Pad.
|
|
4
|
+
|
|
5
|
+
## Developing Logic Core
|
|
6
|
+
|
|
7
|
+
This package is part of Logic Pad. [Bun >=v1.1.0](https://bun.sh/) is required for this package.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 1. Clone this repository
|
|
11
|
+
git clone https://github.com/logic-pad/logic-pad.git
|
|
12
|
+
|
|
13
|
+
# 2. Restore dependencies
|
|
14
|
+
cd logic-pad
|
|
15
|
+
bun install
|
|
16
|
+
cd packages/logic-core
|
|
17
|
+
bun install
|
|
18
|
+
|
|
19
|
+
# 3. Build the library
|
|
20
|
+
bun build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To test your changes in realtime in Logic Pad, simply run Logic Pad using the Vite dev server.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# In the logic-pad directory
|
|
27
|
+
bun run dev
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Note that Logic Pad bundles the `src` directory of this package directly with Vite instead of using the transpiled
|
|
31
|
+
code in the `dist` output folder, which is for publishing only.
|
|
@@ -2163,6 +2163,8 @@ declare global {
|
|
|
2163
2163
|
* It uses the default serializer when stringifying puzzles, and select the correct deserializer when parsing puzzles.
|
|
2164
2164
|
*/
|
|
2165
2165
|
export declare const Serializer: {
|
|
2166
|
+
stringifyTiles(tiles: readonly (readonly TileData[])[]): string;
|
|
2167
|
+
parseTiles(input: string): TileData[][];
|
|
2166
2168
|
stringifyRule(rule: Rule): string;
|
|
2167
2169
|
parseRule(input: string): Rule;
|
|
2168
2170
|
stringifySymbol(symbol: Symbol$1): string;
|
|
@@ -31,18 +31,18 @@ const { values, positionals } = parseArgs({
|
|
|
31
31
|
});
|
|
32
32
|
positionals.splice(0, 2); // Remove "bun" and script name
|
|
33
33
|
if (values.help || positionals.length !== 1) {
|
|
34
|
-
console.log(`
|
|
35
|
-
Usage: bun bench:prepare <solver> [options]
|
|
36
|
-
|
|
37
|
-
Options:
|
|
38
|
-
-t, --maxTime <number> Maximum seconds allowed for each solve (default: 10)
|
|
39
|
-
-c, --maxCount <number> Maximum number of puzzles included (default: 100)
|
|
40
|
-
-n, --concurrency <number> Number of solves to run concurrently (default: 4)
|
|
41
|
-
-h, --help Show this help message
|
|
42
|
-
|
|
43
|
-
Solver:
|
|
44
|
-
Name of the solver to benchmark. Available solvers are:
|
|
45
|
-
${[...allSolvers.keys()].map(s => ` - ${s}`).join('\n')}
|
|
34
|
+
console.log(`
|
|
35
|
+
Usage: bun bench:prepare <solver> [options]
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
-t, --maxTime <number> Maximum seconds allowed for each solve (default: 10)
|
|
39
|
+
-c, --maxCount <number> Maximum number of puzzles included (default: 100)
|
|
40
|
+
-n, --concurrency <number> Number of solves to run concurrently (default: 4)
|
|
41
|
+
-h, --help Show this help message
|
|
42
|
+
|
|
43
|
+
Solver:
|
|
44
|
+
Name of the solver to benchmark. Available solvers are:
|
|
45
|
+
${[...allSolvers.keys()].map(s => ` - ${s}`).join('\n')}
|
|
46
46
|
`);
|
|
47
47
|
process.exit(0);
|
|
48
48
|
}
|
|
@@ -130,11 +130,11 @@ const selectedPuzzles = results.filter(r => r.result.solveCorrect && r.result.su
|
|
|
130
130
|
const benchmarkEntries = selectedPuzzles.map(r => r.result);
|
|
131
131
|
await Bun.write(`benchmark/data/bench_${solverName}_puzzles.json`, JSON.stringify(selectedPuzzles.map(r => r.puzzle), null, 2));
|
|
132
132
|
await Bun.write(`benchmark/data/bench_${solverName}_results.json`, JSON.stringify(benchmarkEntries, null, 2));
|
|
133
|
-
console.log(`
|
|
134
|
-
Benchmark preparation completed. Selected ${selectedPuzzles.length} puzzles.
|
|
135
|
-
|
|
136
|
-
- Solver: ${solverName} Max Time: ${maxTime}ms Max Count: ${maxCount}
|
|
137
|
-
- Average time: ${benchmarkEntries.filter(e => !Number.isNaN(e.solveTime)).reduce((a, b) => a + b.solveTime, 0) / benchmarkEntries.filter(e => !Number.isNaN(e.solveTime)).length}ms
|
|
138
|
-
- Number of timeouts: ${benchmarkEntries.filter(e => Number.isNaN(e.solveTime)).length}
|
|
139
|
-
- Solve correctness: ${benchmarkEntries.filter(e => e.solveCorrect).length} / ${benchmarkEntries.length}
|
|
133
|
+
console.log(`
|
|
134
|
+
Benchmark preparation completed. Selected ${selectedPuzzles.length} puzzles.
|
|
135
|
+
|
|
136
|
+
- Solver: ${solverName} Max Time: ${maxTime}ms Max Count: ${maxCount}
|
|
137
|
+
- Average time: ${benchmarkEntries.filter(e => !Number.isNaN(e.solveTime)).reduce((a, b) => a + b.solveTime, 0) / benchmarkEntries.filter(e => !Number.isNaN(e.solveTime)).length}ms
|
|
138
|
+
- Number of timeouts: ${benchmarkEntries.filter(e => Number.isNaN(e.solveTime)).length}
|
|
139
|
+
- Solve correctness: ${benchmarkEntries.filter(e => e.solveCorrect).length} / ${benchmarkEntries.length}
|
|
140
140
|
`);
|
|
@@ -30,17 +30,17 @@ const { values, positionals } = parseArgs({
|
|
|
30
30
|
});
|
|
31
31
|
positionals.splice(0, 2); // Remove "bun" and script name
|
|
32
32
|
if (values.help || positionals.length === 0) {
|
|
33
|
-
console.log(`
|
|
34
|
-
Usage: bun bench:run <solver> [options]
|
|
35
|
-
|
|
36
|
-
Options:
|
|
37
|
-
-t, --maxTime <number> Maximum seconds allowed for each solve (default: 10)
|
|
38
|
-
-c, --maxCount <number> Maximum number of puzzles included (default: 100)
|
|
39
|
-
-n, --concurrency <number> Number of solves to run concurrently (default: 4)
|
|
40
|
-
-h, --help Show this help message
|
|
41
|
-
|
|
42
|
-
Solvers available for benchmarking:
|
|
43
|
-
${[...allSolvers.keys()].map(s => ` - ${s}`).join('\n')}
|
|
33
|
+
console.log(`
|
|
34
|
+
Usage: bun bench:run <solver> [options]
|
|
35
|
+
|
|
36
|
+
Options:
|
|
37
|
+
-t, --maxTime <number> Maximum seconds allowed for each solve (default: 10)
|
|
38
|
+
-c, --maxCount <number> Maximum number of puzzles included (default: 100)
|
|
39
|
+
-n, --concurrency <number> Number of solves to run concurrently (default: 4)
|
|
40
|
+
-h, --help Show this help message
|
|
41
|
+
|
|
42
|
+
Solvers available for benchmarking:
|
|
43
|
+
${[...allSolvers.keys()].map(s => ` - ${s}`).join('\n')}
|
|
44
44
|
`);
|
|
45
45
|
process.exit(0);
|
|
46
46
|
}
|
|
@@ -192,15 +192,15 @@ for (let j = 0; j < positionals.length; j++) {
|
|
|
192
192
|
}
|
|
193
193
|
console.log('\nBenchmark Results:');
|
|
194
194
|
for (const result of results) {
|
|
195
|
-
console.log(`
|
|
196
|
-
${result.solver}:
|
|
197
|
-
Fastest Solves: ${result.fastestCount}
|
|
198
|
-
Solve time:
|
|
199
|
-
P25: ${Number.isNaN(result.solve25) ? 'N/A' : `${result.solve25.toFixed(2)}ms`}
|
|
200
|
-
P50: ${Number.isNaN(result.solve50) ? 'N/A' : `${result.solve50.toFixed(2)}ms`}
|
|
201
|
-
P75: ${Number.isNaN(result.solve75) ? 'N/A' : `${result.solve75.toFixed(2)}ms`}
|
|
202
|
-
SD: ${Number.isNaN(result.solveSD) ? 'N/A' : `${result.solveSD.toFixed(2)}ms`}
|
|
203
|
-
Unsupported Puzzles: ${result.unsupportedCount}
|
|
204
|
-
Incorrect Solutions: ${result.incorrectCount}
|
|
195
|
+
console.log(`
|
|
196
|
+
${result.solver}:
|
|
197
|
+
Fastest Solves: ${result.fastestCount}
|
|
198
|
+
Solve time:
|
|
199
|
+
P25: ${Number.isNaN(result.solve25) ? 'N/A' : `${result.solve25.toFixed(2)}ms`}
|
|
200
|
+
P50: ${Number.isNaN(result.solve50) ? 'N/A' : `${result.solve50.toFixed(2)}ms`}
|
|
201
|
+
P75: ${Number.isNaN(result.solve75) ? 'N/A' : `${result.solve75.toFixed(2)}ms`}
|
|
202
|
+
SD: ${Number.isNaN(result.solveSD) ? 'N/A' : `${result.solveSD.toFixed(2)}ms`}
|
|
203
|
+
Unsupported Puzzles: ${result.unsupportedCount}
|
|
204
|
+
Incorrect Solutions: ${result.incorrectCount}
|
|
205
205
|
`);
|
|
206
206
|
}
|
|
@@ -2,12 +2,15 @@ import GridData from '../grid.js';
|
|
|
2
2
|
import { Puzzle, PuzzleData } from '../puzzle.js';
|
|
3
3
|
import Rule from '../rules/rule.js';
|
|
4
4
|
import Symbol from '../symbols/symbol.js';
|
|
5
|
+
import TileData from '../tile.js';
|
|
5
6
|
/**
|
|
6
7
|
* The master serializer for puzzles.
|
|
7
8
|
*
|
|
8
9
|
* It uses the default serializer when stringifying puzzles, and select the correct deserializer when parsing puzzles.
|
|
9
10
|
*/
|
|
10
11
|
declare const Serializer: {
|
|
12
|
+
stringifyTiles(tiles: readonly (readonly TileData[])[]): string;
|
|
13
|
+
parseTiles(input: string): TileData[][];
|
|
11
14
|
stringifyRule(rule: Rule): string;
|
|
12
15
|
parseRule(input: string): Rule;
|
|
13
16
|
stringifySymbol(symbol: Symbol): string;
|
|
@@ -22,6 +22,13 @@ function selectSerializer(input) {
|
|
|
22
22
|
* It uses the default serializer when stringifying puzzles, and select the correct deserializer when parsing puzzles.
|
|
23
23
|
*/
|
|
24
24
|
const Serializer = {
|
|
25
|
+
stringifyTiles(tiles) {
|
|
26
|
+
return `${defaultSerializer.version}_${defaultSerializer.stringifyTiles(tiles)}`;
|
|
27
|
+
},
|
|
28
|
+
parseTiles(input) {
|
|
29
|
+
const { serializer, data } = selectSerializer(input);
|
|
30
|
+
return serializer.parseTiles(data);
|
|
31
|
+
},
|
|
25
32
|
stringifyRule(rule) {
|
|
26
33
|
return `${defaultSerializer.version}_${defaultSerializer.stringifyRule(rule)}`;
|
|
27
34
|
},
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logic-pad/core",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"assets"
|
|
8
8
|
],
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
9
12
|
"homepage": "https://github.com/logic-pad/logic-pad",
|
|
10
13
|
"repository": {
|
|
11
14
|
"type": "git",
|