From c2c0af20fb96e2f33421411f217f7c1fb06c0942 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 31 Dec 2023 09:28:21 -0800 Subject: [PATCH] [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. --- board/src/moves/move.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/board/src/moves/move.rs b/board/src/moves/move.rs index 7e9c4e3..53f6ecc 100644 --- a/board/src/moves/move.rs +++ b/board/src/moves/move.rs @@ -1,16 +1,35 @@ // Eryn Wells -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, + promoting_to: Option, } 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 } }