CoordPair::from_axes
This commit is contained in:
@@ -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<Piece> {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user