Add widgets, proper resources.rs
This commit is contained in:
+62
-1
@@ -19,7 +19,7 @@ use square::{Square, SquarePair};
|
||||
|
||||
use crate::generator::Puzzle;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Board {
|
||||
pub cells: [[Option<Piece>; BOARD_SIZE]; BOARD_SIZE],
|
||||
pub legal_moves: HashSet<CMove>,
|
||||
@@ -37,6 +37,12 @@ pub enum BoardState {
|
||||
Won,
|
||||
}
|
||||
|
||||
impl Default for BoardState {
|
||||
fn default() -> Self {
|
||||
BoardState::NotStarted
|
||||
}
|
||||
}
|
||||
|
||||
impl Board {
|
||||
pub fn new() -> Self {
|
||||
let cells = [[None; BOARD_SIZE]; BOARD_SIZE];
|
||||
@@ -714,4 +720,59 @@ mod tests {
|
||||
|
||||
validate_board!(board2, "..NB", "....", "RQ.K", "P...");
|
||||
}
|
||||
|
||||
macro_rules! sq {
|
||||
($sq:literal) => {
|
||||
Square::parse($sq)
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solver_smoke() {
|
||||
let mut board = Board::new();
|
||||
// . R . .
|
||||
// R . . P
|
||||
// B . B N
|
||||
// P . N .
|
||||
|
||||
board.set(sq!("Pa1"));
|
||||
board.set(sq!("Ba2"));
|
||||
board.set(sq!("Ra3"));
|
||||
board.set(sq!("Rb4"));
|
||||
board.set(sq!("Nc1"));
|
||||
board.set(sq!("Bc2"));
|
||||
board.set(sq!("Nd2"));
|
||||
board.set(sq!("Pd3"));
|
||||
|
||||
let solutions = board.solve().solutions;
|
||||
|
||||
for solution in solutions {
|
||||
let mut board = board.clone();
|
||||
solution
|
||||
.into_iter()
|
||||
.for_each(|m| assert!(board.make_move(m).is_some()));
|
||||
assert_eq!(BoardState::Won, board.game_state);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solver_smoke_no_solution() {
|
||||
// . R . .
|
||||
// R . . .
|
||||
// B . B N
|
||||
// P . N .
|
||||
|
||||
let mut board = Board::new();
|
||||
board.set(sq!("Pa1"));
|
||||
board.set(sq!("Ba2"));
|
||||
board.set(sq!("Ra3"));
|
||||
board.set(sq!("Rb4"));
|
||||
board.set(sq!("Nc1"));
|
||||
board.set(sq!("Bc2"));
|
||||
board.set(sq!("Nd2"));
|
||||
|
||||
let solutions = board.solve().solutions;
|
||||
|
||||
assert_eq!(0, solutions.len());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user