[position] For non-King move generators, only generate moves if the push and captures masks aren't empty

Always generate King moves.
This commit is contained in:
Eryn Wells 2024-02-02 08:03:51 -08:00
parent 31903cb514
commit 986758d011
7 changed files with 35 additions and 26 deletions

View file

@ -51,10 +51,15 @@ macro_rules! move_generator_declaration {
capture_mask: chessfriend_bitboard::BitBoard,
push_mask: chessfriend_bitboard::BitBoard,
) -> $name {
$name {
color,
move_sets: Self::move_sets(position, color, capture_mask, push_mask),
}
let move_sets = if Self::shape() == chessfriend_core::Shape::King
|| (!capture_mask.is_empty() && !push_mask.is_empty())
{
Self::move_sets(position, color, capture_mask, push_mask)
} else {
std::collections::BTreeMap::new()
};
$name { color, move_sets }
}
}
};
@ -84,7 +89,11 @@ macro_rules! move_generator_declaration {
pub(self) use move_generator_declaration;
trait MoveGeneratorInternal {
fn piece(color: Color) -> Piece;
fn shape() -> Shape;
fn piece(color: Color) -> Piece {
Piece::new(color, Self::shape())
}
fn move_sets(
position: &Position,

View file

@ -3,13 +3,13 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::Position;
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Direction, Piece, PlacedPiece};
use chessfriend_core::{Direction, PlacedPiece, Shape};
move_generator_declaration!(ClassicalMoveGenerator);
impl MoveGeneratorInternal for ClassicalMoveGenerator {
fn piece(color: Color) -> Piece {
Piece::bishop(color)
fn shape() -> Shape {
Shape::Bishop
}
fn move_set_for_piece(

View file

@ -6,15 +6,15 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::{r#move::Castle, Position};
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Piece, PlacedPiece};
use chessfriend_core::{PlacedPiece, Shape};
move_generator_declaration!(KingMoveGenerator, struct);
move_generator_declaration!(KingMoveGenerator, new);
move_generator_declaration!(KingMoveGenerator, getters);
impl MoveGeneratorInternal for KingMoveGenerator {
fn piece(color: Color) -> Piece {
Piece::king(color)
fn shape() -> Shape {
Shape::King
}
fn move_set_for_piece(
@ -59,7 +59,7 @@ mod tests {
use super::*;
use crate::{assert_move_list, position, test_position, Move, MoveBuilder, PositionBuilder};
use chessfriend_bitboard::bitboard;
use chessfriend_core::{piece, Square};
use chessfriend_core::{piece, Color, Square};
use std::collections::HashSet;
#[test]

View file

@ -3,13 +3,13 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::Position;
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Piece, PlacedPiece};
use chessfriend_core::{PlacedPiece, Shape};
move_generator_declaration!(KnightMoveGenerator);
impl MoveGeneratorInternal for KnightMoveGenerator {
fn piece(color: Color) -> Piece {
Piece::knight(color)
fn shape() -> Shape {
Shape::Knight
}
fn move_set_for_piece(
@ -35,7 +35,7 @@ impl MoveGeneratorInternal for KnightMoveGenerator {
mod tests {
use super::*;
use crate::{position, Move, MoveBuilder};
use chessfriend_core::{piece, Square};
use chessfriend_core::{piece, Color, Square};
use std::collections::HashSet;
#[test]

View file

@ -3,7 +3,7 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::Position;
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Piece, PlacedPiece, Rank, Square};
use chessfriend_core::{Piece, PlacedPiece, Rank, Shape, Square};
#[derive(Debug)]
struct MoveIterator(usize, usize);
@ -11,8 +11,8 @@ struct MoveIterator(usize, usize);
move_generator_declaration!(PawnMoveGenerator);
impl MoveGeneratorInternal for PawnMoveGenerator {
fn piece(color: Color) -> Piece {
Piece::pawn(color)
fn shape() -> Shape {
Shape::Pawn
}
fn move_set_for_piece(
@ -63,7 +63,7 @@ impl PawnMoveGenerator {
mod tests {
use super::*;
use crate::{assert_move_list, position::DiagramFormatter, test_position, Move, MoveBuilder};
use chessfriend_core::{piece, Square};
use chessfriend_core::{piece, Color, Square};
use std::collections::HashSet;
#[test]

View file

@ -3,13 +3,13 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::Position;
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Direction, Piece, PlacedPiece};
use chessfriend_core::{Direction, PlacedPiece, Shape};
move_generator_declaration!(ClassicalMoveGenerator);
impl MoveGeneratorInternal for ClassicalMoveGenerator {
fn piece(color: Color) -> Piece {
Piece::queen(color)
fn shape() -> Shape {
Shape::Queen
}
fn move_set_for_piece(

View file

@ -3,13 +3,13 @@
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::Position;
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Direction, Piece, PlacedPiece};
use chessfriend_core::{Direction, PlacedPiece, Shape};
move_generator_declaration!(ClassicalMoveGenerator);
impl MoveGeneratorInternal for ClassicalMoveGenerator {
fn piece(color: Color) -> Piece {
Piece::rook(color)
fn shape() -> Shape {
Shape::Rook
}
fn move_set_for_piece(