Move MoveParameter handling inside make/unmake_move
This commit is contained in:
@@ -12,11 +12,12 @@ use crate::movegen::move_generator::{
|
||||
};
|
||||
use crate::movegen::r#move::{Move, MoveType, Promote};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Board {
|
||||
pub white_pieces: [Piece; 6],
|
||||
pub black_pieces: [Piece; 6],
|
||||
pub state: State,
|
||||
pub history: History,
|
||||
}
|
||||
|
||||
impl Board {
|
||||
@@ -39,6 +40,7 @@ impl Board {
|
||||
Piece::new(0x1000000000000000, PieceType::King, Color::Black),
|
||||
],
|
||||
state: State::new(),
|
||||
history: History::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +63,7 @@ impl Board {
|
||||
Piece::new(0x0, PieceType::King, Color::Black),
|
||||
],
|
||||
state: State::new(),
|
||||
history: History::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +195,8 @@ impl Board {
|
||||
let color = self.state.current_player();
|
||||
let pawn_move = self.is_pawn_move(mv.src);
|
||||
let mut en_passant_square = None;
|
||||
self.history
|
||||
.push_move_parameters(MoveParameters::build(&self, mv));
|
||||
|
||||
match &mv.move_type {
|
||||
MoveType::Quiet => {
|
||||
@@ -231,7 +236,9 @@ impl Board {
|
||||
Self::update_game_state(&mut self.state, mv, color, pawn_move, en_passant_square);
|
||||
}
|
||||
|
||||
pub fn unmake_move(&mut self, move_parameters: &MoveParameters) {
|
||||
pub fn unmake_move(&mut self) {
|
||||
let move_parameters =
|
||||
std::mem::take(&mut self.history.pop_move_parameters()).unwrap_or_default();
|
||||
let color_before_move = self.state.change_side();
|
||||
self.state.revert_full_move(color_before_move);
|
||||
self.state.en_passant_square = move_parameters.en_passant_square;
|
||||
@@ -437,7 +444,7 @@ impl PieceType {
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use super::bitboard::square_to_bitboard;
|
||||
use super::history::MoveParameters;
|
||||
use super::history::{History, MoveParameters};
|
||||
use super::square::Square;
|
||||
use super::state::Castle;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user