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
§Example
use chess_lab::constants::{Color, PieceType, Position, Move, MoveType};
use chess_lab::logic::Piece;
let piece = Piece {
color: Color::White,
piece_type: PieceType::Pawn,
};
let from = Position::new(4, 1);
let to = Position::new(4, 3);
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
);
assert_eq!(mv.to_string(), "e4");
Fields§
§piece: Piece
§from: Position
§to: Position
§move_type: MoveType
§captured_piece: Option<PieceType>
§rook_from: Option<Position>
§ambiguity: (bool, bool)
§check: bool
§checkmate: bool
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,
) -> Move
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, ) -> Move
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
§Panics
Panics if the move is a capture, but no captured piece is provided Panics if the move is not a capture, but a captured piece is provided Panics if the move is a promotion, but the piece is not a pawn Panics if the move is a castle, but the piece is not a king Panics if the move is a castle, but the rook position is not provided Panics if the move is an en passant, but the piece is not a pawn
§Example
use chess_lab::constants::{Color, PieceType, Position, Move, MoveType};
use chess_lab::logic::Piece;
let piece = Piece {
color: Color::White,
piece_type: PieceType::Pawn,
};
let from = Position::new(4, 1);
let to = Position::new(4, 3);
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
);
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 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