Specify move type using new MoveType enum and update tests
This commit is contained in:
26
src/board.rs
26
src/board.rs
@@ -5,6 +5,11 @@ use crate::attack::{
|
||||
get_rook_attacks,
|
||||
};
|
||||
use crate::game::State;
|
||||
use crate::movegen::{
|
||||
bishop_pseudo_moves, king_pseudo_moves, knight_pseudo_moves, pawn_pseudo_moves,
|
||||
queen_pseudo_moves, rook_pseudo_moves,
|
||||
};
|
||||
use crate::r#move::{Move, MoveType, Promote};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Board {
|
||||
@@ -12,10 +17,6 @@ pub struct Board {
|
||||
pub black_pieces: [Piece; 6],
|
||||
pub state: State,
|
||||
}
|
||||
use crate::movegen::{
|
||||
bishop_pseudo_moves, king_pseudo_moves, knight_pseudo_moves, pawn_pseudo_moves,
|
||||
queen_pseudo_moves, rook_pseudo_moves, Move,
|
||||
};
|
||||
|
||||
impl Board {
|
||||
pub const fn new() -> Self {
|
||||
@@ -100,6 +101,21 @@ impl Board {
|
||||
|| enemy[Kind::King.idx()].bitboard & get_king_attacks(sq) != 0
|
||||
}
|
||||
|
||||
pub fn is_move_legit(&self, square: usize, opponent_color: Color) -> bool {
|
||||
!self.is_attacked(square, opponent_color)
|
||||
}
|
||||
|
||||
pub fn pseudo_moves_all(&self, color: Color) -> Vec<Move> {
|
||||
let mut moves = vec![];
|
||||
moves.extend(self.pseudo_moves(color, Kind::Pawn));
|
||||
moves.extend(self.pseudo_moves(color, Kind::Knight));
|
||||
moves.extend(self.pseudo_moves(color, Kind::Bishop));
|
||||
moves.extend(self.pseudo_moves(color, Kind::Rook));
|
||||
moves.extend(self.pseudo_moves(color, Kind::Queen));
|
||||
moves.extend(self.pseudo_moves(color, Kind::King));
|
||||
moves
|
||||
}
|
||||
|
||||
pub fn pseudo_moves(&self, color: Color, kind: Kind) -> Vec<Move> {
|
||||
let all_occupancies = self.get_all_occupancies();
|
||||
let (pieces, enemy_occupancies, own_occupancies) = match color {
|
||||
@@ -123,7 +139,7 @@ impl Board {
|
||||
self.state.get_en_passant_target_square(),
|
||||
color,
|
||||
),
|
||||
Kind::Knight => knight_pseudo_moves(pieces, own_occupancies),
|
||||
Kind::Knight => knight_pseudo_moves(pieces, all_occupancies, own_occupancies),
|
||||
Kind::Bishop => bishop_pseudo_moves(pieces, all_occupancies, own_occupancies),
|
||||
Kind::Rook => rook_pseudo_moves(pieces, all_occupancies, own_occupancies),
|
||||
Kind::Queen => queen_pseudo_moves(pieces, all_occupancies, own_occupancies),
|
||||
|
||||
Reference in New Issue
Block a user