diff --git a/src/elo.rs b/src/elo.rs index f886700..202da53 100644 --- a/src/elo.rs +++ b/src/elo.rs @@ -168,14 +168,10 @@ impl PlayerArena { self.process_outcome(i, j, &o); received_num += 1; - // print the leaderboard every 5 steps - if received_num % 5 == 0 { - term.clear_last_lines(self.players.len()) - .expect("unable to clear prev lines"); - let formatted_self = format!("{}", self); - term.write_str(&formatted_self) - .expect("unable to write leaderboard"); - } + term.clear_last_lines(self.players.len()) + .expect("unable to clear prev lines"); + term.write_str(format!("{}", self).as_str()) + .expect("unable to write leaderboard"); // break if all pairs were recieved if received_num == num { diff --git a/src/logic/board_value.rs b/src/logic/board_value.rs index 180af39..7c4bf6f 100644 --- a/src/logic/board_value.rs +++ b/src/logic/board_value.rs @@ -20,12 +20,6 @@ impl BoardValueMap { /// Weights from: https://repub.eur.nl/pub/7142/ei2005-47.pdf pub fn new() -> Self { - assert_eq!( - Board::BOARD_SIZE, - 8, - "BVM only supports Board::BOARD_SIZE of 8" - ); - const POSITION_VALUES: [[i64; 8]; 8] = [ [100, -20, 10, 5, 5, 10, -20, 100], [-20, -50, -2, -2, -2, -2, -50, -20], diff --git a/src/repr/board.rs b/src/repr/board.rs index 9c8a124..00b4867 100644 --- a/src/repr/board.rs +++ b/src/repr/board.rs @@ -143,12 +143,13 @@ impl Board { } /// Starting position - pub fn starting_pos(mut self) -> Self { + pub const fn starting_pos(mut self) -> Self { let hf = Self::BOARD_SIZE / 2; - self.place_unchecked((hf - 1, hf - 1).into(), Piece::White); - self.place_unchecked((hf, hf - 1).into(), Piece::Black); - self.place_unchecked((hf - 1, hf).into(), Piece::Black); - self.place_unchecked((hf, hf).into(), Piece::White); + self.place_unchecked(CoordPair::from_axes(hf - 1, hf - 1), Piece::White); + self.place_unchecked(CoordPair::from_axes(hf, hf - 1), Piece::Black); + + self.place_unchecked(CoordPair::from_axes(hf - 1, hf), Piece::Black); + self.place_unchecked(CoordPair::from_axes(hf, hf), Piece::White); self } @@ -178,13 +179,11 @@ impl Board { } } - #[const_fn(cfg(not(feature = "bitvec")))] pub const fn get_piece(&self, coord: CoordPair, color: Piece) -> bool { self.board(color).get(coord) } /// Returns the color of a place on the [`Board`] at a position - #[const_fn(cfg(not(feature = "bitvec")))] pub const fn get(&self, coord: CoordPair) -> Option { if self.get_piece(coord, Piece::White) { Some(Piece::White) @@ -197,13 +196,11 @@ impl Board { /// Place a piece without checking for propegation of validity /// only pub for setting up benchmark - #[const_fn(cfg(not(feature = "bitvec")))] pub const fn place_unchecked(&mut self, coord: CoordPair, piece: Piece) { self.board_mut(piece).set(coord, true); self.board_mut(piece.flip()).set(coord, false); } - #[const_fn(cfg(not(feature = "bitvec")))] const fn delete(&mut self, coord: CoordPair) { self.board_mut(Piece::White).set(coord, false); self.board_mut(Piece::Black).set(coord, false); @@ -289,14 +286,12 @@ impl Board { } /// Count the number of a type of [`Piece`] on the board - #[const_fn(cfg(not(feature = "bitvec")))] pub const fn count(&self, piece: Piece) -> usize { self.board(piece).count() } /// Get the "net score" of a player /// Formula: `net_score = Score_player - Score_opponent` - #[const_fn(cfg(not(feature = "bitvec")))] pub const fn net_score(&self, piece: Piece) -> i16 { self.count(piece) as i16 - self.count(piece.flip()) as i16 } diff --git a/src/repr/coords.rs b/src/repr/coords.rs index af4e739..ed318be 100644 --- a/src/repr/coords.rs +++ b/src/repr/coords.rs @@ -14,6 +14,13 @@ const_assert!(CoordPairInner::MAX as usize >= Board::BOARD_AREA as usize); #[derive(PartialEq, Eq, Copy, Clone, Hash)] pub struct CoordPair(pub CoordPairInner); +impl CoordPair { + /// Convert a row and column to an index in the board + pub const fn from_axes(row: CoordAxis, col: CoordAxis) -> Self { + Self(row * Board::BOARD_SIZE + col) + } +} + impl std::fmt::Display for CoordPair { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let (i, j) = (*self).into(); @@ -27,18 +34,13 @@ impl std::fmt::Debug for CoordPair { } } -/// Convert a row and column to an index in the board -const fn get_index(row: CoordAxis, col: CoordAxis) -> CoordPair { - CoordPair(row * Board::BOARD_SIZE + col) -} - fn from_index(index: CoordPair) -> (CoordAxis, CoordAxis) { index.0.div_mod_floor(&Board::BOARD_SIZE) } impl From<(CoordAxis, CoordAxis)> for CoordPair { fn from(value: (CoordAxis, CoordAxis)) -> Self { - get_index(value.0, value.1) + Self::from_axes(value.0, value.1) } }