wordulator 1.0.0 → 1.0.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/ReadMe.md +3 -6
- package/main.js +9 -7
- package/package.json +8 -4
- package/{run → scripts}/install.bash +0 -4
- package/scripts/postinstall.js +82 -0
- package/src/pre/feedback_matrix.js +2 -1
- package/src/pre/filter_words.js +1 -1
- package/src/pre/test.js +3 -3
- package/src/solvers/combined.js +10 -7
- /package/{run → scripts}/benchmark.bash +0 -0
- /package/{run → scripts}/solutions.txt +0 -0
- /package/{run → scripts}/wordle.txt +0 -0
package/ReadMe.md
CHANGED
|
@@ -14,18 +14,15 @@ or optimal. It was however an interesting dive into entropy, bitwise optimisatio
|
|
|
14
14
|
and implementing the Wordle ruleset!
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
|
-
-
|
|
18
|
-
- Navigate to `./` in terminal
|
|
19
|
-
- Run `npm run install-wordulator` - and wait to finish
|
|
17
|
+
- Run `npm install -g wordulator` - and wait to finish
|
|
20
18
|
- Installs base Wordle solutions and guesses
|
|
21
19
|
- Precomputes feedback matrix - This step might take a while
|
|
22
20
|
- Creates 5000 benchmark test cases from the solution list
|
|
23
21
|
- All Done
|
|
24
22
|
|
|
25
23
|
### Usage
|
|
26
|
-
- Run in **user** mode using `
|
|
27
|
-
- Run a standard **benchmark** using `
|
|
28
|
-
- Run a custom **benchmark** using `node . combo bench (# of tests)`
|
|
24
|
+
- Run in **user** mode using `wordulator`
|
|
25
|
+
- Run a standard **benchmark** using `wordulator bench (# of tests)`
|
|
29
26
|
- Enjoy
|
|
30
27
|
|
|
31
28
|
### Example Usage
|
package/main.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// NodeJS Imports
|
|
4
|
+
const path = require('path');
|
|
5
5
|
|
|
6
|
-
let
|
|
7
|
-
let
|
|
6
|
+
let { solve : combinedSolver } = require(path.join(__dirname, 'src/solvers/combined.js'));
|
|
7
|
+
let { randomInt } = require(path.join(__dirname, 'src/lib/lib.js'))
|
|
8
|
+
|
|
9
|
+
let words = require(path.join(__dirname, 'data/filter/words.json'));
|
|
10
|
+
let test_data = require(path.join(__dirname, 'data/test/tests.json'))
|
|
8
11
|
|
|
9
12
|
main();
|
|
10
13
|
async function main() {
|
|
@@ -16,8 +19,8 @@ async function main() {
|
|
|
16
19
|
let solve = combinedSolver;
|
|
17
20
|
|
|
18
21
|
switch (type) {
|
|
19
|
-
case 'bench' : await benchmark(solve, num, test_data, console.log);
|
|
20
|
-
case 'benchmark' : await benchmark(solve, num, test_data, console.log);
|
|
22
|
+
case 'bench' : await benchmark(solve, num, test_data, console.log); break;
|
|
23
|
+
case 'benchmark' : await benchmark(solve, num, test_data, console.log); break;
|
|
21
24
|
case 'user' : await solve({ type: "user", rand: true, log: console.log }); break;
|
|
22
25
|
default: throw `Invalid Mode Selected ${type}`
|
|
23
26
|
}
|
|
@@ -80,5 +83,4 @@ async function benchmark(solve, benchmark_num = 100, tests, log) {
|
|
|
80
83
|
log(`\t${i+1} guesses - ${no_of_guesses[i]}`);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
|
-
|
|
84
86
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wordulator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "An Entropy Based Wordle Solver",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wordle",
|
|
7
|
+
"entropy"
|
|
8
|
+
],
|
|
6
9
|
"license": "MIT",
|
|
7
10
|
"author": "Arlo Filley",
|
|
8
11
|
"repository": {
|
|
@@ -12,13 +15,14 @@
|
|
|
12
15
|
"type": "commonjs",
|
|
13
16
|
"main": "main.js",
|
|
14
17
|
"bin": {
|
|
15
|
-
"wordulator": "
|
|
18
|
+
"wordulator": "main.js"
|
|
16
19
|
},
|
|
17
20
|
"scripts": {
|
|
18
21
|
"test": "echo \"What the hell is a test???? YALL TESTING UR CODE??? GETTOUTAHEER!!!\" && exit 1",
|
|
19
22
|
"install-wordulator": "chmod u+x run/install.bash && run/install.bash && chmod u+x run/benchmark.bash",
|
|
20
23
|
"benchmark": "run/benchmark.bash",
|
|
21
|
-
"bench": "run/benchmark.bash"
|
|
24
|
+
"bench": "run/benchmark.bash",
|
|
25
|
+
"postinstall": "scripts/postinstall.js"
|
|
22
26
|
},
|
|
23
27
|
"dependencies": {
|
|
24
28
|
"@luminati-io/mmap-io": "^1.1.7-lum.6",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawnSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
function sleep(ms) {
|
|
8
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Helper to create directories safely
|
|
12
|
+
function mkdirSafe(dirPath) {
|
|
13
|
+
if (!fs.existsSync(dirPath)) {
|
|
14
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
15
|
+
console.log(`Created ${dirPath}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function copyFile(projectRoot, src, dest) {
|
|
20
|
+
fs.copyFileSync(path.join(projectRoot, src), path.join(projectRoot, dest));
|
|
21
|
+
console.log(`Copied ./${src} -> ./${dest}`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function runNodeScript(script, args) {
|
|
25
|
+
const result = spawnSync('node', [script, ...args], { stdio: 'inherit' });
|
|
26
|
+
if (result.error) {
|
|
27
|
+
console.error(`Failed to run ${script}:`, result.error);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
if (result.status !== 0) {
|
|
31
|
+
console.error(`${script} exited with code ${result.status}`);
|
|
32
|
+
process.exit(result.status);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
const projectRoot = path.join(__dirname, '..');
|
|
38
|
+
|
|
39
|
+
// Create Directory Structure
|
|
40
|
+
const dirs = ['data', 'data/filter', 'data/proc', 'data/raw', 'data/test', 'bench']
|
|
41
|
+
console.log("Creating Directory Structure");
|
|
42
|
+
for (const dir of dirs) {
|
|
43
|
+
mkdirSafe(path.join(projectRoot, dir))
|
|
44
|
+
await sleep(200);
|
|
45
|
+
}
|
|
46
|
+
console.log('---|---|---|---|---\n')
|
|
47
|
+
|
|
48
|
+
// Copy files
|
|
49
|
+
console.log("Copying Files Into Correct Places");
|
|
50
|
+
|
|
51
|
+
copyFile(projectRoot, 'scripts/wordle.txt', 'data/raw/wordle.txt');
|
|
52
|
+
await sleep(200);
|
|
53
|
+
|
|
54
|
+
copyFile(projectRoot, 'scripts/solutions.txt', 'data/raw/solutions.txt');
|
|
55
|
+
await sleep(200);
|
|
56
|
+
console.log('---|---|---|---|---\n');
|
|
57
|
+
|
|
58
|
+
// Filtering Lists for Valid Words
|
|
59
|
+
console.log("Filtering List For Valid Words");
|
|
60
|
+
runNodeScript('src/pre/filter_words.js', ['data/raw/wordle.txt', 'data/filter/words.json', '5']);
|
|
61
|
+
runNodeScript('src/pre/filter_words.js', ['data/raw/solutions.txt', 'data/filter/solutions.json', '5']);
|
|
62
|
+
console.log('---|---|---|---|---\n');
|
|
63
|
+
|
|
64
|
+
// Generate feedback matrix
|
|
65
|
+
console.log("Generating Feedback Matrix");
|
|
66
|
+
console.log("This Step Might Take a While");
|
|
67
|
+
console.log("The Feedback Matrix Can Be Found at data/proc/feedback_matrix.bin. It Takes Up Roughly 200mb For 12k Words");
|
|
68
|
+
runNodeScript('src/pre/feedback_matrix.js', ['data/filter/words.json', 'data/proc/feedback_matrix.bin']);
|
|
69
|
+
console.log('---|---|---|---|---\n');
|
|
70
|
+
|
|
71
|
+
// Generate Benchmark Tests
|
|
72
|
+
console.log("Generating Benchmark Tests");
|
|
73
|
+
runNodeScript('src/pre/test.js', ['data/filter/solutions.json', 'data/test/tests.json', '5000']);
|
|
74
|
+
console.log('---|---|---|---|---\n');
|
|
75
|
+
|
|
76
|
+
console.log("Everything installed correctly :>");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main().catch(err => {
|
|
80
|
+
console.error('Postinstall failed:', err);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** Precomputes a frequency matrix for a given set of words */
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const path = require('path')
|
|
3
4
|
|
|
4
|
-
const { entropyFeedback } = require('../lib/entropy.js');
|
|
5
|
+
const { entropyFeedback } = require(path.join(__dirname, '../lib/entropy.js'));
|
|
5
6
|
|
|
6
7
|
try {
|
|
7
8
|
const args = process.argv.slice(2);
|
package/src/pre/filter_words.js
CHANGED
package/src/pre/test.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Precomuputes Frequencies of Letters in Words */
|
|
2
|
-
const fs = require('
|
|
3
|
-
|
|
4
|
-
const { randomInt } = require('../lib/lib.js')
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
5
4
|
|
|
5
|
+
const { randomInt } = require(path.join(__dirname, '../lib/lib.js'));
|
|
6
6
|
|
|
7
7
|
try {
|
|
8
8
|
const args = process.argv.slice(2);
|
package/src/solvers/combined.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
// NodeJS Imports
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
1
4
|
// Lib Imports
|
|
2
|
-
const { calculatePosFreq, pfHeuristicScore: posFreqScore, createOverlap, overlapScore } = require('../lib/heuristic.js');
|
|
3
|
-
const { calculateGuessEntropy: entropy_score, genEntropyTable, loadFeedbackMatrix }
|
|
4
|
-
const { ask, normalise } = require('../lib/lib.js');
|
|
5
|
-
const { Wordle, patternFromUserInput } = require('../lib/wordle.js')
|
|
5
|
+
const { calculatePosFreq, pfHeuristicScore: posFreqScore, createOverlap, overlapScore } = require(path.join(__dirname, '../lib/heuristic.js'));
|
|
6
|
+
const { calculateGuessEntropy: entropy_score, genEntropyTable, loadFeedbackMatrix } = require(path.join(__dirname, '../lib/entropy.js'));
|
|
7
|
+
const { ask, normalise } = require(path.join(__dirname, '../lib/lib.js'));
|
|
8
|
+
const { Wordle, patternFromUserInput } = require(path.join(__dirname, '../lib/wordle.js'));
|
|
6
9
|
|
|
7
10
|
// Load Required Data
|
|
8
|
-
const words = require('../../data/filter/words.json');
|
|
9
|
-
const answers = require('../../data/filter/solutions.json');
|
|
10
|
-
const feedback_matrix = loadFeedbackMatrix('
|
|
11
|
+
const words = require(path.join(__dirname, '../../data/filter/words.json'));
|
|
12
|
+
const answers = require(path.join(__dirname, '../../data/filter/solutions.json'));
|
|
13
|
+
const feedback_matrix = loadFeedbackMatrix(path.join(__dirname, '../../data/proc/feedback_matrix.bin'));
|
|
11
14
|
const word_index = new Map();
|
|
12
15
|
words.forEach((w, i) => word_index.set(w, i));
|
|
13
16
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|