[board] Implement a Pieces iterator
This type iterates the pieces in a Position using the BitScanner struct to iterate all the occupied squares of the position's bitboards.
This commit is contained in:
parent
18d9a845e6
commit
fac98735e3
3 changed files with 171 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
mod pieces;
|
||||
|
||||
use self::pieces::Pieces;
|
||||
use crate::bitboard::BitBoard;
|
||||
use crate::piece::{Piece, PiecePlacementError};
|
||||
use crate::square::Square;
|
||||
|
@ -81,7 +84,7 @@ impl Position {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn bitboard_for_piece(&self, piece: &Piece) -> &BitBoard {
|
||||
pub(super) fn bitboard_for_piece(&self, piece: &Piece) -> &BitBoard {
|
||||
&self.pieces_per_type[piece.color as usize][piece.shape as usize]
|
||||
}
|
||||
|
||||
|
@ -89,6 +92,11 @@ impl Position {
|
|||
&mut self.pieces_per_type[piece.color as usize][piece.shape as usize]
|
||||
}
|
||||
|
||||
fn pieces(&self, color: Color) -> Pieces {
|
||||
Pieces::new(&self, color)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Position {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut output = String::new();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue