Make en_passant_square an Option<u8>
This commit is contained in:
@@ -3,7 +3,6 @@ use crate::attack::{
|
||||
get_rook_attacks,
|
||||
};
|
||||
use crate::board::Color;
|
||||
use crate::game::State;
|
||||
use u64 as Bitboard;
|
||||
|
||||
const NOT_A_FILE: Bitboard = 0xfefefefefefefefe;
|
||||
@@ -27,17 +26,25 @@ pub fn pawn_pseudo_moves(
|
||||
pawns: Bitboard,
|
||||
all_occupancies: Bitboard,
|
||||
enemy_occupancies: Bitboard,
|
||||
state: State,
|
||||
en_passant_square: Option<u8>,
|
||||
color: Color,
|
||||
) -> Vec<Move> {
|
||||
let mut moves: Vec<Move> = vec![];
|
||||
match color {
|
||||
Color::White => {
|
||||
moves.extend(white_pawn_quiet_moves(pawns, all_occupancies));
|
||||
moves.extend(white_pawn_capture_moves(pawns, enemy_occupancies, state));
|
||||
moves.extend(white_pawn_capture_moves(
|
||||
pawns,
|
||||
enemy_occupancies,
|
||||
en_passant_square,
|
||||
));
|
||||
}
|
||||
Color::Black => {
|
||||
moves.extend(black_pawn_capture_moves(pawns, enemy_occupancies, state));
|
||||
moves.extend(black_pawn_capture_moves(
|
||||
pawns,
|
||||
enemy_occupancies,
|
||||
en_passant_square,
|
||||
));
|
||||
moves.extend(black_pawn_quiet_moves(pawns, all_occupancies));
|
||||
}
|
||||
}
|
||||
@@ -91,7 +98,7 @@ fn black_pawn_quiet_moves(pawns: Bitboard, occupancies: Bitboard) -> Vec<Move> {
|
||||
fn white_pawn_capture_moves(
|
||||
pawns: Bitboard,
|
||||
enemy_occupancies: Bitboard,
|
||||
state: State,
|
||||
en_passant_square: Option<u8>,
|
||||
) -> Vec<Move> {
|
||||
let mut moves: Vec<Move> = vec![];
|
||||
let mut w_pawns_capture_east = pawns & ((enemy_occupancies >> 9) & NOT_H_FILE);
|
||||
@@ -110,19 +117,18 @@ fn white_pawn_capture_moves(
|
||||
w_pawns_capture_west &= w_pawns_capture_west - 1;
|
||||
}
|
||||
|
||||
let epts = state.get_en_passant_target_square();
|
||||
if epts != 0 {
|
||||
let attacked_from = get_pawn_attacks(epts as usize, Color::Black);
|
||||
if let Some(en_passant_square) = en_passant_square {
|
||||
let attacked_from = get_pawn_attacks(en_passant_square as usize, Color::Black);
|
||||
let result = attacked_from & pawns;
|
||||
moves.push(Move::new(result.trailing_zeros(), epts as u32));
|
||||
}
|
||||
moves.push(Move::new(result.trailing_zeros(), en_passant_square as u32));
|
||||
};
|
||||
moves
|
||||
}
|
||||
|
||||
fn black_pawn_capture_moves(
|
||||
pawns: Bitboard,
|
||||
enemy_occupancies: Bitboard,
|
||||
state: State,
|
||||
en_passant_square: Option<u8>,
|
||||
) -> Vec<Move> {
|
||||
let mut moves: Vec<Move> = vec![];
|
||||
let mut b_pawns_capture_east = pawns & ((enemy_occupancies << 7) & NOT_H_FILE);
|
||||
@@ -142,12 +148,11 @@ fn black_pawn_capture_moves(
|
||||
b_pawns_capture_west &= b_pawns_capture_west - 1;
|
||||
}
|
||||
|
||||
let epts = state.get_en_passant_target_square();
|
||||
if epts != 0 {
|
||||
let attacked_from = get_pawn_attacks(epts as usize, Color::White);
|
||||
if let Some(en_passant_square) = en_passant_square {
|
||||
let attacked_from = get_pawn_attacks(en_passant_square as usize, Color::White);
|
||||
let result = attacked_from & pawns;
|
||||
moves.push(Move::new(result.trailing_zeros(), epts as u32));
|
||||
}
|
||||
moves.push(Move::new(result.trailing_zeros(), en_passant_square as u32));
|
||||
};
|
||||
moves
|
||||
}
|
||||
|
||||
@@ -190,7 +195,6 @@ pub fn bishop_pseudo_moves(
|
||||
bishops &= bishops - 1;
|
||||
}
|
||||
moves
|
||||
// moves arkoudaki se agapo polu! to gataki sou
|
||||
}
|
||||
|
||||
pub fn rook_pseudo_moves(
|
||||
|
||||
Reference in New Issue
Block a user