From 3376fc1e5b1205d77a36ec3897ec72e4c39d0360 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Tue, 18 Feb 2025 11:29:35 -0500 Subject: [PATCH] adjust othello board coordinate system to project requirements --- src/board.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/board.rs b/src/board.rs index 038badf..c880ed4 100644 --- a/src/board.rs +++ b/src/board.rs @@ -92,12 +92,12 @@ impl fmt::Display for Board { // Print numbers at top so the board can be read more easier write!(f, "{} ", space_padding)?; - for j in 0..BOARD_SIZE { + for j in (0..BOARD_SIZE).rev() { write!(f, "{:0PADDING$} ", j)?; } writeln!(f)?; - for i in 0..BOARD_SIZE { + for i in (0..BOARD_SIZE).rev() { writeln!(f, "{}{}", space_padding, horiz_sep_line)?; write!(f, "{:0PADDING$}|", i)?; @@ -142,10 +142,10 @@ impl Board { /// Starting position pub fn starting_pos(mut self) -> Self { - self.place_unchecked((BOARD_SIZE / 2) - 1, (BOARD_SIZE / 2) - 1, Piece::White); - self.place_unchecked(BOARD_SIZE / 2, (BOARD_SIZE / 2) - 1, Piece::Black); - self.place_unchecked((BOARD_SIZE / 2) - 1, BOARD_SIZE / 2, Piece::Black); - self.place_unchecked(BOARD_SIZE / 2, BOARD_SIZE / 2, Piece::White); + self.place_unchecked((BOARD_SIZE / 2) - 1, (BOARD_SIZE / 2) - 1, Piece::Black); + self.place_unchecked(BOARD_SIZE / 2, (BOARD_SIZE / 2) - 1, Piece::White); + self.place_unchecked((BOARD_SIZE / 2) - 1, BOARD_SIZE / 2, Piece::White); + self.place_unchecked(BOARD_SIZE / 2, BOARD_SIZE / 2, Piece::Black); self } @@ -381,18 +381,6 @@ mod test { } } - #[test] - fn diag_capture() { - let mut board = Board::new().starting_pos(); - - assert_eq!(board.place(2, 4, Piece::White), Ok(()), "{}", board); - assert_eq!(board.place(2, 3, Piece::Black), Ok(()), "{}", board); - - assert_eq!(board.place(2, 2, Piece::White), Ok(()), "{}", board); - - assert_eq!(board.place(2, 5, Piece::Black), Ok(()), "{}", board); - } - // Test corner capture from top-left corner #[test] fn corner_capture_top_left() {