rules: fix promotion when applying a move
This commit is contained in:
parent
c4f5412cd4
commit
cef59b9913
|
@ -39,9 +39,6 @@ pub const fn get_type(square: u8) -> u8 { square & SQ_TYPE_MASK }
|
|||
/// Return true if the piece on this square is of type `piece_type`.
|
||||
#[inline]
|
||||
pub const fn is_type(square: u8, piece_type: u8) -> bool { get_type(square) == piece_type }
|
||||
/// Return true if the piece on this square is the same as `piece`.
|
||||
#[inline]
|
||||
pub const fn is_piece(square: u8, piece: u8) -> bool { has_flag(square, piece) }
|
||||
/// Return true if the piece on this square has this color.
|
||||
#[inline]
|
||||
pub const fn is_color(square: u8, color: u8) -> bool { has_flag(square, color) }
|
||||
|
@ -54,6 +51,9 @@ pub const fn is_black(square: u8) -> bool { is_color(square, SQ_BL) }
|
|||
/// Return the color of the piece on this square.
|
||||
#[inline]
|
||||
pub const fn get_color(square: u8) -> u8 { square & SQ_COLOR_MASK }
|
||||
/// Return true if the piece on this square is the same as `piece`.
|
||||
#[inline]
|
||||
pub const fn is_piece(square: u8, piece: u8) -> bool { has_flag(square, piece) }
|
||||
|
||||
/// Get opposite color.
|
||||
#[inline]
|
||||
|
|
|
@ -72,7 +72,7 @@ pub fn apply_move_to(board: &mut Board, game_state: &mut GameState, m: &Move) {
|
|||
_ => {}
|
||||
};
|
||||
}
|
||||
// Else, check if it's either to rook or the king that moved.
|
||||
// Else, check if it's either a rook or the king that moved.
|
||||
else {
|
||||
let piece = get_square(board, &m.1);
|
||||
if is_white(piece) && game_state.castling & CASTLING_WH_MASK != 0 {
|
||||
|
@ -135,6 +135,10 @@ pub fn apply_move_to_board(board: &mut Board, m: &Move) {
|
|||
}
|
||||
} else {
|
||||
move_piece(board, &m.0, &m.1);
|
||||
if let Some(prom_type) = m.2 {
|
||||
let color = get_color(get_square(board, &m.1));
|
||||
set_square(board, &m.1, color|prom_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue