Directly rename board -> position
This commit is contained in:
parent
569693bda9
commit
220da08727
25 changed files with 0 additions and 0 deletions
81
position/src/move_generator/move_set.rs
Normal file
81
position/src/move_generator/move_set.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::Move;
|
||||
use chessfriend_bitboard::BitBoard;
|
||||
use chessfriend_core::PlacedPiece;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct BitBoardSet {
|
||||
quiet: BitBoard,
|
||||
captures: BitBoard,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct MoveListSet {
|
||||
quiet: Vec<Move>,
|
||||
captures: Vec<Move>,
|
||||
}
|
||||
|
||||
impl MoveListSet {
|
||||
pub fn contains(&self, mv: &Move) -> bool {
|
||||
self.quiet.contains(mv) || self.captures.contains(mv)
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of moves for a piece on the board.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub(crate) struct MoveSet {
|
||||
piece: PlacedPiece,
|
||||
bitboards: BitBoardSet,
|
||||
move_lists: MoveListSet,
|
||||
}
|
||||
|
||||
impl MoveSet {
|
||||
pub(super) fn new(piece: PlacedPiece) -> MoveSet {
|
||||
MoveSet {
|
||||
piece,
|
||||
bitboards: BitBoardSet {
|
||||
quiet: BitBoard::empty(),
|
||||
captures: BitBoard::empty(),
|
||||
},
|
||||
move_lists: MoveListSet {
|
||||
quiet: Vec::new(),
|
||||
captures: Vec::new(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn quiet_moves(
|
||||
mut self,
|
||||
bitboard: BitBoard,
|
||||
move_list: impl Iterator<Item = Move>,
|
||||
) -> MoveSet {
|
||||
self.bitboards.quiet = bitboard;
|
||||
self.move_lists.quiet = move_list.collect();
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub(super) fn capture_moves(
|
||||
mut self,
|
||||
bitboard: BitBoard,
|
||||
move_list: impl Iterator<Item = Move>,
|
||||
) -> MoveSet {
|
||||
self.bitboards.captures = bitboard;
|
||||
self.move_lists.captures = move_list.collect();
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Return a BitBoard representing all possible moves.
|
||||
pub(super) fn bitboard(&self) -> BitBoard {
|
||||
self.bitboards.captures | self.bitboards.quiet
|
||||
}
|
||||
|
||||
pub(super) fn moves(&self) -> impl Iterator<Item = &Move> {
|
||||
self.move_lists
|
||||
.captures
|
||||
.iter()
|
||||
.chain(self.move_lists.quiet.iter())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue