This commit is contained in:
Simon Gardling 2025-01-28 22:45:38 -05:00
parent 37658c7bd0
commit 45e1a05839
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 19 additions and 32 deletions

View File

@ -109,8 +109,7 @@ impl Board {
split_from(0, BOARD_SIZE - 1, i) split_from(0, BOARD_SIZE - 1, i)
.into_iter() .into_iter()
.zip(split_from(0, BOARD_SIZE - 1, j)) .zip(split_from(0, BOARD_SIZE - 1, j))
.map(|(i_vec, j_vec)| i_vec.into_iter().zip(j_vec)) .map(|(i_vec, j_vec)| i_vec.into_iter().zip(j_vec).collect()),
.map(|x| x.into_iter().map(|(i, j)| (i, j)).collect()),
); );
let mut captured: usize = 0; let mut captured: usize = 0;
@ -152,32 +151,18 @@ mod test {
fn place_and_get() { fn place_and_get() {
let mut board = Board::new(); let mut board = Board::new();
assert_eq!(board.get(0, 0), &None); assert_eq!(board.get(0, 0), &None);
assert_eq!( board.place_unchecked(0, 0, Piece::Black);
board.place(0, 0, Piece::Black),
Ok(()),
"placing black on (0, 0)"
);
assert_eq!(board.get(0, 0), &Some(Piece::Black)); assert_eq!(board.get(0, 0), &Some(Piece::Black));
} }
#[test] #[test]
fn place_and_capture_simple() { fn place_and_capture_simple() {
let mut board = Board::new(); let mut board = Board::new();
assert_eq!( board.place_unchecked(0, 0, Piece::Black);
board.place(0, 0, Piece::Black), board.place_unchecked(0, 1, Piece::White);
Ok(()), board.place_unchecked(0, 2, Piece::Black);
"first move of piece black to (0, 0)"
); board.propegate_from(0, 2);
assert_eq!(
board.place(0, 1, Piece::White),
Ok(()),
"white move to (0, 1)"
);
assert_eq!(
board.place(0, 2, Piece::Black),
Ok(()),
"black counter, capturing white"
);
assert_eq!(board.get(0, 1), &Some(Piece::Black)); assert_eq!(board.get(0, 1), &Some(Piece::Black));
} }
@ -185,11 +170,12 @@ mod test {
fn failed_capture() { fn failed_capture() {
let mut board = Board::new(); let mut board = Board::new();
assert_eq!(board.place(0, 0, Piece::Black), Ok(())); board.place_unchecked(0, 0, Piece::Black);
assert_eq!(board.place(0, 2, Piece::White), Ok(())); board.place_unchecked(0, 2, Piece::White);
assert_eq!(board.place(0, 3, Piece::Black), Ok(())); board.place_unchecked(0, 3, Piece::Black);
board.propegate_from(0, 3);
assert_eq!( assert_eq!(
board.get(0, 1), board.get(0, 1),
@ -202,13 +188,14 @@ mod test {
fn long_capture_horiz() { fn long_capture_horiz() {
let mut board = Board::new(); let mut board = Board::new();
assert_eq!(board.place(0, 0, Piece::Black), Ok(())); board.place_unchecked(0, 0, Piece::Black);
for j in 1..=6 { for j in 1..=6 {
assert_eq!(board.place(0, j, Piece::White), Ok(())); board.place_unchecked(0, j, Piece::White);
} }
assert_eq!(board.place(0, 7, Piece::Black), Ok(())); board.place_unchecked(0, 7, Piece::Black);
board.propegate_from(0, 7);
for j in 2..=6 { for j in 2..=6 {
assert_eq!( assert_eq!(
@ -225,13 +212,14 @@ mod test {
fn long_capture_vert() { fn long_capture_vert() {
let mut board = Board::new(); let mut board = Board::new();
assert_eq!(board.place(0, 0, Piece::Black), Ok(())); board.place_unchecked(0, 0, Piece::Black);
for i in 1..=6 { for i in 1..=6 {
assert_eq!(board.place(i, 0, Piece::White), Ok(())); board.place_unchecked(i, 0, Piece::White);
} }
assert_eq!(board.place(7, 0, Piece::Black), Ok(())); board.place_unchecked(7, 0, Piece::Black);
board.propegate_from(7, 0);
for i in 2..=6 { for i in 2..=6 {
assert_eq!( assert_eq!(

View File

@ -16,7 +16,6 @@ fn problem_space(board: &Board, piece: Piece) -> Vec<(usize, usize, (Board, usiz
.collect::<Vec<(usize, usize)>>() .collect::<Vec<(usize, usize)>>()
}) })
.flat_map(|(i, j)| board.what_if(i, j, piece).map(|x| (i, j, x))) .flat_map(|(i, j)| board.what_if(i, j, piece).map(|x| (i, j, x)))
.map(|(i, j, (board, c))| (i, j, (board, c as usize)))
.collect() .collect()
} }