[board] Extend the Move type with two builder-style methods for capturing and promotion

These two methods replace self with one that has a populated capture or promotion field.
This commit is contained in:
Eryn Wells 2023-12-31 09:28:21 -08:00
parent adc2f76e00
commit c2c0af20fb

View file

@ -1,16 +1,35 @@
// Eryn Wells <eryn@erynwells.me>
use crate::piece::Piece;
use crate::piece::{Piece, PlacedPiece, Shape};
use crate::Square;
#[derive(Debug, Clone, Eq, Hash, PartialEq)]
pub struct Move {
pub piece: Piece,
pub from: Square,
pub to: Square,
piece: Piece,
from: Square,
to: Square,
capturing: Option<PlacedPiece>,
promoting_to: Option<Shape>,
}
impl Move {
pub fn new(piece: Piece, from: Square, to: Square) -> Move {
Move { piece, from, to }
Move {
piece,
from,
to,
capturing: None,
promoting_to: None,
}
}
pub fn capturing(mut self, piece: PlacedPiece) -> Move {
self.capturing = Some(piece);
self
}
pub fn promoting_to(mut self, shape: Shape) -> Move {
self.promoting_to = Some(shape);
self
}
}