pub enum ChessMoveType {
Move {
original_position: (usize, usize),
new_position: (usize, usize),
piece: ChessPiece,
taken_piece: Option<ChessPiece>,
promotion: Option<ChessPiece>,
},
EnPassant {
original_position: (usize, usize),
new_position: (usize, usize),
piece: ChessPiece,
taken_piece: ChessPiece,
taken_piece_position: (usize, usize),
promotion: Option<ChessPiece>,
},
Castle {
rook_original_position: (usize, usize),
rook_new_position: (usize, usize),
king_original_position: (usize, usize),
king_new_position: (usize, usize),
},
}Expand description
Represents different types of simple_chess moves.
This enum captures the state and specific details of various types of legal simple_chess moves. It provides functionality to apply and undo these moves on a simple_chess board.
Variants§
Move
A regular piece move which might include capturing an opponent’s piece or promoting a pawn.
Fields:
original_position: (usize, usize) - The starting position of the simple_chess piece.new_position: (usize, usize) - The destination position of the simple_chess piece.piece: ChessPiece - The simple_chess piece being moved.taken_piece: Option- The opponent’s piece captured during this move, if any. promotion: Option- The piece type a pawn is promoted to, if applicable.
EnPassant
A special pawn capture move where a pawn captures another pawn that has moved two squares forward from its starting position on the previous turn.
Fields:
original_position: (usize, usize) - The starting position of the pawn.new_position: (usize, usize) - The destination position of the pawn after capturing.piece: ChessPiece - The pawn performing the en passant capture.taken_piece: ChessPiece - The opponent’s pawn being captured.taken_piece_position: (usize, usize) - The position of the captured pawn.promotion: Option- The piece type if the pawn is promoted, if applicable.
Castle
A special move involving the king and a rook where both pieces move simultaneously.
Fields:
rook_original_position: (usize, usize) - The starting position of the rook.rook_new_position: (usize, usize) - The destination position of the rook.king_original_position: (usize, usize) - The starting position of the king.king_new_position: (usize, usize) - The destination position of the king.
Implementations§
Source§impl ChessMoveType
impl ChessMoveType
Sourcepub fn make_move(&self, board: &mut Board<ChessPiece>)
pub fn make_move(&self, board: &mut Board<ChessPiece>)
Applies the current move to the simple_chess board.
This method performs the actual move on the board by repositioning the involved pieces according to the move type.
§Arguments
board- A mutable reference to the simple_chess board on which the move will be applied.
§Examples
use simple_chess::ChessMoveType;
use simple_chess::Color::White;
use simple_chess::piece::ChessPiece;
use simple_chess::piece::PieceType::Pawn;
use game_board::Board;
let mut board = Board::build(8, 8).unwrap();
let original_position = (0, 1);
board.place_piece(ChessPiece::new(Pawn, White), original_position.0, original_position.1);
let game_move = ChessMoveType::Move {
original_position,
new_position: (0, 2),
piece: *board.get_piece_at_space(original_position.0, original_position.1).unwrap(),
taken_piece: None,
promotion: None,
};
assert!(board.get_piece_at_space(0, 2).is_none());
game_move.make_move(&mut board);
assert!(board.get_piece_at_space(original_position.0, original_position.1).is_none());
assert_eq!(Pawn, board.get_piece_at_space(0, 2).unwrap().get_piece_type());
assert_eq!(White, board.get_piece_at_space(0, 2).unwrap().get_color());pub fn undo_move(&self, board: &mut Board<ChessPiece>)
Trait Implementations§
Source§impl Clone for ChessMoveType
impl Clone for ChessMoveType
Source§fn clone(&self) -> ChessMoveType
fn clone(&self) -> ChessMoveType
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChessMoveType
impl Debug for ChessMoveType
Source§impl Display for ChessMoveType
impl Display for ChessMoveType
Source§impl PartialEq for ChessMoveType
impl PartialEq for ChessMoveType
impl Copy for ChessMoveType
impl StructuralPartialEq for ChessMoveType
Auto Trait Implementations§
impl Freeze for ChessMoveType
impl RefUnwindSafe for ChessMoveType
impl Send for ChessMoveType
impl Sync for ChessMoveType
impl Unpin for ChessMoveType
impl UnwindSafe for ChessMoveType
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