allow lowercase for specifying the board
This commit is contained in:
+1
-1
@@ -49,13 +49,13 @@ fn solve_puzzle(board: Board) {
|
|||||||
println!("No solutions found");
|
println!("No solutions found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("Found {} solutions", solutions.len());
|
|
||||||
let solution = solutions.first().unwrap();
|
let solution = solutions.first().unwrap();
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
solution.iter().for_each(|m| {
|
solution.iter().for_each(|m| {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
println!("{}. {}", idx, m.notation());
|
println!("{}. {}", idx, m.notation());
|
||||||
});
|
});
|
||||||
|
println!("There are atleast {} solutions to this puzzle", solutions.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_puzzle(num_pieces: Option<u32>, num_solutions: Option<u32>) -> Option<Board> {
|
fn generate_puzzle(num_pieces: Option<u32>, num_solutions: Option<u32>) -> Option<Board> {
|
||||||
|
|||||||
+7
-6
@@ -50,6 +50,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_id(board_id: &str) -> Result<Self, SError> {
|
pub fn from_id(board_id: &str) -> Result<Self, SError> {
|
||||||
|
// TODO: validate board_id before decode
|
||||||
let mut board_id_bytes = [0; 8];
|
let mut board_id_bytes = [0; 8];
|
||||||
board_id_bytes.copy_from_slice(board_id.as_bytes());
|
board_id_bytes.copy_from_slice(board_id.as_bytes());
|
||||||
let mut working_bytes_slice = [0; 6];
|
let mut working_bytes_slice = [0; 6];
|
||||||
@@ -83,12 +84,12 @@ impl Board {
|
|||||||
for f in 0..BOARD_SIZE {
|
for f in 0..BOARD_SIZE {
|
||||||
let c = chars.next().unwrap();
|
let c = chars.next().unwrap();
|
||||||
let piece = match c {
|
let piece = match c {
|
||||||
'K' => Piece::King,
|
'K' | 'k' => Piece::King,
|
||||||
'Q' => Piece::Queen,
|
'Q' | 'q' => Piece::Queen,
|
||||||
'B' => Piece::Bishop,
|
'B' | 'b' => Piece::Bishop,
|
||||||
'N' => Piece::Knight,
|
'N' | 'n' => Piece::Knight,
|
||||||
'R' => Piece::Rook,
|
'R' | 'r' => Piece::Rook,
|
||||||
'P' => Piece::Pawn,
|
'P' | 'p' => Piece::Pawn,
|
||||||
'.' => continue,
|
'.' => continue,
|
||||||
_ => return Err(SError::InvalidBoard),
|
_ => return Err(SError::InvalidBoard),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user