rules: fix promotion when applying a move

This commit is contained in:
dece 2020-06-09 23:23:22 +02:00
parent c4f5412cd4
commit cef59b9913
2 changed files with 8 additions and 4 deletions

View file

@ -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`. /// Return true if the piece on this square is of type `piece_type`.
#[inline] #[inline]
pub const fn is_type(square: u8, piece_type: u8) -> bool { get_type(square) == piece_type } 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. /// Return true if the piece on this square has this color.
#[inline] #[inline]
pub const fn is_color(square: u8, color: u8) -> bool { has_flag(square, color) } 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. /// Return the color of the piece on this square.
#[inline] #[inline]
pub const fn get_color(square: u8) -> u8 { square & SQ_COLOR_MASK } 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. /// Get opposite color.
#[inline] #[inline]

View file

@ -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 { else {
let piece = get_square(board, &m.1); let piece = get_square(board, &m.1);
if is_white(piece) && game_state.castling & CASTLING_WH_MASK != 0 { 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 { } else {
move_piece(board, &m.0, &m.1); 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);
}
} }
} }