Compare commits
2
Commits
main
..
531ac5af22
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
531ac5af22 | ||
|
|
30ba157d43 |
@@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
REGISTRY="${REGISTRY#https://}"
|
|
||||||
REGISTRY="${REGISTRY#http://}"
|
|
||||||
REGISTRY="${REGISTRY%/}"
|
|
||||||
|
|
||||||
IMAGE="${REGISTRY}/${REPOSITORY}:${TAG}"
|
|
||||||
|
|
||||||
echo "Pushing ${IMAGE}"
|
|
||||||
|
|
||||||
skopeo copy \
|
|
||||||
--dest-creds "${USERNAME}:${PASSWORD}" \
|
|
||||||
"docker-archive:result" \
|
|
||||||
"docker://${IMAGE}"
|
|
||||||
|
|
||||||
if [ "${REF_NAME:-}" = "main" ]; then
|
|
||||||
skopeo copy \
|
|
||||||
--dest-creds "${USERNAME}:${PASSWORD}" \
|
|
||||||
"docker-archive:result" \
|
|
||||||
"docker://${REGISTRY}/${REPOSITORY}:latest"
|
|
||||||
fi
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
name: Build docker images.
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-wordle-solver-image:
|
|
||||||
runs-on: nixos
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build wordle-solver image
|
|
||||||
run: |
|
|
||||||
nix build .#wordle-solver-docker
|
|
||||||
|
|
||||||
- name: Push image
|
|
||||||
env:
|
|
||||||
REGISTRY: "${{ gitea.server_url }}"
|
|
||||||
REPOSITORY: "${{ gitea.repository }}"
|
|
||||||
USERNAME: "${{ secrets.REGISTRY_USER }}"
|
|
||||||
PASSWORD: "${{ secrets.REGISTRY_TOKEN }}"
|
|
||||||
REF_NAME: "${{ gitea.ref_name }}"
|
|
||||||
TAG: "${{ gitea.sha }}"
|
|
||||||
run: bash .gitea/scripts/push-image.sh
|
|
||||||
|
|
||||||
build-wordle-solver-web-image:
|
|
||||||
runs-on: nixos
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build wordle-solver-web image
|
|
||||||
run: |
|
|
||||||
nix build .#wordle-solver-web-docker
|
|
||||||
|
|
||||||
- name: Push image
|
|
||||||
env:
|
|
||||||
REGISTRY: "${{ gitea.server_url }}"
|
|
||||||
REPOSITORY: "${{ gitea.repository }}-web"
|
|
||||||
USERNAME: "${{ secrets.REGISTRY_USER }}"
|
|
||||||
PASSWORD: "${{ secrets.REGISTRY_TOKEN }}"
|
|
||||||
REF_NAME: "${{ gitea.ref_name }}"
|
|
||||||
TAG: "${{ gitea.sha }}"
|
|
||||||
run: bash .gitea/scripts/push-image.sh
|
|
||||||
Generated
+79
-2
@@ -8,6 +8,12 @@ version = "0.5.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.20.3"
|
version = "3.20.3"
|
||||||
@@ -114,7 +120,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"syn",
|
"syn 2.0.119",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -199,6 +205,15 @@ version = "0.2.189"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.4"
|
version = "1.21.4"
|
||||||
@@ -278,6 +293,25 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rmp"
|
||||||
|
version = "0.8.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rmp-serde"
|
||||||
|
version = "1.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155"
|
||||||
|
dependencies = [
|
||||||
|
"rmp",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -299,6 +333,36 @@ version = "1.0.28"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.229"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_core"
|
||||||
|
version = "1.0.229"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.229"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 3.0.3",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.12"
|
version = "0.4.12"
|
||||||
@@ -325,6 +389,17 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "3.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tabular"
|
name = "tabular"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -430,7 +505,7 @@ dependencies = [
|
|||||||
"bumpalo",
|
"bumpalo",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.119",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -479,6 +554,8 @@ dependencies = [
|
|||||||
"js-sys",
|
"js-sys",
|
||||||
"rand",
|
"rand",
|
||||||
"rayon",
|
"rayon",
|
||||||
|
"rmp-serde",
|
||||||
|
"serde",
|
||||||
"tabular",
|
"tabular",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|||||||
+3
-1
@@ -27,9 +27,11 @@ indicatif = { version = "0.18.6", features = ["rayon"] }
|
|||||||
js-sys = { version = "0.3.104", optional = true }
|
js-sys = { version = "0.3.104", optional = true }
|
||||||
rand = "0.10.2"
|
rand = "0.10.2"
|
||||||
rayon = "1.12.0"
|
rayon = "1.12.0"
|
||||||
|
rmp-serde = { version = "1.3.1", optional = true }
|
||||||
|
serde = { version = "1.0.229", optional = true, features = ["derive"] }
|
||||||
tabular = { version = "0.2.0", features = ["ansi-cell"] }
|
tabular = { version = "0.2.0", features = ["ansi-cell"] }
|
||||||
wasm-bindgen = { version = "0.2.127", optional = true }
|
wasm-bindgen = { version = "0.2.127", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
wasm-bindgen = ["dep:wasm-bindgen", "getrandom/wasm_js", "dep:js-sys"]
|
wasm-bindgen = ["dep:wasm-bindgen", "getrandom/wasm_js", "dep:js-sys", "dep:serde", "dep:rmp-serde"]
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
# Wordle Solver
|
|
||||||
|
|
||||||
This wordle solver uses an information theory based approach to evaluate the next-best-guess. It's heavily inspired by [3b1b's approach](https://www.youtube.com/watch?v=v68zYyaEmEA) on solving wordle.
|
|
||||||
|
|
||||||
There are two ways to use the wordle-solver.
|
|
||||||
|
|
||||||
1. a CLI tool
|
|
||||||
2. a web interface
|
|
||||||
|
|
||||||
|
|
||||||
# Docker
|
|
||||||
|
|
||||||
#### CLI
|
|
||||||
```sh
|
|
||||||
docker run --rm -it git.jroeger.de/jonas/wordle-solver-rs
|
|
||||||
```
|
|
||||||
|
|
||||||
#### web
|
|
||||||
``` sh
|
|
||||||
docker run -p 8080:80 --rm -it git.jroeger.de/jonas/wordle-solver-rs-web
|
|
||||||
```
|
|
||||||
|
|
||||||
# Nix
|
|
||||||
|
|
||||||
#### CLI
|
|
||||||
|
|
||||||
``` sh
|
|
||||||
nix run .
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Static web site
|
|
||||||
|
|
||||||
``` sh
|
|
||||||
nix build git+http://git.jroeger.de/jonas/wordle-solver-rs#wordle-solver-web
|
|
||||||
```
|
|
||||||
|
|
||||||
# Native
|
|
||||||
|
|
||||||
#### CLI
|
|
||||||
|
|
||||||
you will need to have `cargo` installed.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cargo run --profile release
|
|
||||||
```
|
|
||||||
|
|
||||||
#### web
|
|
||||||
|
|
||||||
you need the following tools:
|
|
||||||
- `wasm-pack`
|
|
||||||
- `wasm-bindgen`
|
|
||||||
- `cargo`
|
|
||||||
- `nodejs`
|
|
||||||
- `yarn`
|
|
||||||
|
|
||||||
``` sh
|
|
||||||
cd web
|
|
||||||
yarn install
|
|
||||||
yarn serve # or yarn build
|
|
||||||
```
|
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
outputs = inputs @ {
|
outputs = inputs @ {
|
||||||
flake-parts,
|
flake-parts,
|
||||||
|
crate2nix,
|
||||||
rust-overlay,
|
rust-overlay,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@@ -27,24 +28,33 @@
|
|||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
];
|
];
|
||||||
|
|
||||||
imports = [
|
|
||||||
./nix/wasm-bindgen.nix
|
|
||||||
./nix/wordle-solver-docker.nix
|
|
||||||
./nix/wordle-solver-wasm-pkg.nix
|
|
||||||
./nix/wordle-solver-wasm.nix
|
|
||||||
./nix/wordle-solver-web-docker.nix
|
|
||||||
./nix/wordle-solver-web.nix
|
|
||||||
./nix/wordle-solver.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
perSystem = {
|
perSystem = {
|
||||||
pkgs,
|
pkgs,
|
||||||
system,
|
system,
|
||||||
self',
|
self',
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
utils = import ./nix/utils.nix;
|
# Use rust-bin to generate the toolchain from rust-toolchain.toml
|
||||||
rust-toolchain = utils.rust-toolchain pkgs;
|
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||||
|
|
||||||
|
cross-pkgs = pkgs.pkgsCross.wasm32-unknown-none;
|
||||||
|
|
||||||
|
toolchain = pkgs.callPackage ./nix/with-toolchain.nix {
|
||||||
|
cargo = rust-toolchain;
|
||||||
|
rustc = rust-toolchain;
|
||||||
|
};
|
||||||
|
crossToolchain = cross-pkgs.callPackage ./nix/with-toolchain.nix {
|
||||||
|
cargo = rust-toolchain;
|
||||||
|
rustc = rust-toolchain;
|
||||||
|
};
|
||||||
|
|
||||||
|
wasm-bindgen = toolchain.pkgs.callPackage ./nix/wasm-bindgen.nix {};
|
||||||
|
|
||||||
|
root-crate = pkgs.callPackage ./nix/root-crate.nix {
|
||||||
|
cargo = rust-toolchain;
|
||||||
|
rustc = rust-toolchain;
|
||||||
|
inherit crate2nix;
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
# Overlay pkgs with rust-bin
|
# Overlay pkgs with rust-bin
|
||||||
_module.args.pkgs = import inputs.nixpkgs {
|
_module.args.pkgs = import inputs.nixpkgs {
|
||||||
@@ -53,13 +63,22 @@
|
|||||||
config.allowUnsupportedSystem = true;
|
config.allowUnsupportedSystem = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
packages.default = self'.packages.wordle-solver;
|
packages = {
|
||||||
|
wordle-solver-web = pkgs.callPackage ./nix/wordle-solver-web.nix {inherit (self'.packages) wordle-solver-wasm-pkg;};
|
||||||
|
wordle-solver-wasm = crossToolchain.pkgs.callPackage ./nix/wordle-solver-wasm.nix {};
|
||||||
|
wordle-solver-wasm-pkg = pkgs.callPackage ./nix/wordle-solver-wasm-pkg.nix {
|
||||||
|
inherit wasm-bindgen root-crate;
|
||||||
|
inherit (self'.packages) wordle-solver-wasm;
|
||||||
|
};
|
||||||
|
wordle-solver = root-crate.build;
|
||||||
|
default = self'.packages.wordle-solver;
|
||||||
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
RA_LOG = "rust_analyzer=info";
|
RA_LOG = "rust_analyzer=info";
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
rust-toolchain
|
rust-toolchain
|
||||||
self'.packages.wasm-bindgen
|
wasm-bindgen
|
||||||
pkgs.nodejs
|
pkgs.nodejs
|
||||||
pkgs.svelte-language-server
|
pkgs.svelte-language-server
|
||||||
pkgs.typescript-language-server
|
pkgs.typescript-language-server
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
crate2nix,
|
||||||
|
rustc,
|
||||||
|
cargo,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
buildRustCrateForPkgs = _:
|
||||||
|
pkgs.buildRustCrate.override {
|
||||||
|
inherit cargo rustc;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Cargo.nix for IFD
|
||||||
|
generatedCargoNix = crate2nix.tools.${pkgs.hostPlatform.system}.generatedCargoNix {
|
||||||
|
name = "rustnix";
|
||||||
|
src = ../.;
|
||||||
|
};
|
||||||
|
|
||||||
|
cargoNix = import generatedCargoNix {
|
||||||
|
inherit pkgs buildRustCrateForPkgs;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
cargoNix.rootCrate
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
rec {
|
|
||||||
rust-toolchain = pkgs: pkgs.rust-bin.fromRustupToolchainFile ../rust-toolchain.toml;
|
|
||||||
|
|
||||||
toolchain-pkgs = pkgs:
|
|
||||||
pkgs.extend (_: _: {
|
|
||||||
rustPlatform = pkgs.makeRustPlatform {
|
|
||||||
cargo = rust-toolchain pkgs;
|
|
||||||
rustc = rust-toolchain pkgs;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
toolchain-crosspkgs = pkgs: let
|
|
||||||
crossPkgs = pkgs.pkgsCross.wasm32-unknown-none;
|
|
||||||
in
|
|
||||||
crossPkgs.extend (_: _: {
|
|
||||||
rustPlatform = crossPkgs.makeRustPlatform {
|
|
||||||
cargo = rust-toolchain pkgs;
|
|
||||||
rustc = rust-toolchain pkgs;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
+16
-24
@@ -1,27 +1,19 @@
|
|||||||
let
|
{
|
||||||
drv = {
|
fetchCrate,
|
||||||
fetchCrate,
|
buildWasmBindgenCli,
|
||||||
buildWasmBindgenCli,
|
rustPlatform,
|
||||||
rustPlatform,
|
...
|
||||||
...
|
}:
|
||||||
}:
|
buildWasmBindgenCli rec {
|
||||||
buildWasmBindgenCli rec {
|
src = fetchCrate {
|
||||||
src = fetchCrate {
|
pname = "wasm-bindgen-cli";
|
||||||
pname = "wasm-bindgen-cli";
|
version = "0.2.127";
|
||||||
version = "0.2.127";
|
hash = "sha256-di+qBAdd7pENLiIB9CoZoab+W5xeDoByMREcCGTSzWo=";
|
||||||
hash = "sha256-di+qBAdd7pENLiIB9CoZoab+W5xeDoByMREcCGTSzWo=";
|
};
|
||||||
};
|
|
||||||
|
|
||||||
cargoDeps = rustPlatform.fetchCargoVendor {
|
cargoDeps = rustPlatform.fetchCargoVendor {
|
||||||
inherit src;
|
inherit src;
|
||||||
inherit (src) pname version;
|
inherit (src) pname version;
|
||||||
hash = "sha256-FTv2GZIAQs0ePdIZXIXil7JbZ6kIT05VG6vqC1qNFxQ=";
|
hash = "sha256-FTv2GZIAQs0ePdIZXIXil7JbZ6kIT05VG6vqC1qNFxQ=";
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
utils = import ./utils.nix;
|
|
||||||
in {
|
|
||||||
perSystem = {pkgs, ...}: {
|
|
||||||
packages.wasm-bindgen = (utils.toolchain-pkgs pkgs).callPackage drv {};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
makeRustPlatform,
|
||||||
|
cargo,
|
||||||
|
rustc,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
p = pkgs;
|
||||||
|
in rec {
|
||||||
|
rustPlatform = makeRustPlatform {
|
||||||
|
inherit cargo rustc;
|
||||||
|
};
|
||||||
|
pkgs = p.extend (_: _: {
|
||||||
|
inherit rustPlatform;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
let
|
|
||||||
drv = {
|
|
||||||
buildEnv,
|
|
||||||
dockerTools,
|
|
||||||
wordle-solver,
|
|
||||||
runCommand,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
dockerTools.buildImage {
|
|
||||||
name = "wordle-solver";
|
|
||||||
created = "now";
|
|
||||||
copyToRoot = buildEnv {
|
|
||||||
name = "image-root";
|
|
||||||
paths = [
|
|
||||||
wordle-solver
|
|
||||||
(runCommand "wordle-data" {} ''
|
|
||||||
mkdir -p $out/pwd
|
|
||||||
cp ${../valid-words.txt} $out/pwd/valid-words.txt
|
|
||||||
cp ${../answers.txt} $out/pwd/answers.txt
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
pathsToLink = ["/bin" "/pwd"];
|
|
||||||
};
|
|
||||||
config = {
|
|
||||||
Cmd = ["/bin/wordle-solver"];
|
|
||||||
WorkingDir = "/pwd";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
perSystem = {
|
|
||||||
pkgs,
|
|
||||||
self',
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
packages.wordle-solver-docker = pkgs.callPackage drv {
|
|
||||||
inherit (self'.packages) wordle-solver;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,50 +1,39 @@
|
|||||||
{
|
{
|
||||||
perSystem = {
|
stdenvNoCC,
|
||||||
pkgs,
|
wasm-bindgen,
|
||||||
self',
|
wordle-solver-wasm,
|
||||||
...
|
root-crate,
|
||||||
}: let
|
...
|
||||||
drv = {
|
}: let
|
||||||
stdenvNoCC,
|
snake_name = "wordle_solver";
|
||||||
wasm-bindgen,
|
package-meta = {
|
||||||
wordle-solver-wasm,
|
name = "wordle-solver";
|
||||||
...
|
type = "module";
|
||||||
}: let
|
description = "module";
|
||||||
snake_name = "wordle_solver";
|
version = root-crate.build.crateVersion;
|
||||||
package-meta = {
|
files = [
|
||||||
name = "wordle-solver";
|
"${snake_name}_bg.wasm"
|
||||||
type = "module";
|
"${snake_name}.js"
|
||||||
description = "module";
|
"${snake_name}_bg.js"
|
||||||
version = "0.1.0";
|
"${snake_name}.d.ts"
|
||||||
files = [
|
];
|
||||||
"${snake_name}_bg.wasm"
|
main = "${snake_name}.js";
|
||||||
"${snake_name}.js"
|
types = "${snake_name}.d.ts";
|
||||||
"${snake_name}_bg.js"
|
sideEffects = [
|
||||||
"${snake_name}.d.ts"
|
"./${snake_name}.js"
|
||||||
];
|
"./snippets/*"
|
||||||
main = "${snake_name}.js";
|
];
|
||||||
types = "${snake_name}.d.ts";
|
|
||||||
sideEffects = [
|
|
||||||
"./${snake_name}.js"
|
|
||||||
"./snippets/*"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
package-json = builtins.toJSON package-meta;
|
|
||||||
in
|
|
||||||
stdenvNoCC.mkDerivation {
|
|
||||||
name = "wordle-solver-wasm-pkg";
|
|
||||||
nativeBuildInputs = [wasm-bindgen];
|
|
||||||
unpackPhase = "true";
|
|
||||||
buildPhase = ''
|
|
||||||
wasm-bindgen --target bundler --out-dir $out ${wordle-solver-wasm}/lib/wordle_solver.wasm
|
|
||||||
cat <<EOF > $out/package.json
|
|
||||||
${package-json}
|
|
||||||
EOF
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
packages.wordle-solver-wasm-pkg = pkgs.callPackage drv {
|
|
||||||
inherit (self'.packages) wordle-solver-wasm wasm-bindgen;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
package-json = builtins.toJSON package-meta;
|
||||||
|
in
|
||||||
|
stdenvNoCC.mkDerivation {
|
||||||
|
name = "wordle-solver-wasm-pkg";
|
||||||
|
nativeBuildInputs = [wasm-bindgen];
|
||||||
|
unpackPhase = "true";
|
||||||
|
buildPhase = ''
|
||||||
|
wasm-bindgen --target bundler --out-dir $out ${wordle-solver-wasm}/lib/wordle_solver.wasm
|
||||||
|
cat <<EOF > $out/package.json
|
||||||
|
${package-json}
|
||||||
|
EOF
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|||||||
+31
-48
@@ -1,56 +1,39 @@
|
|||||||
{
|
{
|
||||||
perSystem = {pkgs, ...}: let
|
rustPlatform,
|
||||||
utils = import ./utils.nix;
|
buildPackages,
|
||||||
rust-toolchain = utils.rust-toolchain pkgs;
|
lld,
|
||||||
toolchain-crosspkgs = utils.toolchain-crosspkgs pkgs;
|
name ? "wordle-solver",
|
||||||
drv = {
|
...
|
||||||
rustPlatform,
|
}:
|
||||||
buildPackages,
|
rustPlatform.buildRustPackage {
|
||||||
lld,
|
inherit name;
|
||||||
name ? "wordle-solver",
|
|
||||||
removeReferencesTo,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
rustPlatform.buildRustPackage {
|
|
||||||
inherit name;
|
|
||||||
|
|
||||||
src = ../.; # Or your source location
|
src = ../.; # Or your source location
|
||||||
cargoLock.lockFile = ../Cargo.lock;
|
cargoLock.lockFile = ../Cargo.lock;
|
||||||
|
|
||||||
# Disable tests since they can't run on WASM
|
# Disable tests since they can't run on WASM
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|
||||||
# Required dependencies for WASM builds
|
# Required dependencies for WASM builds
|
||||||
depsBuildBuild = [
|
depsBuildBuild = [
|
||||||
buildPackages.stdenv.cc
|
buildPackages.stdenv.cc
|
||||||
lld # Needed for wasm-ld
|
lld # Needed for wasm-ld
|
||||||
];
|
];
|
||||||
nativeBuildInputs = [removeReferencesTo];
|
|
||||||
|
|
||||||
cargoBuildFlags = [
|
cargoBuildFlags = [
|
||||||
"--lib"
|
"--lib"
|
||||||
"--features"
|
"--features"
|
||||||
"wasm-bindgen"
|
"wasm-bindgen"
|
||||||
];
|
];
|
||||||
|
|
||||||
# Configure rustc for WASM
|
# Configure rustc for WASM
|
||||||
RUSTFLAGS = ''--cfg=web_sys_unstable_apis -C linker=wasm-ld -C strip=debuginfo -C debuginfo=0'';
|
env = {
|
||||||
|
RUSTFLAGS = ''--cfg=web_sys_unstable_apis -C linker=wasm-ld'';
|
||||||
# Copy the WASM file to the output
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/lib
|
|
||||||
cp target/wasm32-unknown-unknown/release/*.wasm $out/lib/
|
|
||||||
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Remove toolchain from closure (store paths are debug artifacts)
|
|
||||||
postInstall = ''
|
|
||||||
remove-references-to -t ${rust-toolchain} $out/lib/*.wasm
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
packages.toolchain = rust-toolchain;
|
|
||||||
packages.wordle-solver-wasm = toolchain-crosspkgs.callPackage drv {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Copy the WASM file to the output
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/lib
|
||||||
|
cp target/wasm32-unknown-unknown/release/*.wasm $out/lib/
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
let
|
|
||||||
drv = {
|
|
||||||
buildEnv,
|
|
||||||
dockerTools,
|
|
||||||
fakeNss,
|
|
||||||
nginx,
|
|
||||||
runCommand,
|
|
||||||
wordle-solver-web,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
dockerTools.buildImage {
|
|
||||||
name = "wordle-solver-web";
|
|
||||||
created = "now";
|
|
||||||
copyToRoot = buildEnv {
|
|
||||||
name = "image-root";
|
|
||||||
paths = [
|
|
||||||
nginx
|
|
||||||
(fakeNss.override {
|
|
||||||
extraGroupLines = [
|
|
||||||
"nogroup:x:65534:"
|
|
||||||
];
|
|
||||||
})
|
|
||||||
(runCommand "nginx-conf" {} ''
|
|
||||||
mkdir -p $out/etc
|
|
||||||
|
|
||||||
cat <<EOF > $out/etc/nginx.conf
|
|
||||||
events {}
|
|
||||||
|
|
||||||
error_log /dev/stderr;
|
|
||||||
|
|
||||||
http {
|
|
||||||
include ${nginx}/conf/mime.types;
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
root ${wordle-solver-web};
|
|
||||||
access_log /dev/stdout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
daemon off;
|
|
||||||
EOF
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
pathsToLink = ["/etc"];
|
|
||||||
};
|
|
||||||
runAsRoot = ''
|
|
||||||
mkdir -p /var/log/nginx
|
|
||||||
'';
|
|
||||||
config = {
|
|
||||||
Cmd = ["${nginx}/bin/nginx" "-c" "/etc/nginx.conf"];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
perSystem = {
|
|
||||||
pkgs,
|
|
||||||
self',
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
packages.wordle-solver-web-docker = pkgs.callPackage drv {
|
|
||||||
inherit (self'.packages) wordle-solver-web;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
+33
-45
@@ -1,49 +1,37 @@
|
|||||||
{
|
{
|
||||||
perSystem = {
|
stdenv,
|
||||||
pkgs,
|
fetchYarnDeps,
|
||||||
self',
|
yarnConfigHook,
|
||||||
...
|
yarnBuildHook,
|
||||||
}: let
|
nodejs,
|
||||||
drv = {
|
wordle-solver-wasm-pkg,
|
||||||
stdenv,
|
}:
|
||||||
fetchYarnDeps,
|
stdenv.mkDerivation (finalAttrs: {
|
||||||
yarnConfigHook,
|
pname = "wordle-solver-web";
|
||||||
yarnBuildHook,
|
version = "0.1.0";
|
||||||
nodejs,
|
|
||||||
wordle-solver-wasm-pkg,
|
|
||||||
}:
|
|
||||||
stdenv.mkDerivation (finalAttrs: {
|
|
||||||
pname = "wordle-solver-web";
|
|
||||||
version = "0.1.0";
|
|
||||||
|
|
||||||
src = ../web;
|
src = ../web;
|
||||||
|
|
||||||
yarnOfflineCache = fetchYarnDeps {
|
yarnOfflineCache = fetchYarnDeps {
|
||||||
yarnLock = finalAttrs.src + "/yarn.lock";
|
yarnLock = finalAttrs.src + "/yarn.lock";
|
||||||
hash = "sha256-MTyHX2+/U7jRB1SJWbK9Td43zq+nclQwx7oDZbX0DqA=";
|
hash = "sha256-MTyHX2+/U7jRB1SJWbK9Td43zq+nclQwx7oDZbX0DqA=";
|
||||||
};
|
|
||||||
|
|
||||||
yarnBuildScript = "build-no-wasm";
|
|
||||||
|
|
||||||
postPatch = ''
|
|
||||||
ln -s ${wordle-solver-wasm-pkg} pkg
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir $out
|
|
||||||
mv dist/* $out/
|
|
||||||
'';
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
yarnConfigHook
|
|
||||||
yarnBuildHook
|
|
||||||
# Needed for executing package.json scripts
|
|
||||||
nodejs
|
|
||||||
];
|
|
||||||
});
|
|
||||||
in {
|
|
||||||
packages.wordle-solver-web = pkgs.callPackage drv {
|
|
||||||
inherit (self'.packages) wordle-solver-wasm-pkg;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
yarnBuildScript = "build-no-wasm";
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
ln -s ${wordle-solver-wasm-pkg} pkg
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir $out
|
||||||
|
mv dist/* $out/
|
||||||
|
'';
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
yarnConfigHook
|
||||||
|
yarnBuildHook
|
||||||
|
# Needed for executing package.json scripts
|
||||||
|
nodejs
|
||||||
|
];
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
{inputs, ...}: {
|
|
||||||
perSystem = {pkgs, ...}: let
|
|
||||||
# Cargo.nix for IFD
|
|
||||||
generatedCargoNix = inputs.crate2nix.tools.${pkgs.hostPlatform.system}.generatedCargoNix {
|
|
||||||
name = "rustnix";
|
|
||||||
src = ../.;
|
|
||||||
};
|
|
||||||
|
|
||||||
utils = import ./utils.nix;
|
|
||||||
|
|
||||||
rust-toolchain = utils.rust-toolchain pkgs;
|
|
||||||
toolchain-pkgs = utils.toolchain-pkgs pkgs;
|
|
||||||
|
|
||||||
buildRustCrateForPkgs = _:
|
|
||||||
pkgs.buildRustCrate.override {
|
|
||||||
cargo = rust-toolchain;
|
|
||||||
rustc = rust-toolchain;
|
|
||||||
};
|
|
||||||
|
|
||||||
cargoNix = import generatedCargoNix {
|
|
||||||
pkgs = toolchain-pkgs;
|
|
||||||
inherit buildRustCrateForPkgs;
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
packages.wordle-solver = cargoNix.rootCrate.build;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use derive_more::Display;
|
use derive_more::Display;
|
||||||
|
#[cfg(feature = "wasm-bindgen")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Display, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
#[derive(Display, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
||||||
|
#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))]
|
||||||
pub enum CharStatus {
|
pub enum CharStatus {
|
||||||
GREY,
|
GREY,
|
||||||
YELLOW,
|
YELLOW,
|
||||||
@@ -9,6 +12,7 @@ pub enum CharStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||||
|
#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))]
|
||||||
pub struct Pattern {
|
pub struct Pattern {
|
||||||
chars: Vec<char>,
|
chars: Vec<char>,
|
||||||
stats: Vec<CharStatus>,
|
stats: Vec<CharStatus>,
|
||||||
|
|||||||
@@ -7,18 +7,23 @@ use crate::pattern::Pattern;
|
|||||||
use indicatif::ParallelProgressIterator;
|
use indicatif::ParallelProgressIterator;
|
||||||
use rayon::iter::{ParallelBridge, ParallelIterator};
|
use rayon::iter::{ParallelBridge, ParallelIterator};
|
||||||
|
|
||||||
|
#[cfg(feature = "wasm-bindgen")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::word_list::WordList;
|
use crate::word_list::WordList;
|
||||||
|
|
||||||
use derive_more::Display;
|
use derive_more::Display;
|
||||||
use tabular::{Row, Table};
|
use tabular::{Row, Table};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))]
|
||||||
pub struct Guess {
|
pub struct Guess {
|
||||||
pub pattern: Pattern,
|
pub pattern: Pattern,
|
||||||
pub information_gained: f64,
|
pub information_gained: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))]
|
||||||
pub struct Solver {
|
pub struct Solver {
|
||||||
valid_words: WordList,
|
valid_words: WordList,
|
||||||
possible_solutions: WordList,
|
possible_solutions: WordList,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
use rmp_serde::{from_slice, to_vec};
|
||||||
|
use serde::Serialize;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -63,6 +65,26 @@ impl Solver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn serialize(&self) -> Result<js_sys::Uint8Array, String> {
|
||||||
|
let r = to_vec(&self.0).map_err(|e| {
|
||||||
|
let s = e.to_string();
|
||||||
|
drop(e);
|
||||||
|
s
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(js_sys::Uint8Array::from(&r[..]))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_from_serialized(bytes: &js_sys::Uint8Array) -> Result<Solver, String> {
|
||||||
|
from_slice(&bytes.to_vec()[..])
|
||||||
|
.map_err(|e| {
|
||||||
|
let s = e.to_string();
|
||||||
|
drop(e);
|
||||||
|
s
|
||||||
|
})
|
||||||
|
.map(Solver)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn guess(&mut self, word: &str, colors: Vec<Color>) -> Result<(), String> {
|
pub fn guess(&mut self, word: &str, colors: Vec<Color>) -> Result<(), String> {
|
||||||
let pat = Pattern::try_new(
|
let pat = Pattern::try_new(
|
||||||
word,
|
word,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use rand::{rng, seq::IteratorRandom};
|
use rand::{rng, seq::IteratorRandom};
|
||||||
|
#[cfg(feature = "wasm-bindgen")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{hash_set, HashSet},
|
collections::{hash_set, HashSet},
|
||||||
fs::{self},
|
fs::{self},
|
||||||
@@ -11,6 +13,7 @@ use derive_more::Display;
|
|||||||
use crate::pattern::Pattern;
|
use crate::pattern::Pattern;
|
||||||
|
|
||||||
#[derive(Display, Clone)]
|
#[derive(Display, Clone)]
|
||||||
|
#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))]
|
||||||
#[display("{:?}", words)]
|
#[display("{:?}", words)]
|
||||||
pub struct WordList {
|
pub struct WordList {
|
||||||
words: HashSet<String>,
|
words: HashSet<String>,
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
pnpm-debug.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
node_modules
|
|
||||||
dist
|
|
||||||
dist-ssr
|
|
||||||
*.local
|
|
||||||
|
|
||||||
# Editor directories and files
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/extensions.json
|
|
||||||
.idea
|
|
||||||
.DS_Store
|
|
||||||
*.suo
|
|
||||||
*.ntvs*
|
|
||||||
*.njsproj
|
|
||||||
*.sln
|
|
||||||
*.sw?
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta
|
|
||||||
name="viewport"
|
|
||||||
content="width=device-width, initial-scale=1.0"
|
|
||||||
/>
|
|
||||||
<title>Wordle Solver</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script type="module" src="/src/main.ts"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "web",
|
|
||||||
"private": true,
|
|
||||||
"version": "0.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"serve": "run-s wasm-pack:release vite:serve",
|
|
||||||
"build-no-wasm": "run-s tsc vite:build",
|
|
||||||
"build": "run-s wasm-pack:release tsc vite:build",
|
|
||||||
"dev": "run-s wasm-pack:dev vite:dev",
|
|
||||||
"tsc": "tsc",
|
|
||||||
"vite:build": "vite build",
|
|
||||||
"vite:dev": "vite -c vite.config.dev.ts",
|
|
||||||
"vite:serve": "vite -c vite.config.ts",
|
|
||||||
"wasm-pack:dev": "rm -rf pkg; wasm-pack build --dev --features wasm-bindgen --manifest-path ../Cargo.toml; mv ../pkg .",
|
|
||||||
"wasm-pack:release": "rm -rf pkg; wasm-pack build --features wasm-bindgen --manifest-path ../Cargo.toml; mv ../pkg ."
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
||||||
"@tailwindcss/typography": "^0.5.20",
|
|
||||||
"@tailwindcss/vite": "^4.3.3",
|
|
||||||
"npm-run-all": "^4.1.5",
|
|
||||||
"tailwindcss": "^4.3.3",
|
|
||||||
"typescript": "~6.0.2",
|
|
||||||
"vite": "^8.2.0",
|
|
||||||
"vite-plugin-top-level-await": "^1.6.0",
|
|
||||||
"vite-plugin-wasm": "^3.6.0",
|
|
||||||
"vite-plugin-wasm-pack-watcher": "^1.0.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@humanspeak/svelte-markdown": "^1.8.7",
|
|
||||||
"@lucide/svelte": "^1.33.0",
|
|
||||||
"esbuild": "^0.28.2",
|
|
||||||
"katex": "^0.18.4",
|
|
||||||
"rollup": "^4.62.4",
|
|
||||||
"svelte": "^5.56.9",
|
|
||||||
"wordle-solver": "link:./pkg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,316 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { Color } from "wordle-solver";
|
|
||||||
import WordleLine from "./components/WordleLine.svelte";
|
|
||||||
import {
|
|
||||||
solver_evaluate_words,
|
|
||||||
solver_guess,
|
|
||||||
solver_reset,
|
|
||||||
solver_solution_space,
|
|
||||||
} from "./solver/solver.ts";
|
|
||||||
import type {
|
|
||||||
GuessResult,
|
|
||||||
SolutionSpaceResult,
|
|
||||||
EvaluateWordsResult,
|
|
||||||
EvaluateWordsProgress,
|
|
||||||
} from "./solver/types.ts";
|
|
||||||
import info_md from "./assets/info.md?raw";
|
|
||||||
import SolverOutput from "./components/SolverOutput.svelte";
|
|
||||||
import { CircleX, FolderGit2, Info } from "@lucide/svelte";
|
|
||||||
import { tick, onMount } from "svelte";
|
|
||||||
import SvelteMarkdown from "@humanspeak/svelte-markdown";
|
|
||||||
|
|
||||||
let guesses = $state([
|
|
||||||
{
|
|
||||||
letters: ["", "", "", "", ""],
|
|
||||||
colors: [
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
let show_info = $state(false);
|
|
||||||
|
|
||||||
let infos_gained: (Promise<GuessResult> | null)[] = $state([null]);
|
|
||||||
|
|
||||||
let use_default_wordle_answers: boolean = $state(true);
|
|
||||||
|
|
||||||
let solution_space: Promise<SolutionSpaceResult> = $state(
|
|
||||||
solver_solution_space(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let best_words: Promise<EvaluateWordsResult> | null = $state(null);
|
|
||||||
let best_words_progress: EvaluateWordsProgress | null = $state(null);
|
|
||||||
let solving: boolean = $state(false);
|
|
||||||
|
|
||||||
let w_lines: WordleLine[] = $state([]);
|
|
||||||
let cursor = $state(0);
|
|
||||||
|
|
||||||
let is_desktop = $state(false);
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const update = () => {
|
|
||||||
is_desktop = window.innerWidth >= 768;
|
|
||||||
};
|
|
||||||
|
|
||||||
update();
|
|
||||||
window.addEventListener("resize", update);
|
|
||||||
|
|
||||||
return () => window.removeEventListener("resize", update);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function toggleSolver() {
|
|
||||||
if (solving) {
|
|
||||||
await stopSolver();
|
|
||||||
} else {
|
|
||||||
best_words = solver_evaluate_words(5, (p) => {
|
|
||||||
best_words_progress = p;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function reset() {
|
|
||||||
await solver_reset(use_default_wordle_answers);
|
|
||||||
|
|
||||||
guesses = [
|
|
||||||
{
|
|
||||||
letters: ["", "", "", "", ""],
|
|
||||||
colors: [
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
infos_gained = [null];
|
|
||||||
best_words = null;
|
|
||||||
solution_space = solver_solution_space();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function stopSolver() {
|
|
||||||
await solver_reset(use_default_wordle_answers);
|
|
||||||
for (const g of guesses.slice(0, -1)) {
|
|
||||||
try {
|
|
||||||
await solver_guess(g.letters, g.colors);
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doGuess() {
|
|
||||||
const guess = guesses[guesses.length - 1];
|
|
||||||
|
|
||||||
if (guess.letters.join("").length != 5) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
infos_gained[infos_gained.length - 1] = solver_guess(
|
|
||||||
guess.letters,
|
|
||||||
guess.colors,
|
|
||||||
);
|
|
||||||
infos_gained.push(null);
|
|
||||||
solution_space = solver_solution_space();
|
|
||||||
|
|
||||||
cursor = 0;
|
|
||||||
|
|
||||||
guesses.push({
|
|
||||||
letters: ["", "", "", "", ""],
|
|
||||||
colors: [
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
await tick();
|
|
||||||
|
|
||||||
w_lines[w_lines.length - 1].focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleKey(event: KeyboardEvent) {
|
|
||||||
if (/^[a-zA-Z ]$/.test(event.key)) {
|
|
||||||
w_lines[guesses.length - 1].focus();
|
|
||||||
} else if (event.key === "Enter" && event.shiftKey) {
|
|
||||||
best_words = solver_evaluate_words(5, (p) => {
|
|
||||||
best_words_progress = p;
|
|
||||||
});
|
|
||||||
} else if (event.key === "Escape" && event.ctrlKey) {
|
|
||||||
await reset();
|
|
||||||
} else if (event.key === "Escape") {
|
|
||||||
await stopSolver();
|
|
||||||
} else if (event.key === "Enter") {
|
|
||||||
await doGuess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:window onkeydown={handleKey} />
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="h-dvh w-full max-w-full
|
|
||||||
bg-zinc-950 text-zinc-100
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="h-full overflow-y-auto
|
|
||||||
flex flex-wrap md:flex-row
|
|
||||||
items-center justify-center p-2 md:p-10 gap-4
|
|
||||||
overflow-hidden select-none"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
class="fixed top-4 right-4"
|
|
||||||
href="https://git.jroeger.de/jonas/wordle-solver-rs"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<FolderGit2 />
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
class="fixed top-4 left-4"
|
|
||||||
onclick={() => {
|
|
||||||
show_info = true;
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Info />
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<h1 class="mb-4 text-3xl font-bold">Wordle Solver</h1>
|
|
||||||
|
|
||||||
<p class="text-sm text-zinc-500">
|
|
||||||
Use Wordle-Answers:
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
bind:checked={use_default_wordle_answers}
|
|
||||||
onfocus={(e) => {
|
|
||||||
if (e.currentTarget) {
|
|
||||||
e.currentTarget.blur();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onchange={reset}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="mt-0 text-sm text-zinc-500">
|
|
||||||
{#await solution_space}
|
|
||||||
loading
|
|
||||||
{:then s}
|
|
||||||
Solution-space: {s.size}, Uncertainty: {s.uncertainty.toFixed(
|
|
||||||
2,
|
|
||||||
)}bits
|
|
||||||
{:catch e}
|
|
||||||
{e}
|
|
||||||
{/await}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="mt-2 flex flex-col gap-2">
|
|
||||||
{#each guesses as g, i (g)}
|
|
||||||
<WordleLine
|
|
||||||
active={i === guesses.length - 1}
|
|
||||||
on_guess_pressed={i === guesses.length - 1
|
|
||||||
? doGuess
|
|
||||||
: null}
|
|
||||||
bind:this={w_lines[i]}
|
|
||||||
bind:cursor
|
|
||||||
bind:letters={guesses[i].letters}
|
|
||||||
bind:colors={guesses[i].colors}
|
|
||||||
info_gained={infos_gained[i]}
|
|
||||||
/>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if is_desktop}
|
|
||||||
<p class="mt-4 text-sm text-zinc-500 mx-auto w-3/4">
|
|
||||||
Type letters · ← → navigate · Space cycle color · Backspace
|
|
||||||
delete · Enter apply · Shift+Enter solve · Escape abort
|
|
||||||
solver · Ctrl+Esc reset
|
|
||||||
</p>
|
|
||||||
{/if}
|
|
||||||
<button
|
|
||||||
tabindex="-1"
|
|
||||||
class="mt-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"
|
|
||||||
onclick={(e) => {
|
|
||||||
e.currentTarget.blur();
|
|
||||||
toggleSolver();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{#if solving}
|
|
||||||
Cancel
|
|
||||||
{:else}
|
|
||||||
Solve
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{#if best_words}
|
|
||||||
<SolverOutput
|
|
||||||
data={best_words}
|
|
||||||
progress={best_words_progress}
|
|
||||||
insert_guess={(g) => {
|
|
||||||
guesses[guesses.length - 1].letters = g;
|
|
||||||
}}
|
|
||||||
bind:solving
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if show_info}
|
|
||||||
<div
|
|
||||||
class="fixed inset-0 z-50 flex items-center justify-center bg-black/60"
|
|
||||||
tabindex="-1"
|
|
||||||
role="button"
|
|
||||||
onclick={() => (show_info = false)}
|
|
||||||
onkeydown={() => (show_info = false)}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="relative flex flex-col
|
|
||||||
rounded-lg
|
|
||||||
bg-zinc-900
|
|
||||||
p-6 shadow-xl
|
|
||||||
md:max-w-[75vw]
|
|
||||||
md:max-h-[75vh]
|
|
||||||
max-w-[calc(100vw-3rem)]
|
|
||||||
max-h-[calc(100vh-3rem)]
|
|
||||||
overflow-hidden"
|
|
||||||
tabindex="0"
|
|
||||||
role="dialog"
|
|
||||||
onclick={(e) => e.stopPropagation()}
|
|
||||||
onkeydown={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="absolute top-4 right-4"
|
|
||||||
tabindex="-1"
|
|
||||||
role="button"
|
|
||||||
onclick={() => (show_info = false)}
|
|
||||||
onkeydown={() => (show_info = false)}
|
|
||||||
>
|
|
||||||
<CircleX />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="prose prose-invert max-w-none
|
|
||||||
h-full
|
|
||||||
overflow-y-auto
|
|
||||||
overflow-x-hidden"
|
|
||||||
>
|
|
||||||
<SvelteMarkdown source={info_md} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
:global(body) {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
overscroll-behavior: none;
|
|
||||||
background: #09090b;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
@import "tailwindcss";
|
|
||||||
@plugin "@tailwindcss/typography";
|
|
||||||
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
min-height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# Wordle Solver
|
|
||||||
|
|
||||||
This wordle solver uses an information theory based approach to
|
|
||||||
evaluate the next-best-guess. It's heavily inspired by [3b1b's approach](https://www.youtube.com/watch?v=v68zYyaEmEA)
|
|
||||||
on solving wordle.
|
|
||||||
|
|
||||||
## How to use?
|
|
||||||
|
|
||||||
You can run the solver at any time to tell you five best next guesses (ranked).
|
|
||||||
However when the solver has no information this can take quite some time. So it's
|
|
||||||
best to make your first guess (e.g. "CRANE", "SALES", ...):
|
|
||||||
|
|
||||||
1. Once your wordle game gave you an answer, type it into the interface:
|
|
||||||
|
|
||||||
- type letters to input them
|
|
||||||
- click a cell to change it's color (or cycle it with <Space>)
|
|
||||||
|
|
||||||
2. To give the solver the information of your guess press enter (or the little enter icon next to the line)
|
|
||||||
|
|
||||||
3. The solver will tell you the amount of information gained by this guess.
|
|
||||||
|
|
||||||
4. Run the solver to get a new next-best-guess and repeat until you found the answer
|
|
||||||
|
|
||||||
## Solution Space
|
|
||||||
|
|
||||||
The solution space is by default the list of possible wordle-answers (uncheck the box to use all valid words as possible answers).
|
|
||||||
Above your inputs you can see how many possible answers are still left given your guesses with a value of
|
|
||||||
remaining uncertainty in bits (how many yes-no questions are required to identify an item in the equally distributed set).
|
|
||||||
The goal is to reach 0bits of uncertainty, meaning one word left.
|
|
||||||
|
|
||||||
Sometimes when adding a guess there may appear an error symbol. This occurrs when the guess would empty
|
|
||||||
the solution space. This can only happen if the solution space did not contain the solution of your wordle game (or there some inconsistencies in the guesses).
|
|
||||||
In this case you might wanna allow all valid words as possible answers.
|
|
||||||
|
|
||||||
|
|
||||||
## The Solver's output
|
|
||||||
|
|
||||||
- p(x) is the probability, that the word is actually the solution.
|
|
||||||
Often it will be 0, because the word is not a possible solution anymore.
|
|
||||||
If so, the expected information of guessing this that high, that it is worth guessing it.
|
|
||||||
|
|
||||||
- E\[Inf.\] The expected information to gain when guessing this word. (I.e. by how much do we expect to shrink the solution space?)
|
|
||||||
|
|
||||||
- E\[Score.\] The expected number of guesses required to solve the wordle when you guess this word now. It's based on a heuristic combination
|
|
||||||
of the current score, p(x) and E\[Inf.\].
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import katex from "katex";
|
|
||||||
import "katex/dist/katex.min.css";
|
|
||||||
import type {
|
|
||||||
EvaluateWordsProgress,
|
|
||||||
EvaluateWordsResult,
|
|
||||||
} from "../solver/types";
|
|
||||||
|
|
||||||
let {
|
|
||||||
data,
|
|
||||||
progress = null,
|
|
||||||
insert_guess = null,
|
|
||||||
solving = $bindable(true),
|
|
||||||
}: {
|
|
||||||
data: Promise<EvaluateWordsResult>;
|
|
||||||
progress: EvaluateWordsProgress | null;
|
|
||||||
insert_guess: ((word: string[]) => void) | null;
|
|
||||||
solving: boolean;
|
|
||||||
} = $props();
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
solving = true;
|
|
||||||
data.finally(() => {
|
|
||||||
solving = false;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function renderMath(txt: string | null) {
|
|
||||||
return (element: HTMLElement) => {
|
|
||||||
if (txt) {
|
|
||||||
katex.render(txt, element);
|
|
||||||
} else {
|
|
||||||
katex.render(element.innerText, element);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#await data}
|
|
||||||
<div
|
|
||||||
class="flex items-center justify-center gap-2 text-gray-600 max-w-full"
|
|
||||||
>
|
|
||||||
Solving...
|
|
||||||
{#if progress}
|
|
||||||
<span class="text-sm">
|
|
||||||
{progress.i} / {progress.n}
|
|
||||||
</span>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{:then d}
|
|
||||||
<div
|
|
||||||
class="select-none rounded-lg border border-gray-500 shadow-sm max-w-full"
|
|
||||||
>
|
|
||||||
<table class="w-full text-left text-sm text-gray-700">
|
|
||||||
<thead class="divide-y divide-x bg-gray-800 text-xs text-gray-600">
|
|
||||||
<tr>
|
|
||||||
<th class="px-4 py-3" title="Rank the solver assigned"></th>
|
|
||||||
<th class="px-4 py-3" title="The best words">Word</th>
|
|
||||||
<th
|
|
||||||
class="px-4 py-3 math-header"
|
|
||||||
title="The probability that this word is the solution."
|
|
||||||
{@attach renderMath("p(x)")}
|
|
||||||
></th>
|
|
||||||
<th
|
|
||||||
title="The expected information to gain when guessing this word."
|
|
||||||
class="px-4 py-3 math-header"
|
|
||||||
{@attach renderMath("E[\\text{Inf.}]")}
|
|
||||||
></th>
|
|
||||||
<th
|
|
||||||
title="The expected number of guesses for this wordle when guessing this word."
|
|
||||||
class="px-4 py-3 math-header"
|
|
||||||
{@attach renderMath("E[\\text{Score}]")}
|
|
||||||
></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody class="divide-y divide-x divide-gray-500">
|
|
||||||
{#each d.stats as s, i}
|
|
||||||
<tr
|
|
||||||
class="transition-colors hover:bg-gray-50"
|
|
||||||
onclick={() => {
|
|
||||||
if (insert_guess) {
|
|
||||||
insert_guess([...s.word]);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<td class="px-4 py-3 font-bold">#{i + 1}</td>
|
|
||||||
<td class="px-4 py-3 font-bold">{s.word}</td>
|
|
||||||
<td class="px-4 py-3">
|
|
||||||
{(s.solution_probability * 100).toFixed(2) + "%"}
|
|
||||||
</td>
|
|
||||||
<td class="px-4 py-3">
|
|
||||||
{s.expected_information_gained.toFixed(2)} bits
|
|
||||||
</td>
|
|
||||||
<td class="px-4 py-3">
|
|
||||||
{s.expected_score_after_guess.toFixed(3)}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{:catch e}
|
|
||||||
<div class="rounded-lg border border-red-400 bg-gray-800 p-4 text-red-400">
|
|
||||||
{e}
|
|
||||||
</div>
|
|
||||||
{/await}
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.math-header :global(.katex) {
|
|
||||||
font-size: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.math-header :global(.katex .mord) {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { Color } from "wordle-solver";
|
|
||||||
import type { GuessResult } from "../solver/types";
|
|
||||||
|
|
||||||
let {
|
|
||||||
active = false,
|
|
||||||
cursor = $bindable(0),
|
|
||||||
letters = $bindable(["", "", "", "", ""]),
|
|
||||||
colors = $bindable([
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
Color.GREY,
|
|
||||||
]),
|
|
||||||
info_gained = null,
|
|
||||||
on_guess_pressed = null,
|
|
||||||
}: {
|
|
||||||
active: boolean;
|
|
||||||
cursor: number;
|
|
||||||
letters: string[];
|
|
||||||
colors: Color[];
|
|
||||||
info_gained: Promise<GuessResult> | null;
|
|
||||||
on_guess_pressed: (() => void) | null;
|
|
||||||
} = $props();
|
|
||||||
|
|
||||||
let invalid: boolean = $state(false);
|
|
||||||
let inputs: HTMLInputElement[] = $state([]);
|
|
||||||
let info_gained_wrapped: Promise<GuessResult> | null = $state(null);
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (info_gained) {
|
|
||||||
info_gained_wrapped = info_gained.catch((e) => {
|
|
||||||
invalid = true;
|
|
||||||
throw e;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
info_gained_wrapped = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export function focus() {
|
|
||||||
inputs[cursor].focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleKey(event: KeyboardEvent) {
|
|
||||||
if (!active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === "Backspace") {
|
|
||||||
if (letters[cursor] === "" && cursor > 0) {
|
|
||||||
const nc = cursor - 1;
|
|
||||||
inputs[nc].focus(); // Focusing / bluring resets cursor temporarily
|
|
||||||
cursor = nc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (active) {
|
|
||||||
letters[cursor] = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === "ArrowLeft") {
|
|
||||||
const nc = Math.max(0, cursor - 1);
|
|
||||||
inputs[nc].focus();
|
|
||||||
cursor = nc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === "ArrowRight") {
|
|
||||||
const nc = Math.min(4, cursor + 1);
|
|
||||||
inputs[nc].focus();
|
|
||||||
cursor = nc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === " ") {
|
|
||||||
colors[cursor] = (colors[cursor] + 1) % 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:window onkeydown={handleKey} />
|
|
||||||
|
|
||||||
<div class="flex justify-center gap-2">
|
|
||||||
{#each letters as _, i}
|
|
||||||
<input
|
|
||||||
disabled={!active}
|
|
||||||
tabindex="-1"
|
|
||||||
class="
|
|
||||||
flex aspect-square max-w-16 w-1/6 items-center justify-center
|
|
||||||
rounded-lg border-2
|
|
||||||
text-3xl font-bold
|
|
||||||
transition-all text-center caret-transparent
|
|
||||||
focus:outline-none
|
|
||||||
"
|
|
||||||
bind:this={inputs[i]}
|
|
||||||
bind:value={letters[i]}
|
|
||||||
class:border-blue-500={i === cursor && active}
|
|
||||||
class:border-zinc-700={i !== cursor || !active}
|
|
||||||
class:bg-green-600={colors[i] === Color.GREEN}
|
|
||||||
class:bg-yellow-600={colors[i] === Color.YELLOW}
|
|
||||||
class:bg-grey-600={colors[i] === Color.GREY}
|
|
||||||
class:opacity-20={invalid}
|
|
||||||
onblur={() => {
|
|
||||||
cursor = -1;
|
|
||||||
}}
|
|
||||||
onbeforeinput={(event) => {
|
|
||||||
if (event.inputType === "insertText") {
|
|
||||||
event.preventDefault();
|
|
||||||
let key = event.data ?? "";
|
|
||||||
|
|
||||||
if (/^[a-zA-Z]$/.test(key)) {
|
|
||||||
letters[i] = key.toUpperCase();
|
|
||||||
let nc = cursor;
|
|
||||||
if (nc < 4) {
|
|
||||||
nc++;
|
|
||||||
} else {
|
|
||||||
nc = 0;
|
|
||||||
}
|
|
||||||
inputs[nc].focus();
|
|
||||||
cursor = nc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onclick={() => {
|
|
||||||
if (!active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cursor === i) {
|
|
||||||
colors[cursor] = (colors[cursor] + 1) % 3;
|
|
||||||
} else {
|
|
||||||
cursor = i;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{/each}
|
|
||||||
<span
|
|
||||||
class="max-w-14 w-1/6 text-sm text-zinc-500 self-center flex items-center justify-center"
|
|
||||||
onclick={info_gained === null ? on_guess_pressed : null}
|
|
||||||
>
|
|
||||||
{#if info_gained_wrapped === null}
|
|
||||||
↵
|
|
||||||
{:else}
|
|
||||||
{#await info_gained_wrapped}
|
|
||||||
<div
|
|
||||||
class="size-3 animate-spin rounded-full border-2 border-gray-300 border-t-gray-700"
|
|
||||||
></div>
|
|
||||||
{:then i}
|
|
||||||
{i.info_gained.toFixed(2)} bits
|
|
||||||
{:catch e}
|
|
||||||
<span
|
|
||||||
title={e}
|
|
||||||
class="lex size-4 items-center justify-center rounded-full border border-red-500 text-[10px] font-bold text-red-500"
|
|
||||||
>!</span
|
|
||||||
>
|
|
||||||
{/await}
|
|
||||||
{/if}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import "./app.css";
|
|
||||||
import { mount } from "svelte";
|
|
||||||
import App from "./App.svelte";
|
|
||||||
|
|
||||||
const app = mount(App, {
|
|
||||||
target: document.getElementById("app")!,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default app;
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
import type { Color } from "wordle-solver";
|
|
||||||
import SolverWorker from "./worker?worker";
|
|
||||||
import type { GuessResult, SolutionSpaceResult, EvaluateWordsResult, SolverRequest, SolverResponse, EvaluateWordsProgress } from "./types";
|
|
||||||
|
|
||||||
let solver_worker = new SolverWorker();
|
|
||||||
await init_solver();
|
|
||||||
|
|
||||||
let msg_id = 0;
|
|
||||||
|
|
||||||
const pending = new Map<number, {
|
|
||||||
resolve: (value: any) => void;
|
|
||||||
reject: (error: any) => void;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const progresses = new Map<number, (p: EvaluateWordsProgress) => void>();
|
|
||||||
|
|
||||||
function init_solver(): Promise<void> {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
solver_worker.onmessage = (event: any) => {
|
|
||||||
if (event.data.type === "ready") {
|
|
||||||
solver_worker.onmessage = workerHandleMsg;
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
workerHandleMsg(event);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_solver_worker(): Promise<void> {
|
|
||||||
solver_worker = new SolverWorker();
|
|
||||||
|
|
||||||
return init_solver();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function solver_guess(word: string[], colors: Color[]): Promise<GuessResult> {
|
|
||||||
const id = msg_id++;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
pending.set(id, { resolve, reject });
|
|
||||||
|
|
||||||
const r: SolverRequest = {
|
|
||||||
type: "guess",
|
|
||||||
id: id,
|
|
||||||
input: { word: word, colors: colors },
|
|
||||||
};
|
|
||||||
|
|
||||||
solver_worker.postMessage(JSON.parse(JSON.stringify(r)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function solver_solution_space(): Promise<SolutionSpaceResult> {
|
|
||||||
const id = msg_id++;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
pending.set(id, { resolve, reject });
|
|
||||||
|
|
||||||
const r: SolverRequest = {
|
|
||||||
type: "solution_space",
|
|
||||||
id: id,
|
|
||||||
input: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
solver_worker.postMessage(JSON.parse(JSON.stringify(r)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function solver_evaluate_words(n: number, progress: ((p: EvaluateWordsProgress) => void) | null): Promise<EvaluateWordsResult> {
|
|
||||||
const id = msg_id++;
|
|
||||||
|
|
||||||
if (progress) {
|
|
||||||
progresses.set(id, progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
pending.set(id, { resolve, reject });
|
|
||||||
|
|
||||||
const r: SolverRequest = {
|
|
||||||
type: "evaluate_words",
|
|
||||||
id: id,
|
|
||||||
input: { n },
|
|
||||||
};
|
|
||||||
|
|
||||||
solver_worker.postMessage(JSON.parse(JSON.stringify(r)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function solver_reset(wordle_answers: boolean): Promise<void> {
|
|
||||||
solver_worker.terminate();
|
|
||||||
|
|
||||||
await create_solver_worker();
|
|
||||||
|
|
||||||
pending.forEach((v, _) => {
|
|
||||||
v.reject("Solver was reset");
|
|
||||||
});
|
|
||||||
pending.clear();
|
|
||||||
progresses.clear();
|
|
||||||
|
|
||||||
const id = msg_id++;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
pending.set(id, { resolve, reject });
|
|
||||||
|
|
||||||
const r: SolverRequest = {
|
|
||||||
type: "reload_wordlist",
|
|
||||||
id: id,
|
|
||||||
input: { use_wordle_ansers: wordle_answers },
|
|
||||||
};
|
|
||||||
|
|
||||||
solver_worker.postMessage(JSON.parse(JSON.stringify(r)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function workerHandleMsg(event: MessageEvent<SolverResponse>) {
|
|
||||||
let res = event.data;
|
|
||||||
|
|
||||||
if (res.type == "evaluate_words_progress") {
|
|
||||||
let progress = progresses.get(res.id);
|
|
||||||
|
|
||||||
if (progress) {
|
|
||||||
progress(res.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pendingRequest = pending.get(res.id);
|
|
||||||
|
|
||||||
if (!pendingRequest) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pending.delete(res.id);
|
|
||||||
progresses.delete(res.id);
|
|
||||||
|
|
||||||
if (res.error) {
|
|
||||||
pendingRequest.reject(res.error);
|
|
||||||
} else if (res.result) {
|
|
||||||
pendingRequest.resolve(res.result);
|
|
||||||
} else {
|
|
||||||
pendingRequest.reject("No result");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
import { Color } from "wordle-solver";
|
|
||||||
|
|
||||||
export type SolverRequest =
|
|
||||||
| {
|
|
||||||
type: "guess",
|
|
||||||
id: number,
|
|
||||||
input: Guess
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "evaluate_words",
|
|
||||||
id: number,
|
|
||||||
input: EvaluateWords
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "solution_space",
|
|
||||||
id: number,
|
|
||||||
input: null,
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "reload_wordlist",
|
|
||||||
id: number,
|
|
||||||
input: ReloadWordlist
|
|
||||||
};
|
|
||||||
|
|
||||||
export type SolverResponse =
|
|
||||||
| {
|
|
||||||
type: "guess",
|
|
||||||
id: number,
|
|
||||||
error: string | null,
|
|
||||||
result: GuessResult | null
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "evaluate_words",
|
|
||||||
id: number,
|
|
||||||
error: string | null,
|
|
||||||
result: EvaluateWordsResult | null
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "evaluate_words_progress",
|
|
||||||
id: number,
|
|
||||||
error: null,
|
|
||||||
result: EvaluateWordsProgress
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "solution_space",
|
|
||||||
id: number,
|
|
||||||
error: string | null,
|
|
||||||
result: SolutionSpaceResult | null
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: "reload_wordlist",
|
|
||||||
id: number,
|
|
||||||
error: string | null
|
|
||||||
result: boolean | null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Guess = {
|
|
||||||
word: string[],
|
|
||||||
colors: Color[]
|
|
||||||
};
|
|
||||||
export type GuessResult = {
|
|
||||||
info_gained: number,
|
|
||||||
};
|
|
||||||
export type EvaluateWords = {
|
|
||||||
n: number,
|
|
||||||
};
|
|
||||||
export type EvaluateWordsProgress = {
|
|
||||||
i: number,
|
|
||||||
n: number
|
|
||||||
};
|
|
||||||
export type ReloadWordlist = {
|
|
||||||
use_wordle_ansers: boolean
|
|
||||||
};
|
|
||||||
export type WordStats = {
|
|
||||||
word: string,
|
|
||||||
solution_probability: number,
|
|
||||||
expected_information_gained: number,
|
|
||||||
expected_score_after_guess: number
|
|
||||||
};
|
|
||||||
export type EvaluateWordsResult = {
|
|
||||||
stats: WordStats[]
|
|
||||||
};
|
|
||||||
export type SolutionSpaceResult = {
|
|
||||||
size: number,
|
|
||||||
uncertainty: number
|
|
||||||
};
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
import { Solver, } from "wordle-solver";
|
|
||||||
import type { SolverRequest, SolverResponse, WordStats } from "./types";
|
|
||||||
|
|
||||||
let solver = Solver.new(true);
|
|
||||||
|
|
||||||
self.postMessage({
|
|
||||||
type: "ready",
|
|
||||||
});
|
|
||||||
|
|
||||||
self.onmessage = (event: MessageEvent<SolverRequest>) => {
|
|
||||||
const request = event.data;
|
|
||||||
|
|
||||||
switch (request.type) {
|
|
||||||
case "guess": {
|
|
||||||
try {
|
|
||||||
solver.guess(request.input.word.join(""), request.input.colors);
|
|
||||||
const infos = solver.guess_infos();
|
|
||||||
|
|
||||||
const response: SolverResponse = {
|
|
||||||
type: "guess",
|
|
||||||
id: request.id,
|
|
||||||
error: null,
|
|
||||||
result: { info_gained: infos[infos.length - 1] }
|
|
||||||
};
|
|
||||||
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(response)));
|
|
||||||
} catch (e) {
|
|
||||||
const response: SolverResponse = {
|
|
||||||
type: "guess",
|
|
||||||
id: request.id,
|
|
||||||
error: e as string,
|
|
||||||
result: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(response)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
case "evaluate_words": {
|
|
||||||
try {
|
|
||||||
let stats = solver.evaluate_words(request.input.n, (i: number, n: number) => {
|
|
||||||
let p: SolverResponse = {
|
|
||||||
type: "evaluate_words_progress",
|
|
||||||
id: request.id,
|
|
||||||
error: null,
|
|
||||||
result: { i, n }
|
|
||||||
};
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(p)));
|
|
||||||
}).map((ws): WordStats => {
|
|
||||||
return {
|
|
||||||
word: ws.word,
|
|
||||||
solution_probability: ws.solution_probability,
|
|
||||||
expected_information_gained: ws.expected_information_gained,
|
|
||||||
expected_score_after_guess: ws.expected_score_after_guess
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const response: SolverResponse = {
|
|
||||||
type: "evaluate_words",
|
|
||||||
id: request.id,
|
|
||||||
error: null,
|
|
||||||
result: { stats },
|
|
||||||
};
|
|
||||||
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(response)));
|
|
||||||
} catch (e) {
|
|
||||||
const response: SolverResponse = {
|
|
||||||
type: "evaluate_words",
|
|
||||||
id: request.id,
|
|
||||||
error: e as string,
|
|
||||||
result: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(response)));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
case "solution_space": {
|
|
||||||
const response: SolverResponse = {
|
|
||||||
type: "solution_space",
|
|
||||||
id: request.id,
|
|
||||||
error: null,
|
|
||||||
result: { size: solver.solution_space(), uncertainty: solver.solution_space_uncertainty() }
|
|
||||||
};
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(response)));
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
case "reload_wordlist": {
|
|
||||||
solver.free();
|
|
||||||
solver = Solver.new(request.input.use_wordle_ansers);
|
|
||||||
const response: SolverResponse = {
|
|
||||||
type: "reload_wordlist",
|
|
||||||
id: request.id,
|
|
||||||
error: null,
|
|
||||||
result: true
|
|
||||||
};
|
|
||||||
self.postMessage(JSON.parse(JSON.stringify(response)));
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es2023",
|
|
||||||
"module": "esnext",
|
|
||||||
"lib": ["ES2023", "DOM"],
|
|
||||||
"types": ["vite/client"],
|
|
||||||
"allowArbitraryExtensions": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
|
|
||||||
/* Bundler mode */
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"allowImportingTsExtensions": true,
|
|
||||||
"verbatimModuleSyntax": true,
|
|
||||||
"moduleDetection": "force",
|
|
||||||
"noEmit": true,
|
|
||||||
|
|
||||||
/* Linting */
|
|
||||||
"noUnusedLocals": true,
|
|
||||||
"noUnusedParameters": true,
|
|
||||||
"erasableSyntaxOnly": true,
|
|
||||||
"noFallthroughCasesInSwitch": true
|
|
||||||
},
|
|
||||||
"include": ["src"]
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { defineConfig } from "vite";
|
|
||||||
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
|
||||||
import wasm from "vite-plugin-wasm";
|
|
||||||
import wasmPackWatchPlugin from "vite-plugin-wasm-pack-watcher";
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
build: {
|
|
||||||
watch: {
|
|
||||||
include: ["src/**/*.ts", "../src/**/*.rs"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: [wasmPackWatchPlugin(), wasm(), svelte(), tailwindcss()],
|
|
||||||
});
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { defineConfig } from "vite";
|
|
||||||
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
|
||||||
import wasm from "vite-plugin-wasm";
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [wasm(), svelte(), tailwindcss()],
|
|
||||||
build: {
|
|
||||||
target: "esnext"
|
|
||||||
},
|
|
||||||
worker: {
|
|
||||||
format: "es",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
-2371
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user