[moves, position] Move MoveRecord to the moves crate
This commit is contained in:
parent
b8f45aaece
commit
34e8c08c36
5 changed files with 8 additions and 7 deletions
|
@ -6,8 +6,10 @@ pub mod testing;
|
|||
mod builder;
|
||||
mod defs;
|
||||
mod moves;
|
||||
mod record;
|
||||
|
||||
pub use builder::{Builder, Error as BuildMoveError, Result as BuildMoveResult};
|
||||
pub use defs::{Kind, PromotionShape};
|
||||
pub use generators::GeneratedMove;
|
||||
pub use moves::Move;
|
||||
pub use record::MoveRecord;
|
||||
|
|
43
moves/src/record.rs
Normal file
43
moves/src/record.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::Move;
|
||||
use chessfriend_board::{board::HalfMoveClock, Board, CastleRights};
|
||||
use chessfriend_core::{Color, Piece, Square};
|
||||
|
||||
/// A record of a move made on a board. This struct contains all the information
|
||||
/// necessary to restore the board position to its state immediately before the
|
||||
/// move was made.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MoveRecord {
|
||||
/// The color of the player who made the move
|
||||
pub color: Color,
|
||||
|
||||
/// The move played
|
||||
pub ply: Move,
|
||||
|
||||
/// The en passant square when the move was made
|
||||
pub en_passant_target: Option<Square>,
|
||||
|
||||
/// Castling rights for all players when the move was made
|
||||
pub castling_rights: CastleRights,
|
||||
|
||||
/// The half move clock when the move was made
|
||||
pub half_move_clock: HalfMoveClock,
|
||||
|
||||
/// The piece captured by the move, if any
|
||||
pub captured_piece: Option<Piece>,
|
||||
}
|
||||
|
||||
impl MoveRecord {
|
||||
#[must_use]
|
||||
pub fn new(board: &Board, ply: Move, capture: Option<Piece>) -> Self {
|
||||
Self {
|
||||
color: board.active_color,
|
||||
ply,
|
||||
en_passant_target: board.en_passant_target,
|
||||
castling_rights: board.castling_rights,
|
||||
half_move_clock: board.half_move_clock,
|
||||
captured_piece: capture,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue