[position] Fix all the unit tests
The pawn move generator only generated pushes for white pawns. The is_king_in_check returned an inverted flag. MoveSet needed a couple more validation methods: can_move_to_square and can_castle. The MakeMoveBuilder also needed a little more move validation using the above methods.
This commit is contained in:
parent
63758a2edd
commit
4a601c2b81
6 changed files with 82 additions and 31 deletions
|
@ -2,15 +2,16 @@
|
|||
|
||||
use crate::{r#move::Castle, Move, MoveBuilder};
|
||||
use chessfriend_bitboard::BitBoard;
|
||||
use chessfriend_core::{Color, Piece, PlacedPiece, Shape};
|
||||
use chessfriend_core::{Color, Piece, PlacedPiece, Shape, Square};
|
||||
|
||||
/// A set of bitboards defining the moves for a single piece on the board.
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
struct BitBoardSet {
|
||||
quiet: BitBoard,
|
||||
captures: BitBoard,
|
||||
}
|
||||
|
||||
/// A set of moves for a piece on the board.
|
||||
/// A set of moves for a single piece on the board.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub(crate) struct MoveSet {
|
||||
piece: PlacedPiece,
|
||||
|
@ -27,6 +28,17 @@ impl MoveSet {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn can_move_to_square(&self, to: Square) -> bool {
|
||||
self.bitboard().is_set(to)
|
||||
}
|
||||
|
||||
pub(crate) fn can_castle(&self, castle: Castle) -> bool {
|
||||
match castle {
|
||||
Castle::KingSide => (self.special & 0b1) != 0,
|
||||
Castle::QueenSide => (self.special & 0b10) != 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn quiet_moves(mut self, bitboard: BitBoard) -> MoveSet {
|
||||
self.bitboards.quiet = bitboard;
|
||||
self
|
||||
|
@ -52,7 +64,7 @@ impl MoveSet {
|
|||
self.bitboards.captures | self.bitboards.quiet
|
||||
}
|
||||
|
||||
pub(super) fn moves(&self) -> impl Iterator<Item = Move> + '_ {
|
||||
pub(crate) fn moves(&self) -> impl Iterator<Item = Move> + '_ {
|
||||
let piece = self.piece.piece();
|
||||
let from_square = self.piece.square();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue