Compare commits
4 Commits
game
..
0.0.1.wasm
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a8d9a47af | |||
| 2ada9183e7 | |||
| e957903a39 | |||
| f4b41bc6de |
@@ -19,3 +19,5 @@ Cargo.lock
|
||||
# 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.
|
||||
.idea/
|
||||
|
||||
dist/
|
||||
|
||||
Generated
-268
@@ -64,12 +64,6 @@ version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.21.0"
|
||||
@@ -94,19 +88,6 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.2"
|
||||
@@ -116,12 +97,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.7"
|
||||
@@ -151,17 +126,6 @@ dependencies = [
|
||||
"ttf-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glam"
|
||||
version = "0.27.0"
|
||||
@@ -190,41 +154,12 @@ dependencies = [
|
||||
"png",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indicatif"
|
||||
version = "0.17.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf675b85ed934d3c67b5c5469701eec7db22689d0a2139d856e0925fa28b281"
|
||||
dependencies = [
|
||||
"console",
|
||||
"number_prefix",
|
||||
"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]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6ea2a48c204030ee31a7d7fc72c93294c92fe87ecb1789881c9543516e1a0d"
|
||||
|
||||
[[package]]
|
||||
name = "macroquad"
|
||||
version = "0.4.13"
|
||||
@@ -292,12 +227,6 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "number_prefix"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
@@ -326,21 +255,6 @@ dependencies = [
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.92"
|
||||
@@ -365,36 +279,6 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-fuzzy-search"
|
||||
version = "0.1.1"
|
||||
@@ -441,9 +325,7 @@ name = "sol_chess"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"argh",
|
||||
"indicatif",
|
||||
"macroquad",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -469,88 +351,12 @@ version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396"
|
||||
dependencies = [
|
||||
"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]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@@ -573,86 +379,12 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"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]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ default-run = "sol_chess"
|
||||
|
||||
[dependencies]
|
||||
argh = "0.1.13"
|
||||
indicatif = "0.17.9"
|
||||
macroquad = "0.4.13"
|
||||
rand = "0.8.5"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 's'
|
||||
|
||||
@@ -10,7 +10,7 @@ Goal: Generate 'hard' puzzles.
|
||||
|
||||
## Usage
|
||||
|
||||
- [WIP] Run `sol_chess` to start a windowed GUI game.
|
||||
- Run `sol_chess` to start a windowed GUI game.
|
||||
- Run `sol_cli` to start the CLI tool.
|
||||
|
||||
## CLI Usage
|
||||
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
cargo build --target wasm32-unknown-unknown --release
|
||||
mkdir -p ./dist
|
||||
rm ./web/sol_chess.wasm
|
||||
mv ./target/wasm32-unknown-unknown/release/sol_chess.wasm ./dist/sol_chess.wasm
|
||||
|
||||
basic-http-server ./dist
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
cargo build --target wasm32-unknown-unknown --release
|
||||
mkdir -p ./dist
|
||||
rm ./web/sol_chess.wasm
|
||||
mv ./target/wasm32-unknown-unknown/release/sol_chess.wasm ./dist/sol_chess.wasm
|
||||
|
||||
basic-http-server ./dist
|
||||
+34
-16
@@ -4,7 +4,12 @@ pub mod errors;
|
||||
pub mod piece;
|
||||
pub mod square;
|
||||
|
||||
use std::{collections::HashSet, mem};
|
||||
use core::fmt;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fmt::{Display, Formatter},
|
||||
mem,
|
||||
};
|
||||
|
||||
use cmove::CMove;
|
||||
use constants::BOARD_SIZE;
|
||||
@@ -16,12 +21,12 @@ use square::{Square, SquarePair};
|
||||
pub struct Board {
|
||||
pub cells: [[Option<Piece>; BOARD_SIZE]; BOARD_SIZE],
|
||||
pub legal_moves: HashSet<CMove>,
|
||||
pub game_state: GameState,
|
||||
pub game_state: BoardState,
|
||||
pieces_remaining: u8,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub enum GameState {
|
||||
pub enum BoardState {
|
||||
NotStarted,
|
||||
InProgress,
|
||||
Lost,
|
||||
@@ -34,7 +39,7 @@ impl Board {
|
||||
cells: [[None; BOARD_SIZE]; BOARD_SIZE],
|
||||
legal_moves: HashSet::new(),
|
||||
pieces_remaining: 0,
|
||||
game_state: GameState::NotStarted,
|
||||
game_state: BoardState::NotStarted,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,13 +263,13 @@ impl Board {
|
||||
|
||||
fn calc_game_state(&mut self) {
|
||||
self.game_state = if self.pieces_remaining == 0 {
|
||||
GameState::NotStarted
|
||||
BoardState::NotStarted
|
||||
} else if self.pieces_remaining == 1 {
|
||||
GameState::Won
|
||||
BoardState::Won
|
||||
} else if self.legal_moves.is_empty() {
|
||||
GameState::Lost
|
||||
BoardState::Lost
|
||||
} else {
|
||||
GameState::InProgress
|
||||
BoardState::InProgress
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,6 +355,19 @@ 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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -502,7 +520,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_smoke_puzzle() {
|
||||
let mut board = Board::new();
|
||||
assert_eq!(GameState::NotStarted, board.game_state);
|
||||
assert_eq!(BoardState::NotStarted, board.game_state);
|
||||
assert_eq!(0, board.pieces_remaining);
|
||||
|
||||
// K . . .
|
||||
@@ -510,22 +528,22 @@ mod tests {
|
||||
// . . R .
|
||||
// N . . .
|
||||
board.set(sq!("Ka4"));
|
||||
assert_eq!(GameState::Won, board.game_state);
|
||||
assert_eq!(BoardState::Won, board.game_state);
|
||||
|
||||
board.set(sq!("Pb3"));
|
||||
board.set(sq!("Rc2"));
|
||||
board.set(sq!("Na1"));
|
||||
|
||||
assert_eq!(GameState::InProgress, board.game_state);
|
||||
assert_eq!(BoardState::InProgress, board.game_state);
|
||||
assert_eq!(4, board.pieces_remaining);
|
||||
|
||||
assert!(board.make_move(mv!("Na1", "Rc2")).is_some());
|
||||
assert_eq!(3, board.pieces_remaining);
|
||||
assert_eq!(GameState::InProgress, board.game_state);
|
||||
assert_eq!(BoardState::InProgress, board.game_state);
|
||||
|
||||
assert!(board.make_move(mv!("Pb3", "Ka4")).is_some());
|
||||
assert_eq!(2, board.pieces_remaining);
|
||||
assert_eq!(GameState::Lost, board.game_state);
|
||||
assert_eq!(BoardState::Lost, board.game_state);
|
||||
|
||||
// P . . .
|
||||
// . . . .
|
||||
@@ -540,12 +558,12 @@ mod tests {
|
||||
// . . N .
|
||||
// P . . .
|
||||
assert_eq!(4, board.pieces_remaining);
|
||||
assert_eq!(GameState::InProgress, board.game_state);
|
||||
assert_eq!(BoardState::InProgress, board.game_state);
|
||||
|
||||
board.make_move(mv!("Qa3", "Pa4"));
|
||||
board.make_move(mv!("Nc2", "Pa1"));
|
||||
assert_eq!(2, board.pieces_remaining);
|
||||
assert_eq!(GameState::InProgress, board.game_state);
|
||||
assert_eq!(BoardState::InProgress, board.game_state);
|
||||
|
||||
// Q . . .
|
||||
// . . . .
|
||||
@@ -553,7 +571,7 @@ mod tests {
|
||||
// N . . .
|
||||
board.make_move(mv!("Qa4", "Na1"));
|
||||
assert_eq!(1, board.pieces_remaining);
|
||||
assert_eq!(GameState::Won, board.game_state);
|
||||
assert_eq!(BoardState::Won, board.game_state);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+23
-31
@@ -1,14 +1,13 @@
|
||||
use std::{fmt::Display, time::Duration};
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{
|
||||
board::{piece::Piece, Board},
|
||||
solver::Solver,
|
||||
};
|
||||
use indicatif::ProgressBar;
|
||||
use rand::{seq::*, Rng};
|
||||
|
||||
use macroquad::{prelude::rand, time};
|
||||
|
||||
pub fn generate(num_pieces: u32, num_solutions: u32) -> GenerateStats {
|
||||
let rand = rand::thread_rng();
|
||||
let candidate_pieces = vec![
|
||||
Piece::Pawn,
|
||||
Piece::Pawn,
|
||||
@@ -34,31 +33,23 @@ pub fn generate(num_pieces: u32, num_solutions: u32) -> GenerateStats {
|
||||
}
|
||||
|
||||
let attempts: u32 = 1000;
|
||||
let bar = ProgressBar::new_spinner();
|
||||
bar.enable_steady_tick(Duration::from_millis(100));
|
||||
let mut overall_stats = GenerateStats::new(0, 0, 0, 0, None);
|
||||
let mut overall_stats = GenerateStats::new(0, 0, 0, 0., None);
|
||||
for _ in 0..attempts {
|
||||
let stats = try_generate(
|
||||
num_pieces,
|
||||
num_solutions,
|
||||
candidate_pieces.clone(),
|
||||
rand.clone(),
|
||||
);
|
||||
let stats = try_generate(num_pieces, num_solutions, candidate_pieces.clone());
|
||||
overall_stats.piece_total += stats.piece_total;
|
||||
overall_stats.piece_success += stats.piece_success;
|
||||
overall_stats.total += stats.total;
|
||||
overall_stats.total_millis += stats.total_millis;
|
||||
overall_stats.total_seconds += stats.total_seconds;
|
||||
overall_stats.board = stats.board;
|
||||
bar.set_message(format!(
|
||||
println!(
|
||||
"Generating puzzle.. Elapsed: {}s",
|
||||
overall_stats.total_millis / 1000
|
||||
));
|
||||
overall_stats.total_seconds,
|
||||
);
|
||||
if overall_stats.board.is_some() {
|
||||
return overall_stats;
|
||||
}
|
||||
}
|
||||
|
||||
bar.finish_and_clear();
|
||||
overall_stats
|
||||
}
|
||||
|
||||
@@ -66,7 +57,7 @@ pub struct GenerateStats {
|
||||
piece_total: u32,
|
||||
piece_success: u32,
|
||||
total: u32,
|
||||
total_millis: u128,
|
||||
total_seconds: f64,
|
||||
board: Option<Board>,
|
||||
}
|
||||
|
||||
@@ -75,14 +66,14 @@ impl GenerateStats {
|
||||
piece_total: u32,
|
||||
piece_success: u32,
|
||||
total: u32,
|
||||
total_millis: u128,
|
||||
total_millis: f64,
|
||||
board: Option<Board>,
|
||||
) -> Self {
|
||||
Self {
|
||||
piece_total,
|
||||
piece_success,
|
||||
total,
|
||||
total_millis,
|
||||
total_seconds: total_millis,
|
||||
board,
|
||||
}
|
||||
}
|
||||
@@ -92,7 +83,7 @@ impl GenerateStats {
|
||||
add_stat(&mut stats, "Total attempts", self.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, "Total time (ms)", self.total_millis);
|
||||
add_stat(&mut stats, "Total time (ms)", self.total_seconds);
|
||||
|
||||
println!("{}", stats);
|
||||
}
|
||||
@@ -113,28 +104,28 @@ fn try_generate(
|
||||
num_pieces: u32,
|
||||
num_solutions: u32,
|
||||
mut candidate_pieces: Vec<Piece>,
|
||||
mut rand: rand::prelude::ThreadRng,
|
||||
) -> GenerateStats {
|
||||
let mut board = Board::new();
|
||||
let mut piece_total = 0;
|
||||
let mut piece_success = 0;
|
||||
let now = std::time::Instant::now();
|
||||
let now = time::get_time();
|
||||
for _ in 0..num_pieces {
|
||||
let mut placed = false;
|
||||
let empty_squares = board.empty_squares();
|
||||
let mut attempts = 15;
|
||||
while !placed {
|
||||
if attempts == 0 {
|
||||
let elapsed = now.elapsed().as_millis();
|
||||
let elapsed = time::get_time() - now;
|
||||
return GenerateStats::new(piece_total, piece_success, 1, elapsed, None);
|
||||
}
|
||||
|
||||
attempts -= 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 mut random_square = empty_squares.choose(&mut rand).unwrap().clone();
|
||||
let square_index = rand::gen_range(0, empty_squares.len());
|
||||
let mut random_square = empty_squares[square_index].clone();
|
||||
random_square.piece = Some(piece);
|
||||
board.set(random_square.clone());
|
||||
let solutions = Solver::new(board.clone()).solve();
|
||||
@@ -151,7 +142,7 @@ fn try_generate(
|
||||
}
|
||||
|
||||
let solutions = Solver::new(board.clone()).solve();
|
||||
let elapsed = now.elapsed().as_millis();
|
||||
let elapsed = time::get_time() - now;
|
||||
if solutions.len() > num_solutions as usize {
|
||||
GenerateStats::new(piece_total, piece_success, 1, elapsed, None)
|
||||
} else {
|
||||
@@ -161,16 +152,17 @@ fn try_generate(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{board::GameState, solver::Solver};
|
||||
use crate::{board::BoardState, solver::Solver};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
// Figure out a way to remove the macroquad dependencies from this package
|
||||
// #[test]
|
||||
fn generator_smoke() {
|
||||
for _ in 0..10 {
|
||||
let gen_stats = generate(5, 5);
|
||||
let board = gen_stats.board.expect("No puzzle was generated");
|
||||
assert_eq!(board.game_state, GameState::InProgress);
|
||||
assert_eq!(board.game_state, BoardState::InProgress);
|
||||
|
||||
let solutions = Solver::new(board).solve();
|
||||
assert!(solutions.len() <= 5);
|
||||
|
||||
+397
-25
@@ -1,39 +1,43 @@
|
||||
use core::fmt;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use game::texture::PieceTexture;
|
||||
use macroquad::prelude::*;
|
||||
use sol_chess::board::{square::Square, Board};
|
||||
use sol_chess::{
|
||||
board::{Board, BoardState},
|
||||
generator,
|
||||
};
|
||||
|
||||
mod game;
|
||||
|
||||
#[macroquad::main("Solitaire Chess")]
|
||||
async fn main() {
|
||||
let background_color = Color::from_rgba(196, 195, 208, 255);
|
||||
let game = init().await;
|
||||
let mut game = init().await;
|
||||
loop {
|
||||
clear_background(background_color);
|
||||
draw_heading("Solitaire Chess");
|
||||
game.update_window_size();
|
||||
game.draw();
|
||||
game.handle_input();
|
||||
next_frame().await
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_heading(title: &str) {
|
||||
let dims = measure_text(title, None, 60, 1.0);
|
||||
let x = screen_width() / 2.0 - dims.width / 2.0;
|
||||
let y = 2.0 * dims.height;
|
||||
draw_text(title, x, y, 60.0, BLACK);
|
||||
}
|
||||
|
||||
async fn init() -> Game {
|
||||
set_pc_assets_folder("./assets");
|
||||
let texture_res = load_texture("pieces.png").await.unwrap();
|
||||
let texture_bytes = include_bytes!("../assets/pieces.png");
|
||||
let texture_res = Texture2D::from_file_with_format(&texture_bytes[..], None);
|
||||
texture_res.set_filter(FilterMode::Nearest);
|
||||
build_textures_atlas();
|
||||
let mut board = Board::new();
|
||||
board.set(Square::parse("Pa4"));
|
||||
board.set(Square::parse("Pa3"));
|
||||
board.set(Square::parse("Na2"));
|
||||
board.set(Square::parse("Na1"));
|
||||
board.set(Square::parse("Bb4"));
|
||||
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 generate = generator::generate(6, 100);
|
||||
let board = generate.board().expect("No puzzle was generated");
|
||||
let square_width = 128.0;
|
||||
let num_squares = 4;
|
||||
let x = (screen_width() - (square_width * num_squares as f32)) / 2.0;
|
||||
@@ -44,10 +48,33 @@ async fn init() -> Game {
|
||||
}
|
||||
|
||||
struct Game {
|
||||
original_board: Board,
|
||||
board: Board,
|
||||
squares: Vec<GameSquare>,
|
||||
texture_res: Texture2D,
|
||||
num_squares: usize,
|
||||
state: GameState,
|
||||
debug: bool,
|
||||
info_square: Rect,
|
||||
window_height: f32,
|
||||
window_width: f32,
|
||||
}
|
||||
|
||||
struct GameSquare {
|
||||
rect: Rect,
|
||||
color: Color,
|
||||
is_source: bool,
|
||||
is_target: bool,
|
||||
is_previous_target: bool,
|
||||
i: usize,
|
||||
j: usize,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum GameState {
|
||||
SelectSource(Option<(usize, usize)>),
|
||||
SelectTarget((usize, usize)),
|
||||
GameOver((usize, usize)),
|
||||
}
|
||||
|
||||
impl Game {
|
||||
@@ -72,36 +99,113 @@ impl Game {
|
||||
_ => light,
|
||||
};
|
||||
|
||||
rects.push(GameSquare { rect, color, i, j });
|
||||
rects.push(GameSquare {
|
||||
rect,
|
||||
color,
|
||||
i,
|
||||
j,
|
||||
is_source: false,
|
||||
is_target: false,
|
||||
is_previous_target: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let info_x = x;
|
||||
let info_y = y + (num_squares as f32 * square_width) + square_width / 2.0;
|
||||
let info_w = square_width * num_squares as f32;
|
||||
|
||||
Self {
|
||||
original_board: board.clone(),
|
||||
board,
|
||||
squares: rects,
|
||||
num_squares,
|
||||
texture_res,
|
||||
state: GameState::SelectSource(None),
|
||||
debug: false,
|
||||
info_square: Rect::new(info_x, info_y, info_w, square_width),
|
||||
window_height: screen_height(),
|
||||
window_width: screen_width(),
|
||||
}
|
||||
}
|
||||
|
||||
fn update_window_size(&mut self) {
|
||||
let new_height = screen_height();
|
||||
let new_width = screen_width();
|
||||
|
||||
if new_height == self.window_height && new_width == self.window_width {
|
||||
return;
|
||||
}
|
||||
|
||||
self.window_height = screen_height();
|
||||
self.window_width = screen_width();
|
||||
|
||||
let square_width = 128.0;
|
||||
let num_squares = 4;
|
||||
let x = (self.window_width - (square_width * num_squares as f32)) / 2.0;
|
||||
let y = (self.window_height - (square_width * num_squares as f32)) / 2.0;
|
||||
|
||||
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,
|
||||
is_source: false,
|
||||
is_target: false,
|
||||
is_previous_target: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let info_x = x;
|
||||
let info_y = y + (num_squares as f32 * square_width) + square_width / 2.0;
|
||||
let info_w = square_width * num_squares as f32;
|
||||
|
||||
self.squares = rects;
|
||||
self.info_square = Rect::new(info_x, info_y, info_w, square_width);
|
||||
}
|
||||
|
||||
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;
|
||||
let mut selected_square = None;
|
||||
self.squares.iter().for_each(|square| {
|
||||
let color = if square.is_source {
|
||||
Color::from_rgba(152, 152, 152, 255)
|
||||
} else if square.is_target {
|
||||
Color::from_rgba(152, 129, 123, 255)
|
||||
} else {
|
||||
square.color
|
||||
};
|
||||
|
||||
draw_rectangle(
|
||||
square.rect.x,
|
||||
square.rect.y,
|
||||
square.rect.w,
|
||||
square.rect.h,
|
||||
square.color,
|
||||
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,
|
||||
@@ -109,14 +213,282 @@ impl Game {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
draw_text(
|
||||
&format!("Press 'R' to reset"),
|
||||
self.info_square.x + 20.0,
|
||||
self.info_square.y + 20.0,
|
||||
20.0,
|
||||
BLACK,
|
||||
);
|
||||
|
||||
draw_text(
|
||||
&format!("Press 'N' for new game (when the current game is won)"),
|
||||
self.info_square.x + 20.0,
|
||||
self.info_square.y + 40.0,
|
||||
20.0,
|
||||
BLACK,
|
||||
);
|
||||
|
||||
draw_text(
|
||||
&format!("Press 'D' to toggle debug mode"),
|
||||
self.info_square.x + 20.0,
|
||||
self.info_square.y + 60.0,
|
||||
20.0,
|
||||
GRAY,
|
||||
);
|
||||
|
||||
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 handle_input(&mut self) {
|
||||
if is_key_released(KeyCode::R) {
|
||||
self.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if is_key_released(KeyCode::N) {
|
||||
if let GameState::GameOver(_) = self.state {
|
||||
self.next_puzzle();
|
||||
}
|
||||
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_pressed(MouseButton::Right) {
|
||||
let current_state = self.state.clone();
|
||||
let new_state = match current_state {
|
||||
GameState::SelectSource(_) => GameState::SelectSource(None),
|
||||
GameState::SelectTarget((_, _)) => {
|
||||
self.reset_squares();
|
||||
GameState::SelectSource(None)
|
||||
}
|
||||
GameState::GameOver((i, j)) => GameState::SelectSource(Some((i, j))),
|
||||
};
|
||||
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;
|
||||
}
|
||||
|
||||
if is_mouse_button_released(MouseButton::Left) {
|
||||
let current_state = self.state.clone();
|
||||
let new_state = match current_state {
|
||||
GameState::SelectSource(previous_target) => {
|
||||
GameState::SelectSource(previous_target)
|
||||
}
|
||||
GameState::SelectTarget(source) => {
|
||||
self.handle_select_target(mouse_position(), source)
|
||||
}
|
||||
GameState::GameOver(previous_target) => GameState::GameOver(previous_target),
|
||||
};
|
||||
|
||||
self.state = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
return GameState::GameOver((x, y));
|
||||
}
|
||||
|
||||
self.reset_squares();
|
||||
self.get(x, y).is_target = true;
|
||||
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();
|
||||
self.state = GameState::SelectSource(None);
|
||||
}
|
||||
|
||||
fn next_puzzle(&mut self) {
|
||||
self.reset();
|
||||
let generate = generator::generate(6, 100);
|
||||
let board = generate.board().expect("No puzzle was generated");
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
struct GameSquare {
|
||||
rect: Rect,
|
||||
color: Color,
|
||||
i: usize,
|
||||
j: usize,
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
use crate::board::{
|
||||
cmove::CMove,
|
||||
{Board, GameState},
|
||||
{Board, BoardState},
|
||||
};
|
||||
|
||||
pub struct Solver {
|
||||
@@ -26,12 +26,12 @@ impl Solver {
|
||||
|
||||
pub fn solve(&self) -> Vec<Vec<CMove>> {
|
||||
let mut solutions = Vec::new();
|
||||
if let GameState::Won = self.board.game_state {
|
||||
if let BoardState::Won = self.board.game_state {
|
||||
solutions.push(self.moves.clone());
|
||||
return solutions;
|
||||
}
|
||||
|
||||
let GameState::InProgress = self.board.game_state else {
|
||||
let BoardState::InProgress = self.board.game_state else {
|
||||
return solutions;
|
||||
};
|
||||
|
||||
@@ -81,7 +81,7 @@ mod tests {
|
||||
solution
|
||||
.into_iter()
|
||||
.for_each(|m| assert!(board.make_move(m).is_some()));
|
||||
assert_eq!(GameState::Won, board.game_state);
|
||||
assert_eq!(BoardState::Won, board.game_state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user