[board, explorer, position] Clean up naming of sight and movement methods
These methods have a prefix, either `sight` or `movement`, and then follow the conventions for other "trio" clusters where there's an un-suffixed method that takes an Option<Color>, a _active method that uses the active color, and a _unwrapped method that takes a bare Color.
This commit is contained in:
parent
e7fd65672d
commit
a30553503f
4 changed files with 42 additions and 25 deletions
|
@ -4,12 +4,12 @@
|
|||
//! of squares a piece can move to. For all pieces except pawns, the Movement
|
||||
//! set is equal to the Sight set.
|
||||
|
||||
use crate::{sight::Sight, Board};
|
||||
use crate::{Board, sight::Sight};
|
||||
use chessfriend_bitboard::BitBoard;
|
||||
use chessfriend_core::{Color, Piece, Rank, Shape, Square, Wing};
|
||||
|
||||
impl Board {
|
||||
pub fn movement(&self, square: Square) -> BitBoard {
|
||||
pub fn movement_piece(&self, square: Square) -> BitBoard {
|
||||
if let Some(piece) = self.get_piece(square) {
|
||||
piece.movement(square, self)
|
||||
} else {
|
||||
|
@ -93,7 +93,7 @@ fn pawn_pushes(pawn: BitBoard, color: Color, occupancy: BitBoard) -> BitBoard {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::pawn_pushes;
|
||||
use chessfriend_bitboard::{bitboard, BitBoard};
|
||||
use chessfriend_bitboard::{BitBoard, bitboard};
|
||||
use chessfriend_core::{Color, Square};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -23,7 +23,7 @@ use std::ops::BitOr;
|
|||
|
||||
impl Board {
|
||||
/// Compute sight of the piece on the given square.
|
||||
pub fn sight(&self, square: Square) -> BitBoard {
|
||||
pub fn sight_piece(&self, square: Square) -> BitBoard {
|
||||
if let Some(piece) = self.get_piece(square) {
|
||||
piece.sight(square, self)
|
||||
} else {
|
||||
|
@ -31,8 +31,23 @@ impl Board {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn active_sight(&self) -> BitBoard {
|
||||
self.friendly_sight(self.active_color())
|
||||
/// Calculate sight of all pieces of the given [`Color`]. If `color` is
|
||||
/// `None`, calculate sight of the active color.
|
||||
pub fn sight(&self, color: Option<Color>) -> BitBoard {
|
||||
self.sight_unwrapped(self.unwrap_color(color))
|
||||
}
|
||||
|
||||
/// Calculate sight of all pieces of the active color.
|
||||
pub fn sight_active(&self) -> BitBoard {
|
||||
self.sight_unwrapped(self.active_color())
|
||||
}
|
||||
|
||||
/// Calculate sight of all pieces of the given [`Color`].
|
||||
pub fn sight_unwrapped(&self, color: Color) -> BitBoard {
|
||||
self.friendly_occupancy(color)
|
||||
.occupied_squares_leading()
|
||||
.map(|square| self.sight_piece(square))
|
||||
.fold(BitBoard::EMPTY, BitOr::bitor)
|
||||
}
|
||||
|
||||
/// A [`BitBoard`] of all squares the given color can see.
|
||||
|
@ -40,7 +55,7 @@ impl Board {
|
|||
// TODO: Probably want to implement a caching layer here.
|
||||
self.friendly_occupancy(color)
|
||||
.occupied_squares(&IterationDirection::default())
|
||||
.map(|square| self.sight(square))
|
||||
.map(|square| self.sight_piece(square))
|
||||
.fold(BitBoard::EMPTY, BitOr::bitor)
|
||||
}
|
||||
|
||||
|
@ -244,7 +259,7 @@ mod tests {
|
|||
White King on E4,
|
||||
);
|
||||
|
||||
let sight = pos.active_sight();
|
||||
let sight = pos.sight_active();
|
||||
assert_eq!(sight, bitboard![E5 F5 F4 F3 E3 D3 D4 D5]);
|
||||
}
|
||||
|
||||
|
@ -267,8 +282,8 @@ mod tests {
|
|||
|
||||
mod pawn {
|
||||
use crate::{sight::Sight, test_board};
|
||||
use chessfriend_bitboard::{bitboard, BitBoard};
|
||||
use chessfriend_core::{piece, Square};
|
||||
use chessfriend_bitboard::{BitBoard, bitboard};
|
||||
use chessfriend_core::{Square, piece};
|
||||
|
||||
sight_test!(e4_pawn, piece!(White Pawn), Square::E4, bitboard![D5 F5]);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue