pub struct Move {
pub piece: Piece,
pub from: Position,
pub to: Position,
pub move_type: MoveType,
pub captured_piece: Option<PieceType>,
pub rook_from: Option<Position>,
pub ambiguity: (bool, bool),
pub check: bool,
pub checkmate: bool,
}Expand description
Represents a move in a chess game
Fields§
§piece: PieceThe Piece that is moving
from: PositionThe Position the piece is moving from
to: PositionThe Position the piece is moving to
move_type: MoveTypeThe type of the move
captured_piece: Option<PieceType>The type of the piece that is captured, if any
rook_from: Option<Position>The position of the rook, if the move is a castle
ambiguity: (bool, bool)A tuple of booleans representing the ambiguity of the move
check: boolWhether the move puts the opponent in check
checkmate: boolWhether the move puts the opponent in checkmate
Implementations§
Source§impl Move
impl Move
Sourcepub fn new(
piece: Piece,
from: Position,
to: Position,
move_type: MoveType,
captured_piece: Option<PieceType>,
rook_from: Option<Position>,
ambiguity: (bool, bool),
check: bool,
checkmate: bool,
) -> Result<Move, MoveInfoError>
pub fn new( piece: Piece, from: Position, to: Position, move_type: MoveType, captured_piece: Option<PieceType>, rook_from: Option<Position>, ambiguity: (bool, bool), check: bool, checkmate: bool, ) -> Result<Move, MoveInfoError>
Creates a new Move
§Arguments
piece: The Piece that is movingfrom: The Position the piece is moving fromto: The Position the piece is moving tomove_type: The type of the movecaptured_piece: The Piece that is captured, if anyrook_from: The Position of the rook, if the move is a castleambiguity: A tuple of booleans representing the ambiguity of the movecheck: Whether the move puts the opponent in checkcheckmate: Whether the move puts the opponent in checkmate
§Returns
A Result<Move, MoveInfoError>
Ok(Move): The move if it is validErr(MoveInfoError): The error if the move is invalid
§Example
use chess_lab::core::{Color, PieceType, Piece, Position, Move, MoveType};
let piece = Piece::new(Color::White, PieceType::Pawn);
let from = Position::new(4, 1).unwrap();
let to = Position::new(4, 3).unwrap();
let move_type = MoveType::Normal {
capture: false,
promotion: None,
};
let captured_piece = None;
let rook_from = None;
let ambiguity = (false, false);
let mv = Move::new(
piece,
from,
to,
move_type,
captured_piece,
rook_from,
ambiguity,
false,
false
).unwrap();
assert_eq!(mv.to_string(), "e4");Trait Implementations§
impl StructuralPartialEq for Move
Auto Trait Implementations§
impl Freeze for Move
impl RefUnwindSafe for Move
impl Send for Move
impl Sync for Move
impl Unpin for Move
impl UnsafeUnpin for Move
impl UnwindSafe for Move
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more