[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:
parent
adc2f76e00
commit
c2c0af20fb
1 changed files with 24 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue