chessfriend/board/src/moves/move_set.rs
Eryn Wells b842b3520b [board] Implement a MoveSet struct
This struct represents a set of moves for a PlacedPiece
2024-01-05 18:30:00 -08:00

68 lines
1.6 KiB
Rust

use crate::{bitboard::BitBoard, piece::PlacedPiece, Move};
struct BitBoardSet {
quiet: BitBoard,
captures: BitBoard,
}
struct MoveListSet {
quiet: Vec<Move>,
captures: Vec<Move>,
}
/// A set of moves for a piece on the board.
pub(super) 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())
}
}