Compare commits
No commits in common. "main" and "game" have entirely different histories.
4
.gitignore
vendored
4
.gitignore
vendored
@ -19,7 +19,3 @@ Cargo.lock
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
dist/
|
|
||||||
sol_chess.tar.gz
|
|
||||||
local-deploy/
|
|
||||||
|
353
Cargo.lock
generated
353
Cargo.lock
generated
@ -17,7 +17,7 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"version_check",
|
"version_check",
|
||||||
"zerocopy 0.7.35",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -52,24 +52,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "audir-sles"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ea47348666a8edb7ad80cbee3940eb2bccf70df0e6ce09009abe1a836cb779f5"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "audrey"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "58b92a84e89497e3cd25d3672cd5d1c288abaac02c18ff21283f17d118b889b8"
|
|
||||||
dependencies = [
|
|
||||||
"dasp_frame",
|
|
||||||
"dasp_sample",
|
|
||||||
"hound",
|
|
||||||
"lewton",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@ -83,10 +65,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bumpalo"
|
||||||
version = "2.9.0"
|
version = "3.16.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytemuck"
|
name = "bytemuck"
|
||||||
@ -112,6 +94,19 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console"
|
||||||
|
version = "0.15.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b"
|
||||||
|
dependencies = [
|
||||||
|
"encode_unicode",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"unicode-width",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.4.2"
|
version = "1.4.2"
|
||||||
@ -122,19 +117,10 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dasp_frame"
|
name = "encode_unicode"
|
||||||
version = "0.11.0"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b2a3937f5fe2135702897535c8d4a5553f8b116f76c1529088797f2eee7c5cd6"
|
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
||||||
dependencies = [
|
|
||||||
"dasp_sample",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dasp_sample"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fdeflate"
|
name = "fdeflate"
|
||||||
@ -167,13 +153,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.3.3"
|
version = "0.2.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"r-efi",
|
|
||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -192,12 +177,6 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hound"
|
|
||||||
version = "3.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "image"
|
name = "image"
|
||||||
version = "0.24.9"
|
version = "0.24.9"
|
||||||
@ -212,14 +191,26 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lewton"
|
name = "indicatif"
|
||||||
version = "0.9.4"
|
version = "0.17.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d542c1a317036c45c2aa1cf10cc9d403ca91eb2d333ef1a4917e5cb10628bd0"
|
checksum = "cbf675b85ed934d3c67b5c5469701eec7db22689d0a2139d856e0925fa28b281"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"console",
|
||||||
"ogg",
|
"number_prefix",
|
||||||
"smallvec",
|
"portable-atomic",
|
||||||
|
"unicode-width",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "js-sys"
|
||||||
|
version = "0.3.76"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -228,6 +219,12 @@ version = "0.2.169"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d6ea2a48c204030ee31a7d7fc72c93294c92fe87ecb1789881c9543516e1a0d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "macroquad"
|
name = "macroquad"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
@ -240,7 +237,6 @@ dependencies = [
|
|||||||
"macroquad_macro",
|
"macroquad_macro",
|
||||||
"miniquad",
|
"miniquad",
|
||||||
"quad-rand",
|
"quad-rand",
|
||||||
"quad-snd",
|
|
||||||
"slotmap",
|
"slotmap",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -259,12 +255,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "maybe-uninit"
|
|
||||||
version = "2.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniquad"
|
name = "miniquad"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@ -302,6 +292,12 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_prefix"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc"
|
name = "objc"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
@ -311,15 +307,6 @@ dependencies = [
|
|||||||
"malloc_buf",
|
"malloc_buf",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ogg"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "13e571c3517af9e1729d4c63571a27edd660ade0667973bfc74a67c660c2b651"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.20.2"
|
version = "1.20.2"
|
||||||
@ -332,7 +319,7 @@ version = "0.17.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
|
checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags",
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"fdeflate",
|
"fdeflate",
|
||||||
"flate2",
|
"flate2",
|
||||||
@ -340,12 +327,18 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "portable-atomic"
|
||||||
version = "0.2.21"
|
version = "1.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy 0.8.25",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -357,34 +350,12 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quad-alsa-sys"
|
|
||||||
version = "0.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c66c2f04a6946293477973d85adc251d502da51c57b08cd9c997f0cfd8dcd4b5"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quad-rand"
|
name = "quad-rand"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a651516ddc9168ebd67b24afd085a718be02f8858fe406591b013d101ce2f40"
|
checksum = "5a651516ddc9168ebd67b24afd085a718be02f8858fe406591b013d101ce2f40"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quad-snd"
|
|
||||||
version = "0.2.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cba0c4943fc67147fbe9d1eb731fb9e678bfc9d926507eebbbfe0103e154e5b0"
|
|
||||||
dependencies = [
|
|
||||||
"audir-sles",
|
|
||||||
"audrey",
|
|
||||||
"libc",
|
|
||||||
"quad-alsa-sys",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.38"
|
version = "1.0.38"
|
||||||
@ -394,27 +365,22 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "r-efi"
|
|
||||||
version = "5.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.9.1"
|
version = "0.8.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"libc",
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_chacha"
|
name = "rand_chacha"
|
||||||
version = "0.9.0"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ppv-lite86",
|
"ppv-lite86",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
@ -422,9 +388,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.9.3"
|
version = "0.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
@ -470,22 +436,13 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "smallvec"
|
|
||||||
version = "0.6.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0"
|
|
||||||
dependencies = [
|
|
||||||
"maybe-uninit",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sol_chess"
|
name = "sol_chess"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argh",
|
"argh",
|
||||||
|
"indicatif",
|
||||||
"macroquad",
|
"macroquad",
|
||||||
"quad-snd",
|
|
||||||
"rand",
|
"rand",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -512,6 +469,12 @@ version = "1.0.14"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
@ -520,11 +483,72 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.14.2+wasi-0.2.4"
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen"
|
||||||
|
version = "0.2.99"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wit-bindgen-rt",
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
"wasm-bindgen-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-backend"
|
||||||
|
version = "0.2.99"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro"
|
||||||
|
version = "0.2.99"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro-support"
|
||||||
|
version = "0.2.99"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-shared"
|
||||||
|
version = "0.2.99"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "web-time"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -550,30 +574,86 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen-rt"
|
name = "windows-sys"
|
||||||
version = "0.39.0"
|
version = "0.59.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.9.0",
|
"windows-targets",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_gnullvm",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.7.35"
|
version = "0.7.35"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy-derive 0.7.35",
|
"byteorder",
|
||||||
]
|
"zerocopy-derive",
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerocopy"
|
|
||||||
version = "0.8.25"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
|
|
||||||
dependencies = [
|
|
||||||
"zerocopy-derive 0.8.25",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -586,14 +666,3 @@ dependencies = [
|
|||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerocopy-derive"
|
|
||||||
version = "0.8.25"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
@ -6,11 +6,9 @@ default-run = "sol_chess"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argh = "0.1.13"
|
argh = "0.1.13"
|
||||||
macroquad = { version = "0.4.13", features = ["audio"] }
|
indicatif = "0.17.9"
|
||||||
quad-snd = "0.2.8"
|
macroquad = "0.4.13"
|
||||||
|
rand = "0.8.5"
|
||||||
[dev-dependencies]
|
|
||||||
rand = "0.9.1"
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 's'
|
opt-level = 's'
|
||||||
|
10
README.md
10
README.md
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
Goal: Generate 'hard' puzzles.
|
Goal: Generate 'hard' puzzles.
|
||||||
|
|
||||||
### Play a demo of the game [here](https://games.neophyte.me/sol_chess/)
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
- Install Rust from [here](https://www.rust-lang.org/tools/install).
|
- Install Rust from [here](https://www.rust-lang.org/tools/install).
|
||||||
@ -14,13 +10,9 @@ Goal: Generate 'hard' puzzles.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
- Run `sol_chess` to start a windowed GUI game.
|
- [WIP] Run `sol_chess` to start a windowed GUI game.
|
||||||
- Run `sol_cli` to start the CLI tool.
|
- Run `sol_cli` to start the CLI tool.
|
||||||
|
|
||||||
## Demo site
|
|
||||||
|
|
||||||
- Play a demo of the game [here](https://games.neophyte.me/sol_chess/)
|
|
||||||
|
|
||||||
## CLI Usage
|
## CLI Usage
|
||||||
|
|
||||||
- Generate a puzzle
|
- Generate a puzzle
|
||||||
|
Binary file not shown.
BIN
assets/click.wav
BIN
assets/click.wav
Binary file not shown.
BIN
assets/loss.wav
BIN
assets/loss.wav
Binary file not shown.
BIN
assets/mode.wav
BIN
assets/mode.wav
Binary file not shown.
BIN
assets/win.wav
BIN
assets/win.wav
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 271 KiB |
@ -1,17 +1,9 @@
|
|||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
|
|
||||||
use sol_chess::board::Board;
|
use sol_chess::board::Board;
|
||||||
use sol_chess::generator::{self, RandomRange};
|
use sol_chess::generator;
|
||||||
use sol_chess::solver::Solver;
|
use sol_chess::solver::Solver;
|
||||||
|
|
||||||
// Learn how to specify a different dependency for this binary
|
|
||||||
struct MacroquadRngTodo;
|
|
||||||
impl RandomRange for MacroquadRngTodo {
|
|
||||||
fn gen_range(&self, min: usize, max: usize) -> usize {
|
|
||||||
macroquad::rand::gen_range(min, max)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Args = argh::from_env();
|
let args: Args = argh::from_env();
|
||||||
|
|
||||||
@ -73,7 +65,7 @@ fn generate_puzzle(num_pieces: Option<u32>, num_solutions: Option<u32>) -> Optio
|
|||||||
"Generating a puzzle with {} pieces with a maximum of {} solutions",
|
"Generating a puzzle with {} pieces with a maximum of {} solutions",
|
||||||
num_pieces, num_solutions
|
num_pieces, num_solutions
|
||||||
);
|
);
|
||||||
let gen = generator::generate(num_pieces, num_solutions, &MacroquadRngTodo);
|
let gen = generator::generate(num_pieces, num_solutions);
|
||||||
gen.print_stats();
|
gen.print_stats();
|
||||||
|
|
||||||
let Some(board) = gen.board() else {
|
let Some(board) = gen.board() else {
|
||||||
|
50
src/board.rs
50
src/board.rs
@ -4,12 +4,7 @@ pub mod errors;
|
|||||||
pub mod piece;
|
pub mod piece;
|
||||||
pub mod square;
|
pub mod square;
|
||||||
|
|
||||||
use core::fmt;
|
use std::{collections::HashSet, mem};
|
||||||
use std::{
|
|
||||||
collections::HashSet,
|
|
||||||
fmt::{Display, Formatter},
|
|
||||||
mem,
|
|
||||||
};
|
|
||||||
|
|
||||||
use cmove::CMove;
|
use cmove::CMove;
|
||||||
use constants::BOARD_SIZE;
|
use constants::BOARD_SIZE;
|
||||||
@ -21,12 +16,12 @@ use square::{Square, SquarePair};
|
|||||||
pub struct Board {
|
pub struct Board {
|
||||||
pub cells: [[Option<Piece>; BOARD_SIZE]; BOARD_SIZE],
|
pub cells: [[Option<Piece>; BOARD_SIZE]; BOARD_SIZE],
|
||||||
pub legal_moves: HashSet<CMove>,
|
pub legal_moves: HashSet<CMove>,
|
||||||
pub game_state: BoardState,
|
pub game_state: GameState,
|
||||||
pieces_remaining: u8,
|
pieces_remaining: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub enum BoardState {
|
pub enum GameState {
|
||||||
NotStarted,
|
NotStarted,
|
||||||
InProgress,
|
InProgress,
|
||||||
Lost,
|
Lost,
|
||||||
@ -39,7 +34,7 @@ impl Board {
|
|||||||
cells: [[None; BOARD_SIZE]; BOARD_SIZE],
|
cells: [[None; BOARD_SIZE]; BOARD_SIZE],
|
||||||
legal_moves: HashSet::new(),
|
legal_moves: HashSet::new(),
|
||||||
pieces_remaining: 0,
|
pieces_remaining: 0,
|
||||||
game_state: BoardState::NotStarted,
|
game_state: GameState::NotStarted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,13 +258,13 @@ impl Board {
|
|||||||
|
|
||||||
fn calc_game_state(&mut self) {
|
fn calc_game_state(&mut self) {
|
||||||
self.game_state = if self.pieces_remaining == 0 {
|
self.game_state = if self.pieces_remaining == 0 {
|
||||||
BoardState::NotStarted
|
GameState::NotStarted
|
||||||
} else if self.pieces_remaining == 1 {
|
} else if self.pieces_remaining == 1 {
|
||||||
BoardState::Won
|
GameState::Won
|
||||||
} else if self.legal_moves.is_empty() {
|
} else if self.legal_moves.is_empty() {
|
||||||
BoardState::Lost
|
GameState::Lost
|
||||||
} else {
|
} else {
|
||||||
BoardState::InProgress
|
GameState::InProgress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,19 +350,6 @@ fn get_square_for_display(piece: &Option<Piece>, pretty: bool) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for BoardState {
|
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
||||||
let display = match self {
|
|
||||||
BoardState::NotStarted => "Not Started",
|
|
||||||
BoardState::InProgress => "In Progress",
|
|
||||||
BoardState::Lost => "Lost",
|
|
||||||
BoardState::Won => "Won",
|
|
||||||
};
|
|
||||||
|
|
||||||
write!(f, "{}", display)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -520,7 +502,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_smoke_puzzle() {
|
fn test_smoke_puzzle() {
|
||||||
let mut board = Board::new();
|
let mut board = Board::new();
|
||||||
assert_eq!(BoardState::NotStarted, board.game_state);
|
assert_eq!(GameState::NotStarted, board.game_state);
|
||||||
assert_eq!(0, board.pieces_remaining);
|
assert_eq!(0, board.pieces_remaining);
|
||||||
|
|
||||||
// K . . .
|
// K . . .
|
||||||
@ -528,22 +510,22 @@ mod tests {
|
|||||||
// . . R .
|
// . . R .
|
||||||
// N . . .
|
// N . . .
|
||||||
board.set(sq!("Ka4"));
|
board.set(sq!("Ka4"));
|
||||||
assert_eq!(BoardState::Won, board.game_state);
|
assert_eq!(GameState::Won, board.game_state);
|
||||||
|
|
||||||
board.set(sq!("Pb3"));
|
board.set(sq!("Pb3"));
|
||||||
board.set(sq!("Rc2"));
|
board.set(sq!("Rc2"));
|
||||||
board.set(sq!("Na1"));
|
board.set(sq!("Na1"));
|
||||||
|
|
||||||
assert_eq!(BoardState::InProgress, board.game_state);
|
assert_eq!(GameState::InProgress, board.game_state);
|
||||||
assert_eq!(4, board.pieces_remaining);
|
assert_eq!(4, board.pieces_remaining);
|
||||||
|
|
||||||
assert!(board.make_move(mv!("Na1", "Rc2")).is_some());
|
assert!(board.make_move(mv!("Na1", "Rc2")).is_some());
|
||||||
assert_eq!(3, board.pieces_remaining);
|
assert_eq!(3, board.pieces_remaining);
|
||||||
assert_eq!(BoardState::InProgress, board.game_state);
|
assert_eq!(GameState::InProgress, board.game_state);
|
||||||
|
|
||||||
assert!(board.make_move(mv!("Pb3", "Ka4")).is_some());
|
assert!(board.make_move(mv!("Pb3", "Ka4")).is_some());
|
||||||
assert_eq!(2, board.pieces_remaining);
|
assert_eq!(2, board.pieces_remaining);
|
||||||
assert_eq!(BoardState::Lost, board.game_state);
|
assert_eq!(GameState::Lost, board.game_state);
|
||||||
|
|
||||||
// P . . .
|
// P . . .
|
||||||
// . . . .
|
// . . . .
|
||||||
@ -558,12 +540,12 @@ mod tests {
|
|||||||
// . . N .
|
// . . N .
|
||||||
// P . . .
|
// P . . .
|
||||||
assert_eq!(4, board.pieces_remaining);
|
assert_eq!(4, board.pieces_remaining);
|
||||||
assert_eq!(BoardState::InProgress, board.game_state);
|
assert_eq!(GameState::InProgress, board.game_state);
|
||||||
|
|
||||||
board.make_move(mv!("Qa3", "Pa4"));
|
board.make_move(mv!("Qa3", "Pa4"));
|
||||||
board.make_move(mv!("Nc2", "Pa1"));
|
board.make_move(mv!("Nc2", "Pa1"));
|
||||||
assert_eq!(2, board.pieces_remaining);
|
assert_eq!(2, board.pieces_remaining);
|
||||||
assert_eq!(BoardState::InProgress, board.game_state);
|
assert_eq!(GameState::InProgress, board.game_state);
|
||||||
|
|
||||||
// Q . . .
|
// Q . . .
|
||||||
// . . . .
|
// . . . .
|
||||||
@ -571,7 +553,7 @@ mod tests {
|
|||||||
// N . . .
|
// N . . .
|
||||||
board.make_move(mv!("Qa4", "Na1"));
|
board.make_move(mv!("Qa4", "Na1"));
|
||||||
assert_eq!(1, board.pieces_remaining);
|
assert_eq!(1, board.pieces_remaining);
|
||||||
assert_eq!(BoardState::Won, board.game_state);
|
assert_eq!(GameState::Won, board.game_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -21,7 +21,7 @@ impl CMove {
|
|||||||
from,
|
from,
|
||||||
to_piece,
|
to_piece,
|
||||||
to,
|
to,
|
||||||
disambig,
|
disambig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
696
src/game.rs
696
src/game.rs
@ -1,697 +1 @@
|
|||||||
use std::{
|
|
||||||
collections::HashMap,
|
|
||||||
fmt::{self, Display, Formatter},
|
|
||||||
};
|
|
||||||
|
|
||||||
use button::Button;
|
|
||||||
use color::UiColor;
|
|
||||||
use macroquad::{audio, math, prelude::*, rand};
|
|
||||||
use shadow::draw_shadow;
|
|
||||||
use sol_chess::{
|
|
||||||
board::{Board, BoardState},
|
|
||||||
generator::{self, RandomRange},
|
|
||||||
};
|
|
||||||
use sound::Sounds;
|
|
||||||
use texture::PieceTexture;
|
|
||||||
|
|
||||||
pub mod button;
|
|
||||||
pub mod color;
|
|
||||||
pub mod shadow;
|
|
||||||
pub mod sound;
|
|
||||||
pub mod texture;
|
pub mod texture;
|
||||||
|
|
||||||
pub struct MacroquadRandAdapter;
|
|
||||||
impl RandomRange for MacroquadRandAdapter {
|
|
||||||
fn gen_range(&self, min: usize, max: usize) -> usize {
|
|
||||||
rand::gen_range(min, max)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Game {
|
|
||||||
// The generated puzzle. We keep a copy of this to reset the game.
|
|
||||||
original_board: Board,
|
|
||||||
|
|
||||||
// What is shown to the user
|
|
||||||
board: Board,
|
|
||||||
|
|
||||||
// Constants througout the game
|
|
||||||
texture_res: Texture2D,
|
|
||||||
sounds: Sounds,
|
|
||||||
num_squares: usize,
|
|
||||||
heading_text: String,
|
|
||||||
|
|
||||||
// Update below on handle input
|
|
||||||
state: GameState,
|
|
||||||
debug: bool,
|
|
||||||
game_mode: GameMode,
|
|
||||||
|
|
||||||
// Update below on window resize
|
|
||||||
// Used for drawing the state
|
|
||||||
square_width: f32,
|
|
||||||
window_height: f32,
|
|
||||||
window_width: f32,
|
|
||||||
board_rect: Rect,
|
|
||||||
squares: Vec<GameSquare>,
|
|
||||||
heading_rect: Rect,
|
|
||||||
heading_font_size: f32,
|
|
||||||
gp_btns: HashMap<ButtonAction, Button>,
|
|
||||||
mode_btns: HashMap<GameMode, Button>,
|
|
||||||
rules: bool,
|
|
||||||
rules_btn: Vec<Button>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct GameSquare {
|
|
||||||
rect: Rect,
|
|
||||||
color: Color,
|
|
||||||
is_source: bool,
|
|
||||||
is_target: bool,
|
|
||||||
is_previous_target: bool,
|
|
||||||
i: usize,
|
|
||||||
j: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
|
||||||
pub enum ButtonAction {
|
|
||||||
Reset,
|
|
||||||
Next,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
|
||||||
pub enum GameMode {
|
|
||||||
Easy,
|
|
||||||
Medium,
|
|
||||||
Hard,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
enum GameState {
|
|
||||||
SelectSource(Option<(usize, usize)>),
|
|
||||||
SelectTarget((usize, usize)),
|
|
||||||
GameOver((usize, usize)),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Game {
|
|
||||||
pub fn new(texture_res: Texture2D, sounds: Sounds) -> Self {
|
|
||||||
let num_squares: usize = 4;
|
|
||||||
let game_mode = GameMode::Medium;
|
|
||||||
let board = Game::generate_puzzle(game_mode);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
original_board: board.clone(),
|
|
||||||
board,
|
|
||||||
board_rect: Rect::new(0., 0., 0., 0.),
|
|
||||||
squares: Vec::new(),
|
|
||||||
heading_rect: Rect::new(0., 0., 0., 0.),
|
|
||||||
heading_text: "Solitaire Chess".to_string(),
|
|
||||||
heading_font_size: 0.,
|
|
||||||
num_squares,
|
|
||||||
texture_res,
|
|
||||||
sounds,
|
|
||||||
state: GameState::SelectSource(None),
|
|
||||||
game_mode,
|
|
||||||
debug: false,
|
|
||||||
gp_btns: HashMap::new(),
|
|
||||||
mode_btns: HashMap::new(),
|
|
||||||
rules: false,
|
|
||||||
rules_btn: Vec::new(),
|
|
||||||
window_height: 0.,
|
|
||||||
window_width: 0.,
|
|
||||||
square_width: 0.,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn draw(&mut self) {
|
|
||||||
self.update_window_size();
|
|
||||||
self.draw_heading();
|
|
||||||
self.draw_board();
|
|
||||||
self.draw_buttons();
|
|
||||||
self.draw_debug();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_window_size(&mut self) {
|
|
||||||
let new_height = math::clamp(screen_height(), 200.0, 10000.0);
|
|
||||||
let new_width = math::clamp(screen_width(), 200.0, 10000.0);
|
|
||||||
if new_height == self.window_height && new_width == self.window_width {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.window_height = new_height;
|
|
||||||
self.window_width = new_width;
|
|
||||||
self.update_drawables();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_input(&mut self) {
|
|
||||||
let mut gp_btn_clicked = None;
|
|
||||||
for btn in &mut self.gp_btns {
|
|
||||||
btn.1.handle_input();
|
|
||||||
if btn.1.is_clicked() {
|
|
||||||
gp_btn_clicked = Some(btn.0.clone());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(action) = gp_btn_clicked {
|
|
||||||
match action {
|
|
||||||
ButtonAction::Reset => self.reset(),
|
|
||||||
ButtonAction::Next => self.next_puzzle(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mut mode_btn_clicked = None;
|
|
||||||
for btn in &mut self.mode_btns {
|
|
||||||
btn.1.handle_input();
|
|
||||||
if btn.1.is_clicked() {
|
|
||||||
mode_btn_clicked = Some(btn);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(btn) = mode_btn_clicked {
|
|
||||||
self.game_mode = *btn.0;
|
|
||||||
self.next_puzzle();
|
|
||||||
} else {
|
|
||||||
let mut rules_btn_clicked = false;
|
|
||||||
for btn in &mut self.rules_btn {
|
|
||||||
btn.handle_input();
|
|
||||||
if btn.is_clicked() {
|
|
||||||
rules_btn_clicked = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rules_btn_clicked {
|
|
||||||
self.rules = !self.rules;
|
|
||||||
if self.rules {
|
|
||||||
self.rules_btn[0].text = "Close".to_string();
|
|
||||||
self.rules_btn[0].color = UiColor::Green;
|
|
||||||
} else {
|
|
||||||
self.rules_btn[0].text = "Rules".to_string();
|
|
||||||
self.rules_btn[0].color = UiColor::Brown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for btn in &mut self.mode_btns {
|
|
||||||
if self.game_mode == *btn.0 {
|
|
||||||
btn.1.is_active = false;
|
|
||||||
} else {
|
|
||||||
btn.1.is_active = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_key_released(KeyCode::Escape) {
|
|
||||||
self.rules = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_key_released(KeyCode::D) {
|
|
||||||
self.debug = !self.debug;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_key_released(KeyCode::Q) {
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_mouse_button_released(MouseButton::Left) {
|
|
||||||
let current_state = self.state.clone();
|
|
||||||
let new_state = match current_state {
|
|
||||||
GameState::SelectSource(previous_target) => {
|
|
||||||
self.handle_select_source(mouse_position(), previous_target)
|
|
||||||
}
|
|
||||||
GameState::SelectTarget(source) => {
|
|
||||||
let next = self.handle_select_target(mouse_position(), source);
|
|
||||||
if let GameState::SelectTarget(_) = next {
|
|
||||||
self.reset_squares();
|
|
||||||
GameState::SelectSource(None)
|
|
||||||
} else {
|
|
||||||
next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GameState::GameOver(previous_target) => GameState::GameOver(previous_target),
|
|
||||||
};
|
|
||||||
self.state = new_state;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_mouse_button_pressed(MouseButton::Left) {
|
|
||||||
let current_state = self.state.clone();
|
|
||||||
let new_state = match current_state {
|
|
||||||
GameState::SelectSource(previous_target) => {
|
|
||||||
self.handle_select_source(mouse_position(), previous_target)
|
|
||||||
}
|
|
||||||
GameState::SelectTarget(source) => GameState::SelectTarget(source),
|
|
||||||
GameState::GameOver(previous_target) => GameState::GameOver(previous_target),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.state = new_state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_heading(&self) {
|
|
||||||
let f = self.heading_font_size.floor() as u16;
|
|
||||||
let dims = measure_text(self.heading_text.as_str(), None, f, 1.0);
|
|
||||||
draw_text(
|
|
||||||
self.heading_text.as_str(),
|
|
||||||
self.heading_rect.x,
|
|
||||||
self.heading_rect.y + dims.offset_y,
|
|
||||||
self.heading_font_size,
|
|
||||||
BLACK,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_board(&self) {
|
|
||||||
let board_shadow_width = 0.1 * self.square_width;
|
|
||||||
draw_shadow(self.board_rect, board_shadow_width);
|
|
||||||
|
|
||||||
if self.rules {
|
|
||||||
draw_rectangle(
|
|
||||||
self.board_rect.x,
|
|
||||||
self.board_rect.y,
|
|
||||||
self.board_rect.w,
|
|
||||||
self.board_rect.h,
|
|
||||||
UiColor::Brown.to_bg_color(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let font_size = self.heading_font_size * 0.8;
|
|
||||||
let rules = "\
|
|
||||||
Every move should be a \n\
|
|
||||||
capture. Win when only \n\
|
|
||||||
one piece is left.\n";
|
|
||||||
let measurement = measure_text(rules, None, font_size as u16, 1.0);
|
|
||||||
draw_multiline_text(
|
|
||||||
rules,
|
|
||||||
self.board_rect.x + 0.05 * self.square_width,
|
|
||||||
self.board_rect.y + 0.5 * (self.board_rect.h - measurement.height)
|
|
||||||
- 2. * measurement.offset_y,
|
|
||||||
font_size,
|
|
||||||
Some(2.),
|
|
||||||
UiColor::Brown.to_fg_color(),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let sprite_size = 0.8 * self.square_width;
|
|
||||||
let mut selected_square = None;
|
|
||||||
self.squares.iter().for_each(|square| {
|
|
||||||
let color = match square.is_source {
|
|
||||||
true => square.color,
|
|
||||||
false => match square.is_target {
|
|
||||||
true => UiColor::Pink.to_shadow_color(),
|
|
||||||
false => square.color,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
draw_rectangle(
|
|
||||||
square.rect.x,
|
|
||||||
square.rect.y,
|
|
||||||
square.rect.w,
|
|
||||||
square.rect.h,
|
|
||||||
color,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(p) = &self.board.cells[square.i][square.j] {
|
|
||||||
let offset = (square.rect.w - sprite_size) / 2.0;
|
|
||||||
let dtp = PieceTexture::for_piece(*p, sprite_size);
|
|
||||||
if !square.is_source {
|
|
||||||
draw_texture_ex(
|
|
||||||
&self.texture_res,
|
|
||||||
square.rect.x + offset,
|
|
||||||
square.rect.y + offset,
|
|
||||||
WHITE,
|
|
||||||
dtp,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
selected_square = Some(square);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(selected_square) = selected_square {
|
|
||||||
if let Some(p) = self.board.cells[selected_square.i][selected_square.j] {
|
|
||||||
let dtp = PieceTexture::for_piece(p, sprite_size);
|
|
||||||
draw_texture_ex(
|
|
||||||
&self.texture_res,
|
|
||||||
mouse_position().0 - sprite_size / 2.0,
|
|
||||||
mouse_position().1 - sprite_size / 2.0,
|
|
||||||
WHITE,
|
|
||||||
dtp,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_buttons(&self) {
|
|
||||||
for btn in &self.gp_btns {
|
|
||||||
btn.1.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
for btn in &self.mode_btns {
|
|
||||||
btn.1.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
for btn in &self.rules_btn {
|
|
||||||
btn.draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_debug(&self) {
|
|
||||||
if self.debug {
|
|
||||||
let mut debug_lines = vec![];
|
|
||||||
let (mx, my) = mouse_position();
|
|
||||||
let hover_square = self.squares.iter().find(|s| {
|
|
||||||
let c = Circle::new(mx, my, 0.0);
|
|
||||||
if c.overlaps_rect(&s.rect) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
debug_lines.push(format!("Game State: {}", self.state));
|
|
||||||
debug_lines.push(format!("Board State: {}", self.board.game_state));
|
|
||||||
if let Some(hover_square) = hover_square {
|
|
||||||
debug_lines.push(format!("Hover: [ {}, {} ]", hover_square.i, hover_square.j));
|
|
||||||
}
|
|
||||||
self.add_debug_info(debug_lines);
|
|
||||||
|
|
||||||
self.show_fps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&mut self, i: usize, j: usize) -> &mut GameSquare {
|
|
||||||
&mut self.squares[i * self.num_squares + j]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_drawables(&mut self) {
|
|
||||||
let min_dimension = f32::min(self.window_height, self.window_width);
|
|
||||||
self.square_width = 0.15 * min_dimension;
|
|
||||||
let board_width = self.square_width * self.num_squares as f32;
|
|
||||||
let board_x = (self.window_width - board_width) / 2.0;
|
|
||||||
let board_y = (self.window_height - board_width) / 2.0;
|
|
||||||
self.board_rect = Rect::new(board_x, board_y, board_width, board_width);
|
|
||||||
|
|
||||||
self.heading_font_size = 0.07 * min_dimension;
|
|
||||||
let f = self.heading_font_size.floor() as u16;
|
|
||||||
let dims = measure_text(self.heading_text.as_str(), None, f, 1.0);
|
|
||||||
self.heading_rect = Rect::new(
|
|
||||||
board_x + (board_width - dims.width) / 2.0,
|
|
||||||
(board_y - dims.height) / 2.0,
|
|
||||||
dims.width,
|
|
||||||
dims.height,
|
|
||||||
);
|
|
||||||
|
|
||||||
let dark = UiColor::Brown.to_bg_color();
|
|
||||||
let light = UiColor::Yellow.to_bg_color();
|
|
||||||
let mut rects = Vec::new();
|
|
||||||
for i in 0..self.num_squares {
|
|
||||||
for j in 0..self.num_squares {
|
|
||||||
let x_eff = board_x + (i as f32 * self.square_width);
|
|
||||||
let y_eff = board_y + (j as f32 * self.square_width);
|
|
||||||
let rect = Rect::new(x_eff, y_eff, self.square_width, self.square_width);
|
|
||||||
let color = match (i + j) % 2 {
|
|
||||||
1 => dark,
|
|
||||||
_ => light,
|
|
||||||
};
|
|
||||||
|
|
||||||
rects.push(GameSquare {
|
|
||||||
rect,
|
|
||||||
color,
|
|
||||||
i,
|
|
||||||
j,
|
|
||||||
is_source: false,
|
|
||||||
is_target: false,
|
|
||||||
is_previous_target: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.squares = rects;
|
|
||||||
|
|
||||||
let btn_h = 0.08 * min_dimension;
|
|
||||||
let btn_w = board_width * 0.2;
|
|
||||||
|
|
||||||
let btn_y = board_width + board_y + 0.3 * self.square_width;
|
|
||||||
let btn_x_offset = 0.5 * (board_width / 2. - btn_w);
|
|
||||||
let reset_btn = Button::new(
|
|
||||||
"Reset",
|
|
||||||
Rect::new(board_x + btn_x_offset, btn_y, btn_w, btn_h),
|
|
||||||
UiColor::Yellow,
|
|
||||||
self.sounds.button.clone(),
|
|
||||||
);
|
|
||||||
let mut next_btn = Button::new(
|
|
||||||
"Next",
|
|
||||||
Rect::new(
|
|
||||||
board_x + (0.5 * board_width) + btn_x_offset,
|
|
||||||
btn_y,
|
|
||||||
btn_w,
|
|
||||||
btn_h,
|
|
||||||
),
|
|
||||||
UiColor::Green,
|
|
||||||
self.sounds.button.clone(),
|
|
||||||
);
|
|
||||||
next_btn.is_active = false;
|
|
||||||
|
|
||||||
let rules_button = Button::new(
|
|
||||||
"Rules",
|
|
||||||
Rect::new(
|
|
||||||
(board_x - btn_w) / 2.,
|
|
||||||
board_y + (self.square_width - btn_h) / 2.,
|
|
||||||
btn_w,
|
|
||||||
btn_h,
|
|
||||||
),
|
|
||||||
UiColor::Brown,
|
|
||||||
self.sounds.button.clone(),
|
|
||||||
);
|
|
||||||
self.rules_btn = vec![rules_button];
|
|
||||||
|
|
||||||
self.gp_btns = HashMap::new();
|
|
||||||
self.gp_btns.insert(ButtonAction::Next, next_btn);
|
|
||||||
self.gp_btns.insert(ButtonAction::Reset, reset_btn);
|
|
||||||
|
|
||||||
let easy_btn = Button::new(
|
|
||||||
"Easy",
|
|
||||||
Rect::new(
|
|
||||||
(board_x - btn_w) / 2.,
|
|
||||||
board_y + self.square_width + (self.square_width - btn_h) / 2.,
|
|
||||||
btn_w,
|
|
||||||
btn_h,
|
|
||||||
),
|
|
||||||
UiColor::Yellow,
|
|
||||||
self.sounds.mode.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let medium_btn = Button::new(
|
|
||||||
"Medium",
|
|
||||||
Rect::new(
|
|
||||||
(board_x - btn_w) / 2.,
|
|
||||||
board_y + 2. * self.square_width + (self.square_width - btn_h) / 2.,
|
|
||||||
btn_w,
|
|
||||||
btn_h,
|
|
||||||
),
|
|
||||||
UiColor::Yellow,
|
|
||||||
self.sounds.mode.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let hard_button = Button::new(
|
|
||||||
"Hard",
|
|
||||||
Rect::new(
|
|
||||||
(board_x - btn_w) / 2.,
|
|
||||||
board_y + 3. * self.square_width + (self.square_width - btn_h) / 2.,
|
|
||||||
btn_w,
|
|
||||||
btn_h,
|
|
||||||
),
|
|
||||||
UiColor::Yellow,
|
|
||||||
self.sounds.mode.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.mode_btns = HashMap::new();
|
|
||||||
self.mode_btns.insert(GameMode::Easy, easy_btn);
|
|
||||||
self.mode_btns.insert(GameMode::Medium, medium_btn);
|
|
||||||
self.mode_btns.insert(GameMode::Hard, hard_button);
|
|
||||||
|
|
||||||
for btn in &mut self.mode_btns {
|
|
||||||
btn.1.is_active = true;
|
|
||||||
if self.game_mode == *btn.0 {
|
|
||||||
btn.1.is_active = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_select_source(
|
|
||||||
&mut self,
|
|
||||||
mouse_position: (f32, f32),
|
|
||||||
previous_target: Option<(usize, usize)>,
|
|
||||||
) -> GameState {
|
|
||||||
self.reset_squares();
|
|
||||||
let (x, y) = mouse_position;
|
|
||||||
let mouse = Circle::new(x, y, 0.0);
|
|
||||||
let mut selected = None;
|
|
||||||
for square in &mut self.squares {
|
|
||||||
if mouse.overlaps_rect(&square.rect) {
|
|
||||||
if let Some(_) = self.board.cells[square.i][square.j] {
|
|
||||||
selected = Some((square.i, square.j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((i, j)) = selected {
|
|
||||||
self.get(i, j).is_source = true;
|
|
||||||
let mut target_squares = vec![];
|
|
||||||
for m in self.board.legal_moves.iter() {
|
|
||||||
if m.from.file == i && m.from.rank == j {
|
|
||||||
target_squares.push((m.to.file, m.to.rank));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i, j) in target_squares {
|
|
||||||
self.get(i, j).is_target = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GameState::SelectTarget(selected.unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((i, j)) = previous_target {
|
|
||||||
self.get(i, j).is_previous_target = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GameState::SelectSource(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_select_target(
|
|
||||||
&mut self,
|
|
||||||
mouse_position: (f32, f32),
|
|
||||||
source: (usize, usize),
|
|
||||||
) -> GameState {
|
|
||||||
let (x, y) = mouse_position;
|
|
||||||
let mouse = Circle::new(x, y, 0.0);
|
|
||||||
|
|
||||||
let mut selected = None;
|
|
||||||
for square in &mut self.squares {
|
|
||||||
if mouse.overlaps_rect(&square.rect) {
|
|
||||||
if let Some(_) = self.board.cells[square.i][square.j] {
|
|
||||||
selected = Some((square.i, square.j));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (s_x, s_y) = source;
|
|
||||||
let Some((x, y)) = selected else {
|
|
||||||
self.get(s_x, s_y).is_source = true;
|
|
||||||
return GameState::SelectTarget(source);
|
|
||||||
};
|
|
||||||
|
|
||||||
if x == s_x && y == s_y {
|
|
||||||
self.get(s_x, s_y).is_source = true;
|
|
||||||
return GameState::SelectTarget(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut is_legal = false;
|
|
||||||
if self.get(x, y).is_target {
|
|
||||||
is_legal = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_legal {
|
|
||||||
let m = self.board.legal_moves.iter().find(|m| {
|
|
||||||
m.from.file == s_x && m.from.rank == s_y && m.to.file == x && m.to.rank == y
|
|
||||||
});
|
|
||||||
|
|
||||||
let m = m.expect("legal move should be found");
|
|
||||||
self.board.make_move(m.clone());
|
|
||||||
|
|
||||||
if self.board.game_state == BoardState::Won || self.board.game_state == BoardState::Lost
|
|
||||||
{
|
|
||||||
self.reset_squares();
|
|
||||||
if self.board.game_state == BoardState::Won {
|
|
||||||
let next_btn = self
|
|
||||||
.gp_btns
|
|
||||||
.get_mut(&ButtonAction::Next)
|
|
||||||
.expect("Cannot find next button");
|
|
||||||
next_btn.is_active = true;
|
|
||||||
audio::play_sound_once(&self.sounds.win);
|
|
||||||
} else {
|
|
||||||
audio::play_sound_once(&self.sounds.loss);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GameState::GameOver((x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.reset_squares();
|
|
||||||
self.get(x, y).is_target = true;
|
|
||||||
audio::play_sound_once(&self.sounds.click);
|
|
||||||
return GameState::SelectSource(Some((x, y)));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.reset_squares();
|
|
||||||
return GameState::SelectSource(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reset(&mut self) {
|
|
||||||
self.board = self.original_board.clone();
|
|
||||||
self.reset_squares();
|
|
||||||
|
|
||||||
let next_button = self
|
|
||||||
.gp_btns
|
|
||||||
.get_mut(&ButtonAction::Next)
|
|
||||||
.expect("Cannot find next button");
|
|
||||||
next_button.is_active = false;
|
|
||||||
|
|
||||||
self.state = GameState::SelectSource(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next_puzzle(&mut self) {
|
|
||||||
self.reset();
|
|
||||||
let board = Game::generate_puzzle(self.game_mode);
|
|
||||||
self.original_board = board.clone();
|
|
||||||
self.board = board;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reset_squares(&mut self) {
|
|
||||||
for i in 0..self.num_squares {
|
|
||||||
for j in 0..self.num_squares {
|
|
||||||
self.get(i, j).is_source = false;
|
|
||||||
self.get(i, j).is_target = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_debug_info(&self, lines: Vec<String>) {
|
|
||||||
let mut y = 20.0;
|
|
||||||
for line in lines {
|
|
||||||
draw_text(&line, 10.0, y, 20.0, BLACK);
|
|
||||||
y += 25.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_fps(&self) {
|
|
||||||
let fps = get_fps();
|
|
||||||
draw_text(
|
|
||||||
&format!("FPS: {}", fps),
|
|
||||||
10.0,
|
|
||||||
screen_height() - 20.0,
|
|
||||||
20.0,
|
|
||||||
BLACK,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_puzzle(mode: GameMode) -> Board {
|
|
||||||
let piece_count = match mode {
|
|
||||||
GameMode::Easy => 3,
|
|
||||||
GameMode::Medium => 5,
|
|
||||||
GameMode::Hard => 7,
|
|
||||||
};
|
|
||||||
|
|
||||||
let generate = generator::generate(piece_count, 100, &MacroquadRandAdapter);
|
|
||||||
generate.board().expect("No puzzle was generated")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for GameState {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
GameState::SelectSource(Some(x)) => write!(f, "Select Source [ {}, {} ]", x.0, x.1),
|
|
||||||
GameState::SelectSource(None) => write!(f, "Select Source [ ]"),
|
|
||||||
GameState::SelectTarget(x) => write!(f, "Select Target [ {}, {} ]", x.0, x.1),
|
|
||||||
GameState::GameOver(x) => write!(f, "Game Over [ {}, {} ]", x.0, x.1),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
use macroquad::{audio::{self, Sound}, prelude::*};
|
|
||||||
|
|
||||||
use super::{color::UiColor, shadow::draw_shadow};
|
|
||||||
|
|
||||||
pub struct Button {
|
|
||||||
pub is_active: bool,
|
|
||||||
pub text: String,
|
|
||||||
is_down: bool,
|
|
||||||
is_clicked: bool,
|
|
||||||
rect: Rect,
|
|
||||||
shadow_width: f32,
|
|
||||||
pub color: UiColor,
|
|
||||||
sound: Sound,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Button {
|
|
||||||
pub fn new(text: &str, rect: Rect, color: UiColor, sound: Sound) -> Self {
|
|
||||||
Self {
|
|
||||||
text: text.to_string(),
|
|
||||||
is_down: false,
|
|
||||||
is_clicked: false,
|
|
||||||
is_active: true,
|
|
||||||
rect,
|
|
||||||
shadow_width: 5.0,
|
|
||||||
color,
|
|
||||||
sound,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_clicked(&mut self) -> bool {
|
|
||||||
if self.is_clicked {
|
|
||||||
self.is_clicked = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn draw(&self) {
|
|
||||||
self.draw_button();
|
|
||||||
self.draw_label();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_button(&self) {
|
|
||||||
let bg_color = match self.is_active {
|
|
||||||
true => self.color.to_bg_color(),
|
|
||||||
false => self.color.to_shadow_color(),
|
|
||||||
};
|
|
||||||
let button_draw_offset = self.get_button_draw_offset();
|
|
||||||
draw_rectangle(
|
|
||||||
self.rect.x + button_draw_offset,
|
|
||||||
self.rect.y + button_draw_offset,
|
|
||||||
self.rect.w,
|
|
||||||
self.rect.h,
|
|
||||||
bg_color,
|
|
||||||
);
|
|
||||||
|
|
||||||
self.draw_shadow();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_shadow(&self) {
|
|
||||||
if !self.is_active {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_down {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_shadow(self.rect, self.shadow_width);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_label(&self) {
|
|
||||||
let font_color = match self.is_active {
|
|
||||||
true => self.color.to_fg_color(),
|
|
||||||
false => Color::from_rgba(100, 100, 100, 255),
|
|
||||||
};
|
|
||||||
|
|
||||||
let font_size = (0.3 * self.rect.w) as u16;
|
|
||||||
let dims = measure_text(&self.text, None, font_size, 1.0);
|
|
||||||
let button_draw_offset = self.get_button_draw_offset();
|
|
||||||
|
|
||||||
draw_text(
|
|
||||||
&self.text,
|
|
||||||
self.rect.x + (self.rect.w - dims.width) * 0.5 + button_draw_offset,
|
|
||||||
self.rect.y + (self.rect.h - dims.height) * 0.5 + dims.offset_y + button_draw_offset,
|
|
||||||
font_size as f32,
|
|
||||||
font_color,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_button_draw_offset(&self) -> f32 {
|
|
||||||
let button_pressed_correction = match self.is_down {
|
|
||||||
true => self.shadow_width,
|
|
||||||
false => match self.is_active {
|
|
||||||
true => 0.0,
|
|
||||||
false => self.shadow_width,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
button_pressed_correction
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_input(&mut self) {
|
|
||||||
if !self.is_active {
|
|
||||||
self.is_down = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (mx, my) = mouse_position();
|
|
||||||
let c = Circle::new(mx, my, 0.0);
|
|
||||||
|
|
||||||
if is_mouse_button_pressed(MouseButton::Left) {
|
|
||||||
if c.overlaps_rect(&self.rect) {
|
|
||||||
self.is_down = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_mouse_button_released(MouseButton::Left) {
|
|
||||||
if c.overlaps_rect(&self.rect) {
|
|
||||||
self.is_clicked = true;
|
|
||||||
audio::play_sound_once(&self.sound);
|
|
||||||
self.is_down = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.is_down = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
use macroquad::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub enum UiColor {
|
|
||||||
Grey,
|
|
||||||
Green,
|
|
||||||
Pink,
|
|
||||||
Brown,
|
|
||||||
Yellow,
|
|
||||||
Blue,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UiColor {
|
|
||||||
pub fn to_bg_color(&self) -> Color {
|
|
||||||
match self {
|
|
||||||
UiColor::Grey => Color::from_rgba(140, 140, 140, 200),
|
|
||||||
UiColor::Green => Color::from_rgba(16, 60, 50, 200),
|
|
||||||
UiColor::Pink => Color::from_rgba(234, 128, 71, 200),
|
|
||||||
UiColor::Brown => Color::from_rgba(123, 61, 35, 200),
|
|
||||||
UiColor::Yellow => Color::from_rgba(242, 230, 190, 200),
|
|
||||||
UiColor::Blue => Color::from_rgba(47, 85, 172, 200),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_fg_color(&self) -> Color {
|
|
||||||
match self {
|
|
||||||
UiColor::Grey => Color::from_rgba(255, 255, 255, 200),
|
|
||||||
UiColor::Green => Color::from_rgba(255, 255, 255, 200),
|
|
||||||
UiColor::Pink => Color::from_rgba(255, 255, 255, 200),
|
|
||||||
UiColor::Brown => Color::from_rgba(255, 255, 255, 200),
|
|
||||||
UiColor::Yellow => Color::from_rgba(0, 0, 0, 200),
|
|
||||||
UiColor::Blue => Color::from_rgba(255, 255, 255, 200),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_shadow_color(&self) -> Color {
|
|
||||||
let bg_color = self.to_bg_color();
|
|
||||||
Color::from_rgba(
|
|
||||||
(bg_color.r * 255.) as u8,
|
|
||||||
(bg_color.g * 255.) as u8,
|
|
||||||
(bg_color.b * 255.) as u8,
|
|
||||||
100,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
use macroquad::prelude::*;
|
|
||||||
|
|
||||||
pub fn draw_shadow(rect: Rect, shadow_width: f32) {
|
|
||||||
let shadow_color = Color::new(0., 0., 0., 0.8);
|
|
||||||
draw_rectangle(
|
|
||||||
rect.x + rect.w,
|
|
||||||
rect.y + shadow_width,
|
|
||||||
shadow_width,
|
|
||||||
rect.h,
|
|
||||||
shadow_color,
|
|
||||||
);
|
|
||||||
|
|
||||||
draw_rectangle(
|
|
||||||
rect.x + shadow_width,
|
|
||||||
rect.y + rect.h,
|
|
||||||
rect.w - shadow_width,
|
|
||||||
shadow_width,
|
|
||||||
shadow_color,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
use macroquad::audio::Sound;
|
|
||||||
|
|
||||||
pub struct Sounds {
|
|
||||||
pub click: Sound,
|
|
||||||
pub win: Sound,
|
|
||||||
pub loss: Sound,
|
|
||||||
pub button: Sound,
|
|
||||||
pub mode: Sound,
|
|
||||||
}
|
|
@ -1,15 +1,14 @@
|
|||||||
use std::fmt::Display;
|
use std::{fmt::Display, time::Duration};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
board::{piece::Piece, Board},
|
board::{piece::Piece, Board},
|
||||||
solver::Solver,
|
solver::Solver,
|
||||||
};
|
};
|
||||||
|
use indicatif::ProgressBar;
|
||||||
|
use rand::{seq::*, Rng};
|
||||||
|
|
||||||
pub trait RandomRange {
|
pub fn generate(num_pieces: u32, num_solutions: u32) -> GenerateStats {
|
||||||
fn gen_range(&self, min: usize, max: usize) -> usize;
|
let rand = rand::thread_rng();
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate(num_pieces: u32, num_solutions: u32, rand: &impl RandomRange) -> GenerateStats {
|
|
||||||
let candidate_pieces = vec![
|
let candidate_pieces = vec![
|
||||||
Piece::Pawn,
|
Piece::Pawn,
|
||||||
Piece::Pawn,
|
Piece::Pawn,
|
||||||
@ -35,18 +34,31 @@ pub fn generate(num_pieces: u32, num_solutions: u32, rand: &impl RandomRange) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
let attempts: u32 = 1000;
|
let attempts: u32 = 1000;
|
||||||
let mut overall_stats = GenerateStats::new(0, 0, 0, None);
|
let bar = ProgressBar::new_spinner();
|
||||||
|
bar.enable_steady_tick(Duration::from_millis(100));
|
||||||
|
let mut overall_stats = GenerateStats::new(0, 0, 0, 0, None);
|
||||||
for _ in 0..attempts {
|
for _ in 0..attempts {
|
||||||
let stats = try_generate(num_pieces, num_solutions, rand, candidate_pieces.clone());
|
let stats = try_generate(
|
||||||
|
num_pieces,
|
||||||
|
num_solutions,
|
||||||
|
candidate_pieces.clone(),
|
||||||
|
rand.clone(),
|
||||||
|
);
|
||||||
overall_stats.piece_total += stats.piece_total;
|
overall_stats.piece_total += stats.piece_total;
|
||||||
overall_stats.piece_success += stats.piece_success;
|
overall_stats.piece_success += stats.piece_success;
|
||||||
overall_stats.total += stats.total;
|
overall_stats.total += stats.total;
|
||||||
|
overall_stats.total_millis += stats.total_millis;
|
||||||
overall_stats.board = stats.board;
|
overall_stats.board = stats.board;
|
||||||
|
bar.set_message(format!(
|
||||||
|
"Generating puzzle.. Elapsed: {}s",
|
||||||
|
overall_stats.total_millis / 1000
|
||||||
|
));
|
||||||
if overall_stats.board.is_some() {
|
if overall_stats.board.is_some() {
|
||||||
return overall_stats;
|
return overall_stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bar.finish_and_clear();
|
||||||
overall_stats
|
overall_stats
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,15 +66,23 @@ pub struct GenerateStats {
|
|||||||
piece_total: u32,
|
piece_total: u32,
|
||||||
piece_success: u32,
|
piece_success: u32,
|
||||||
total: u32,
|
total: u32,
|
||||||
|
total_millis: u128,
|
||||||
board: Option<Board>,
|
board: Option<Board>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GenerateStats {
|
impl GenerateStats {
|
||||||
fn new(piece_total: u32, piece_success: u32, total: u32, board: Option<Board>) -> Self {
|
fn new(
|
||||||
|
piece_total: u32,
|
||||||
|
piece_success: u32,
|
||||||
|
total: u32,
|
||||||
|
total_millis: u128,
|
||||||
|
board: Option<Board>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
piece_total,
|
piece_total,
|
||||||
piece_success,
|
piece_success,
|
||||||
total,
|
total,
|
||||||
|
total_millis,
|
||||||
board,
|
board,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,6 +92,7 @@ impl GenerateStats {
|
|||||||
add_stat(&mut stats, "Total attempts", self.total);
|
add_stat(&mut stats, "Total attempts", self.total);
|
||||||
add_stat(&mut stats, "Total pieces placed", self.piece_total);
|
add_stat(&mut stats, "Total pieces placed", self.piece_total);
|
||||||
add_stat(&mut stats, "Success pieces placed", self.piece_success);
|
add_stat(&mut stats, "Success pieces placed", self.piece_success);
|
||||||
|
add_stat(&mut stats, "Total time (ms)", self.total_millis);
|
||||||
|
|
||||||
println!("{}", stats);
|
println!("{}", stats);
|
||||||
}
|
}
|
||||||
@ -91,28 +112,29 @@ where
|
|||||||
fn try_generate(
|
fn try_generate(
|
||||||
num_pieces: u32,
|
num_pieces: u32,
|
||||||
num_solutions: u32,
|
num_solutions: u32,
|
||||||
rand: &impl RandomRange,
|
|
||||||
mut candidate_pieces: Vec<Piece>,
|
mut candidate_pieces: Vec<Piece>,
|
||||||
|
mut rand: rand::prelude::ThreadRng,
|
||||||
) -> GenerateStats {
|
) -> GenerateStats {
|
||||||
let mut board = Board::new();
|
let mut board = Board::new();
|
||||||
let mut piece_total = 0;
|
let mut piece_total = 0;
|
||||||
let mut piece_success = 0;
|
let mut piece_success = 0;
|
||||||
|
let now = std::time::Instant::now();
|
||||||
for _ in 0..num_pieces {
|
for _ in 0..num_pieces {
|
||||||
let mut placed = false;
|
let mut placed = false;
|
||||||
let empty_squares = board.empty_squares();
|
let empty_squares = board.empty_squares();
|
||||||
let mut attempts = 15;
|
let mut attempts = 15;
|
||||||
while !placed {
|
while !placed {
|
||||||
if attempts == 0 {
|
if attempts == 0 {
|
||||||
return GenerateStats::new(piece_total, piece_success, 1, None);
|
let elapsed = now.elapsed().as_millis();
|
||||||
|
return GenerateStats::new(piece_total, piece_success, 1, elapsed, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
attempts -= 1;
|
attempts -= 1;
|
||||||
piece_total += 1;
|
piece_total += 1;
|
||||||
|
|
||||||
let index = rand.gen_range(0, candidate_pieces.len());
|
let index = rand.gen_range(0..candidate_pieces.len());
|
||||||
let piece = candidate_pieces[index];
|
let piece = candidate_pieces[index];
|
||||||
let square_index = rand.gen_range(0, empty_squares.len());
|
let mut random_square = empty_squares.choose(&mut rand).unwrap().clone();
|
||||||
let mut random_square = empty_squares[square_index].clone();
|
|
||||||
random_square.piece = Some(piece);
|
random_square.piece = Some(piece);
|
||||||
board.set(random_square.clone());
|
board.set(random_square.clone());
|
||||||
let solutions = Solver::new(board.clone()).solve();
|
let solutions = Solver::new(board.clone()).solve();
|
||||||
@ -129,34 +151,26 @@ fn try_generate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let solutions = Solver::new(board.clone()).solve();
|
let solutions = Solver::new(board.clone()).solve();
|
||||||
|
let elapsed = now.elapsed().as_millis();
|
||||||
if solutions.len() > num_solutions as usize {
|
if solutions.len() > num_solutions as usize {
|
||||||
GenerateStats::new(piece_total, piece_success, 1, None)
|
GenerateStats::new(piece_total, piece_success, 1, elapsed, None)
|
||||||
} else {
|
} else {
|
||||||
GenerateStats::new(piece_total, piece_success, 1, Some(board))
|
GenerateStats::new(piece_total, piece_success, 1, elapsed, Some(board))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{board::BoardState, solver::Solver};
|
use crate::{board::GameState, solver::Solver};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
struct TestRandom;
|
|
||||||
impl RandomRange for TestRandom {
|
|
||||||
fn gen_range(&self, min: usize, max: usize) -> usize {
|
|
||||||
rand::rng().random_range(min..max)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generator_smoke() {
|
fn generator_smoke() {
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let gen_stats = generate(5, 5, &TestRandom);
|
let gen_stats = generate(5, 5);
|
||||||
let board = gen_stats.board.expect("No puzzle was generated");
|
let board = gen_stats.board.expect("No puzzle was generated");
|
||||||
assert_eq!(board.game_state, BoardState::InProgress);
|
assert_eq!(board.game_state, GameState::InProgress);
|
||||||
|
|
||||||
let solutions = Solver::new(board).solve();
|
let solutions = Solver::new(board).solve();
|
||||||
assert!(solutions.len() <= 5);
|
assert!(solutions.len() <= 5);
|
||||||
|
142
src/main.rs
142
src/main.rs
@ -1,54 +1,122 @@
|
|||||||
use game::{sound::Sounds, Game};
|
use game::texture::PieceTexture;
|
||||||
use macroquad::{audio, prelude::*};
|
use macroquad::prelude::*;
|
||||||
use miniquad::date;
|
use sol_chess::board::{square::Square, Board};
|
||||||
|
|
||||||
mod game;
|
mod game;
|
||||||
|
|
||||||
fn window_conf() -> Conf {
|
#[macroquad::main("Solitaire Chess")]
|
||||||
let window_name = match std::env::var("TESTING") {
|
|
||||||
Ok(_) => "DEV TESTING MOVE TO WORKSPACE 10",
|
|
||||||
Err(_) => "Solitaire Chess",
|
|
||||||
};
|
|
||||||
|
|
||||||
Conf {
|
|
||||||
window_title: window_name.to_string(),
|
|
||||||
fullscreen: false,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macroquad::main(window_conf)]
|
|
||||||
async fn main() {
|
async fn main() {
|
||||||
rand::srand(date::now() as u64);
|
|
||||||
let background_color = Color::from_rgba(196, 195, 208, 255);
|
let background_color = Color::from_rgba(196, 195, 208, 255);
|
||||||
let mut game = init().await;
|
let game = init().await;
|
||||||
loop {
|
loop {
|
||||||
clear_background(background_color);
|
clear_background(background_color);
|
||||||
game.handle_input();
|
|
||||||
game.draw();
|
game.draw();
|
||||||
next_frame().await
|
next_frame().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! load_sound {
|
|
||||||
($file_name:expr) => {
|
|
||||||
audio::load_sound_from_bytes(include_bytes!($file_name))
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn init() -> Game {
|
async fn init() -> Game {
|
||||||
let texture_bytes = include_bytes!("../assets/pieces.png");
|
set_pc_assets_folder("./assets");
|
||||||
let texture_res = Texture2D::from_file_with_format(&texture_bytes[..], None);
|
let texture_res = load_texture("pieces.png").await.unwrap();
|
||||||
texture_res.set_filter(FilterMode::Nearest);
|
texture_res.set_filter(FilterMode::Nearest);
|
||||||
build_textures_atlas();
|
build_textures_atlas();
|
||||||
let click = load_sound!("../assets/click.wav");
|
let mut board = Board::new();
|
||||||
let win = load_sound!("../assets/win.wav");
|
board.set(Square::parse("Pa4"));
|
||||||
let loss = load_sound!("../assets/loss.wav");
|
board.set(Square::parse("Pa3"));
|
||||||
let button = load_sound!("../assets/button.wav");
|
board.set(Square::parse("Na2"));
|
||||||
let mode = load_sound!("../assets/mode.wav");
|
board.set(Square::parse("Na1"));
|
||||||
let sounds = Sounds { click, win, loss, button, mode };
|
board.set(Square::parse("Bb4"));
|
||||||
let game = Game::new(texture_res, sounds);
|
board.set(Square::parse("Bb3"));
|
||||||
|
board.set(Square::parse("Rb2"));
|
||||||
|
board.set(Square::parse("Rb1"));
|
||||||
|
board.set(Square::parse("Kc4"));
|
||||||
|
board.set(Square::parse("Kc3"));
|
||||||
|
board.set(Square::parse("Qc2"));
|
||||||
|
board.set(Square::parse("Qc1"));
|
||||||
|
|
||||||
|
let square_width = 128.0;
|
||||||
|
let num_squares = 4;
|
||||||
|
let x = (screen_width() - (square_width * num_squares as f32)) / 2.0;
|
||||||
|
let y = (screen_height() - (square_width * num_squares as f32)) / 2.0;
|
||||||
|
let game = Game::new(board, x, y, square_width, num_squares, texture_res);
|
||||||
|
|
||||||
game
|
game
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Game {
|
||||||
|
board: Board,
|
||||||
|
squares: Vec<GameSquare>,
|
||||||
|
texture_res: Texture2D,
|
||||||
|
num_squares: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Game {
|
||||||
|
fn new(
|
||||||
|
board: Board,
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
square_width: f32,
|
||||||
|
num_squares: usize,
|
||||||
|
texture_res: Texture2D,
|
||||||
|
) -> Self {
|
||||||
|
let dark = Color::from_rgba(83, 104, 120, 255);
|
||||||
|
let light = Color::from_rgba(190, 190, 190, 255);
|
||||||
|
let mut rects = Vec::new();
|
||||||
|
for i in 0..num_squares {
|
||||||
|
for j in 0..num_squares {
|
||||||
|
let x_eff = x + (i as f32 * square_width);
|
||||||
|
let y_eff = y + (j as f32 * square_width);
|
||||||
|
let rect = Rect::new(x_eff, y_eff, square_width, square_width);
|
||||||
|
let color = match (i + j) % 2 {
|
||||||
|
1 => dark,
|
||||||
|
_ => light,
|
||||||
|
};
|
||||||
|
|
||||||
|
rects.push(GameSquare { rect, color, i, j });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
board,
|
||||||
|
squares: rects,
|
||||||
|
num_squares,
|
||||||
|
texture_res,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get(&mut self, i: usize, j: usize) -> &mut GameSquare {
|
||||||
|
&mut self.squares[i * self.num_squares + j]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&self) {
|
||||||
|
let sprite_size = 100.0;
|
||||||
|
self.squares.iter().for_each(|square| {
|
||||||
|
draw_rectangle(
|
||||||
|
square.rect.x,
|
||||||
|
square.rect.y,
|
||||||
|
square.rect.w,
|
||||||
|
square.rect.h,
|
||||||
|
square.color,
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(p) = &self.board.cells[square.i][square.j] {
|
||||||
|
let offset = (square.rect.w - sprite_size) / 2.0;
|
||||||
|
let dtp = PieceTexture::for_piece(*p, sprite_size);
|
||||||
|
draw_texture_ex(
|
||||||
|
&self.texture_res,
|
||||||
|
square.rect.x + offset,
|
||||||
|
square.rect.y + offset,
|
||||||
|
WHITE,
|
||||||
|
dtp,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GameSquare {
|
||||||
|
rect: Rect,
|
||||||
|
color: Color,
|
||||||
|
i: usize,
|
||||||
|
j: usize,
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::board::{
|
use crate::board::{
|
||||||
cmove::CMove,
|
cmove::CMove,
|
||||||
{Board, BoardState},
|
{Board, GameState},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Solver {
|
pub struct Solver {
|
||||||
@ -26,12 +26,12 @@ impl Solver {
|
|||||||
|
|
||||||
pub fn solve(&self) -> Vec<Vec<CMove>> {
|
pub fn solve(&self) -> Vec<Vec<CMove>> {
|
||||||
let mut solutions = Vec::new();
|
let mut solutions = Vec::new();
|
||||||
if let BoardState::Won = self.board.game_state {
|
if let GameState::Won = self.board.game_state {
|
||||||
solutions.push(self.moves.clone());
|
solutions.push(self.moves.clone());
|
||||||
return solutions;
|
return solutions;
|
||||||
}
|
}
|
||||||
|
|
||||||
let BoardState::InProgress = self.board.game_state else {
|
let GameState::InProgress = self.board.game_state else {
|
||||||
return solutions;
|
return solutions;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ mod tests {
|
|||||||
solution
|
solution
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|m| assert!(board.make_move(m).is_some()));
|
.for_each(|m| assert!(board.make_move(m).is_some()));
|
||||||
assert_eq!(BoardState::Won, board.game_state);
|
assert_eq!(GameState::Won, board.game_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
tools/puzzle_checker/games/1.txt
Normal file
26
tools/puzzle_checker/games/1.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 1 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 328
|
||||||
|
Total pieces placed: 3363
|
||||||
|
Success pieces placed: 2296
|
||||||
|
Total time (ms): 1840
|
||||||
|
|
||||||
|
♗ ♗ ♙ ♘
|
||||||
|
|
||||||
|
. . . ♖
|
||||||
|
|
||||||
|
. . ♙ .
|
||||||
|
|
||||||
|
. . . ♙
|
||||||
|
|
||||||
|
|
||||||
|
id: 140771860875974
|
||||||
|
|
||||||
|
Found 1 solutions
|
||||||
|
1. BxPc2
|
||||||
|
2. BxPd1
|
||||||
|
3. RxBd1
|
||||||
|
4. RxNd4
|
||||||
|
5. RxPc4
|
||||||
|
6. RxBb4
|
26
tools/puzzle_checker/games/10.txt
Normal file
26
tools/puzzle_checker/games/10.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 10 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 43
|
||||||
|
Total pieces placed: 407
|
||||||
|
Success pieces placed: 301
|
||||||
|
Total time (ms): 238
|
||||||
|
|
||||||
|
♙ . ♖ .
|
||||||
|
|
||||||
|
. . ♘ ♙
|
||||||
|
|
||||||
|
. ♙ ♘ .
|
||||||
|
|
||||||
|
♗ . . .
|
||||||
|
|
||||||
|
|
||||||
|
id: 211381923512704
|
||||||
|
|
||||||
|
Found 4 solutions
|
||||||
|
1. BxPb2
|
||||||
|
2. NxPa4
|
||||||
|
3. RxNc2
|
||||||
|
4. RxBb2
|
||||||
|
5. NxRb2
|
||||||
|
6. NxPd3
|
26
tools/puzzle_checker/games/2.txt
Normal file
26
tools/puzzle_checker/games/2.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 2 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 47
|
||||||
|
Total pieces placed: 473
|
||||||
|
Success pieces placed: 329
|
||||||
|
Total time (ms): 279
|
||||||
|
|
||||||
|
. . . ♗
|
||||||
|
|
||||||
|
♘ . ♗ .
|
||||||
|
|
||||||
|
♙ . . .
|
||||||
|
|
||||||
|
. ♘ ♖ ♗
|
||||||
|
|
||||||
|
|
||||||
|
id: 25288852387844
|
||||||
|
|
||||||
|
Found 4 solutions
|
||||||
|
1. RxBd1
|
||||||
|
2. BxBc3
|
||||||
|
3. RxNb1
|
||||||
|
4. NxRb1
|
||||||
|
5. NxBc3
|
||||||
|
6. NxPa2
|
26
tools/puzzle_checker/games/3.txt
Normal file
26
tools/puzzle_checker/games/3.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 3 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 22
|
||||||
|
Total pieces placed: 239
|
||||||
|
Success pieces placed: 154
|
||||||
|
Total time (ms): 160
|
||||||
|
|
||||||
|
♗ . ♖ ♙
|
||||||
|
|
||||||
|
. . . ♙
|
||||||
|
|
||||||
|
. . . ♙
|
||||||
|
|
||||||
|
. ♙ . ♗
|
||||||
|
|
||||||
|
|
||||||
|
id: 140737595313588
|
||||||
|
|
||||||
|
Found 5 solutions
|
||||||
|
1. RxBa4
|
||||||
|
2. RxPd4
|
||||||
|
3. RxPd3
|
||||||
|
4. RxPd2
|
||||||
|
5. RxBd1
|
||||||
|
6. RxPb1
|
26
tools/puzzle_checker/games/4.txt
Normal file
26
tools/puzzle_checker/games/4.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 4 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 200
|
||||||
|
Total pieces placed: 2059
|
||||||
|
Success pieces placed: 1388
|
||||||
|
Total time (ms): 929
|
||||||
|
|
||||||
|
♙ ♘ . ♗
|
||||||
|
|
||||||
|
. ♖ ♙ ♘
|
||||||
|
|
||||||
|
. . . .
|
||||||
|
|
||||||
|
. . ♙ .
|
||||||
|
|
||||||
|
|
||||||
|
id: 211152405031232
|
||||||
|
|
||||||
|
Found 1 solutions
|
||||||
|
1. RxNb4
|
||||||
|
2. RxPa4
|
||||||
|
3. RxBd4
|
||||||
|
4. RxNd3
|
||||||
|
5. RxPc3
|
||||||
|
6. RxPc1
|
26
tools/puzzle_checker/games/5.txt
Normal file
26
tools/puzzle_checker/games/5.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 5 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 74
|
||||||
|
Total pieces placed: 771
|
||||||
|
Success pieces placed: 512
|
||||||
|
Total time (ms): 437
|
||||||
|
|
||||||
|
♗ ♙ . ♘
|
||||||
|
|
||||||
|
. ♖ . ♘
|
||||||
|
|
||||||
|
. . . .
|
||||||
|
|
||||||
|
. ♗ ♗ .
|
||||||
|
|
||||||
|
|
||||||
|
id: 140792316316480
|
||||||
|
|
||||||
|
Found 4 solutions
|
||||||
|
1. BxRb3
|
||||||
|
2. BxNd3
|
||||||
|
3. NxBb3
|
||||||
|
4. NxBc1
|
||||||
|
5. NxBd3
|
||||||
|
6. NxPb4
|
26
tools/puzzle_checker/games/6.txt
Normal file
26
tools/puzzle_checker/games/6.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 6 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 1
|
||||||
|
Total pieces placed: 9
|
||||||
|
Success pieces placed: 7
|
||||||
|
Total time (ms): 0
|
||||||
|
|
||||||
|
. ♙ . .
|
||||||
|
|
||||||
|
. . . .
|
||||||
|
|
||||||
|
♗ . ♗ ♗
|
||||||
|
|
||||||
|
♖ ♙ . ♘
|
||||||
|
|
||||||
|
|
||||||
|
id: 2456822087717
|
||||||
|
|
||||||
|
Found 5 solutions
|
||||||
|
1. RxBa2
|
||||||
|
2. RxBc2
|
||||||
|
3. RxBd2
|
||||||
|
4. RxNd1
|
||||||
|
5. RxPb1
|
||||||
|
6. RxPb4
|
26
tools/puzzle_checker/games/7.txt
Normal file
26
tools/puzzle_checker/games/7.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 7 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 22
|
||||||
|
Total pieces placed: 230
|
||||||
|
Success pieces placed: 154
|
||||||
|
Total time (ms): 109
|
||||||
|
|
||||||
|
♖ . . ♙
|
||||||
|
|
||||||
|
. . . ♗
|
||||||
|
|
||||||
|
♗ ♙ ♘ .
|
||||||
|
|
||||||
|
. . ♖ .
|
||||||
|
|
||||||
|
|
||||||
|
id: 107752945007872
|
||||||
|
|
||||||
|
Found 2 solutions
|
||||||
|
1. RxNc2
|
||||||
|
2. RxPb2
|
||||||
|
3. RxBa2
|
||||||
|
4. RxRa4
|
||||||
|
5. RxPd4
|
||||||
|
6. RxBd3
|
26
tools/puzzle_checker/games/8.txt
Normal file
26
tools/puzzle_checker/games/8.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 8 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 63
|
||||||
|
Total pieces placed: 639
|
||||||
|
Success pieces placed: 441
|
||||||
|
Total time (ms): 345
|
||||||
|
|
||||||
|
. . ♖ .
|
||||||
|
|
||||||
|
. ♙ . .
|
||||||
|
|
||||||
|
♙ . ♗ .
|
||||||
|
|
||||||
|
♗ ♙ . ♗
|
||||||
|
|
||||||
|
|
||||||
|
id: 3579962327044
|
||||||
|
|
||||||
|
Found 5 solutions
|
||||||
|
1. BxBc2
|
||||||
|
2. RxBc2
|
||||||
|
3. RxPa2
|
||||||
|
4. RxBa1
|
||||||
|
5. RxPb1
|
||||||
|
6. RxPb3
|
26
tools/puzzle_checker/games/9.txt
Normal file
26
tools/puzzle_checker/games/9.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
*********** Game 9 ************
|
||||||
|
|
||||||
|
Generating a puzzle with 7 pieces with a maximum of 5 solutions
|
||||||
|
Total attempts: 250
|
||||||
|
Total pieces placed: 2557
|
||||||
|
Success pieces placed: 1750
|
||||||
|
Total time (ms): 1298
|
||||||
|
|
||||||
|
. . . .
|
||||||
|
|
||||||
|
♘ ♘ . ♙
|
||||||
|
|
||||||
|
. ♙ . ♗
|
||||||
|
|
||||||
|
♙ . ♘ .
|
||||||
|
|
||||||
|
|
||||||
|
id: 22408723452320
|
||||||
|
|
||||||
|
Found 1 solutions
|
||||||
|
1. BxNc1
|
||||||
|
2. NxBc1
|
||||||
|
3. NxPd3
|
||||||
|
4. NxPb2
|
||||||
|
5. axNb2
|
||||||
|
6. bxNa3
|
9
tools/puzzle_checker/gen_games.sh
Executable file
9
tools/puzzle_checker/gen_games.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
if [ ! -d games ]; then
|
||||||
|
mkdir games
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in {1..10}; do
|
||||||
|
echo "*********** Game $i ************" >> games/$i.txt
|
||||||
|
echo "" >> games/$i.txt
|
||||||
|
sol_cli -g -n 7 --print >> games/$i.txt
|
||||||
|
done
|
128
tools/scripts.sh
128
tools/scripts.sh
@ -1,128 +0,0 @@
|
|||||||
#! /usr/bin/bash
|
|
||||||
|
|
||||||
rootd() {
|
|
||||||
pushd $(git rev-parse --show-toplevel) 2>&1 > /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
restored() {
|
|
||||||
popd 2>&1 > /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
get_parameter() {
|
|
||||||
DEFAULT="${1}"
|
|
||||||
if [ -z ${2} ]; then
|
|
||||||
echo "${DEFAULT}"
|
|
||||||
elif [ ! -d "${2}" ]; then
|
|
||||||
echo "${DEFAULT}"
|
|
||||||
else
|
|
||||||
echo "${2}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Usage: build_web debug|release target_dir [archive_dir]
|
|
||||||
# Build profile location to place files location to place compressed archive
|
|
||||||
build_web() {
|
|
||||||
rootd
|
|
||||||
|
|
||||||
local BINARY_NAME="sol_chess"
|
|
||||||
local BUILD_PROFILE="debug"
|
|
||||||
local BUILD_PROFILE_SWITCH=""
|
|
||||||
if [ -n "${1}" ]; then
|
|
||||||
if [ "${1}" = "release" ]; then
|
|
||||||
local BUILD_PROFILE="release"
|
|
||||||
local BUILD_PROFILE_SWITCH="--release"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
local TARGET_DIR=$(get_parameter "./target/dist" ${2})
|
|
||||||
local ARCHIVE_DIR=$(get_parameter "" ${3})
|
|
||||||
|
|
||||||
echo "Build profile: ${BUILD_PROFILE}"
|
|
||||||
echo "Build profile switch: ${BUILD_PROFILE_SWITCH}"
|
|
||||||
echo "Target directory: ${TARGET_DIR}"
|
|
||||||
echo "Archive directory: ${ARCHIVE_DIR}"
|
|
||||||
|
|
||||||
set -x
|
|
||||||
cargo build --target wasm32-unknown-unknown ${BUILD_PROFILE_SWITCH}
|
|
||||||
set +x
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Wasm build failed"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf ${TARGET_DIR} && mkdir -p ${TARGET_DIR} && mv ./target/wasm32-unknown-unknown/${BUILD_PROFILE}/${BINARY_NAME}.wasm ${TARGET_DIR}/${BINARY_NAME}.wasm && cp ./tools/web/index.html ${TARGET_DIR}/index.html
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Failed to assemble the build in ${TARGET_DIR}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${ARCHIVE_DIR}" ]; then
|
|
||||||
local TAR_NAME="${ARCHIVE_DIR}/${BINARY_NAME}.tar.gz"
|
|
||||||
set -x
|
|
||||||
tar -czvf ${TAR_NAME} -C ${TARGET_DIR} . && echo "Created ${TAR_NAME}"
|
|
||||||
set +x
|
|
||||||
fi
|
|
||||||
|
|
||||||
restored
|
|
||||||
}
|
|
||||||
|
|
||||||
run_web() {
|
|
||||||
rootd
|
|
||||||
|
|
||||||
local TARGET_DIR=$(get_parameter "./target/dist" ${1})
|
|
||||||
echo "Building web app in ${TARGET_DIR}"
|
|
||||||
build_web "debug" $TARGET_DIR
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Failed to build the web app"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
basic-http-server $TARGET_DIR
|
|
||||||
|
|
||||||
restored
|
|
||||||
}
|
|
||||||
|
|
||||||
run_dev() {
|
|
||||||
rootd
|
|
||||||
|
|
||||||
TESTING=1 cargo run
|
|
||||||
|
|
||||||
restored
|
|
||||||
}
|
|
||||||
|
|
||||||
deploy() {
|
|
||||||
rootd
|
|
||||||
|
|
||||||
local BINARY_NAME="sol_chess"
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "Usage: deploy <serve_root>"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d $1 ]; then
|
|
||||||
echo "Directory $1 does not exist"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local serve_root=$1
|
|
||||||
build_web "release" "./target/dist" "./target"
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Failed to build the web app"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
sudo mv ./target/${BINARY_NAME}.tar.gz $serve_root/${BINARY_NAME}.tar.gz && \
|
|
||||||
sudo tar -xzvf $serve_root/${BINARY_NAME}.tar.gz -C $serve_root && \
|
|
||||||
sudo rm $serve_root/${BINARY_NAME}.tar.gz
|
|
||||||
echo "Deployment complete"
|
|
||||||
|
|
||||||
restored
|
|
||||||
}
|
|
||||||
|
|
||||||
clean() {
|
|
||||||
rootd
|
|
||||||
|
|
||||||
rm -rf ./target
|
|
||||||
|
|
||||||
restored
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Solitaire Chess</title>
|
|
||||||
<style>
|
|
||||||
html,
|
|
||||||
body,
|
|
||||||
canvas {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
position: absolute;
|
|
||||||
background: black;
|
|
||||||
z-index: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<canvas id="glcanvas" tabindex='1'></canvas>
|
|
||||||
<script src="https://not-fl3.github.io/miniquad-samples/mq_js_bundle.js"></script>
|
|
||||||
<script>load("sol_chess.wasm");</script> <!-- Your compiled WASM binary -->
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
x
Reference in New Issue
Block a user