From cef59b991380c83776b829c0c98b5ffc1ac42e85 Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 9 Jun 2020 23:23:22 +0200 Subject: [PATCH] rules: fix promotion when applying a move --- src/board.rs | 6 +++--- src/rules.rs | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/board.rs b/src/board.rs index ab258a5..5955689 100644 --- a/src/board.rs +++ b/src/board.rs @@ -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] diff --git a/src/rules.rs b/src/rules.rs index 64a03e8..3474c32 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -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); + } } }