[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, capture_mask: chessfriend_bitboard::BitBoard,
push_mask: chessfriend_bitboard::BitBoard, push_mask: chessfriend_bitboard::BitBoard,
) -> $name { ) -> $name {
$name { let move_sets = if Self::shape() == chessfriend_core::Shape::King
color, || (!capture_mask.is_empty() && !push_mask.is_empty())
move_sets: Self::move_sets(position, color, capture_mask, push_mask), {
} 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; pub(self) use move_generator_declaration;
trait MoveGeneratorInternal { trait MoveGeneratorInternal {
fn piece(color: Color) -> Piece; fn shape() -> Shape;
fn piece(color: Color) -> Piece {
Piece::new(color, Self::shape())
}
fn move_sets( fn move_sets(
position: &Position, position: &Position,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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