Skip to content

Commit

Permalink
feat: refactor to bare web-sys instead of yew
Browse files Browse the repository at this point in the history
  • Loading branch information
sgasse committed Oct 13, 2024
1 parent f40e5d4 commit ec0e4ba
Show file tree
Hide file tree
Showing 19 changed files with 865 additions and 988 deletions.
18 changes: 15 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
[package]
name = "slide-puzzle"
version = "0.2.3"
version = "0.3.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
console_error_panic_hook = { version = "^0.1.7", optional = true }
fnv = "1.0.7"
getrandom = { version = "0.2.15", features = ["js"] }
gloo-timers = "0.3.0"
log = "0.4.22"
rand = "0.8.5"
rustc-hash = "2.0.0"
simple-error = "0.3.1"
wasm-bindgen = "0.2.95"
wasm-logger = "0.2.0"
web-sys = { version = "0.3.72", features = [
"CssStyleDeclaration",
"Document",
"Element",
"HtmlCollection",
"HtmlDivElement",
"Location",
"MouseEvent",
"Touch",
"TouchEvent",
"TouchList",
"Window",
] }
yew = { git = "https://github.com/yewstack/yew/", features = ["csr"] }

[dev-dependencies]
criterion = "0.5.1"
lazy_static = "1.5.0"

[features]
default = ["console_error_panic_hook"]

[[bench]]
name = "optimal_solver_benchmark"
harness = false
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Slide Puzzle

Implementation of a slide-puzzle game with random puzzles and two solver
algorithms. Powered by the frontend framework [`yew`][yew] (compiled to
[`Wasm`][wasm]) and written in Rust.
algorithms. Written in Rust for Wasm.

![Example](./assets/slide_puzzle.gif)

Expand All @@ -20,11 +19,6 @@ to do this is by randomly doing valid swaps.

## Modeling

In code, we represent the puzzle state as an array of fields. To allow for
different sizes of puzzles while always having the same value for the empty
field, we use the maximum value of our data type, so for `u8`, this is
`u8::MAX`.

To know which fields can be swapped with which other fields, we need to tranform
the indices of the fields to the coordinates in the square puzzle grid and vice
versa to perform swaps.
Expand Down Expand Up @@ -53,7 +47,7 @@ through the graph of states which builds the graph on the go.

We can see that holding all the states in memory will be the main limiting
factor for our algorithm. To cut down memory requirements as much as possible,
we use `u8` values. With the empty field value as `u8::MAX` (255), we are
we use `u8` values. With `u8::MAX` (255), we are
limited to puzzles of size `floor(sqrt(255)) == 15` which is enough for our
purposes. It is indispensible to recognize states which we have already seen
before. To do this, we build a set of state hashes.
Expand Down Expand Up @@ -142,5 +136,4 @@ is quite complicated and tedious:
of the empty field (excluding fixed fields and the field to move itself).

[d_and_c_algorithm_explained]: https://www.kopf.com.br/kaplof/how-to-solve-any-slide-puzzle-regardless-of-its-size/
[yew]: https://yew.rs/
[wasm]: https://webassembly.org/
105 changes: 0 additions & 105 deletions app.css

This file was deleted.

1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wasm-pack build --out-dir www/pkg --target no-modules
25 changes: 0 additions & 25 deletions src/bin/main.rs

This file was deleted.

Loading

0 comments on commit ec0e4ba

Please sign in to comment.