[board] Copy the update_moves_with_ray macro into the rook move generator

This is an ugly copy/paste operation, but reduces the code in rook::ClassicalMoveGenerator somewhat.
This commit is contained in:
Eryn Wells 2024-01-06 20:34:16 -08:00
parent edf7d1cd2f
commit 626ac6245e

View file

@ -1,7 +1,5 @@
// Eryn Wells <eryn@erynwells.me>
use std::io::empty;
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
use crate::{
bitboard::BitBoard,
@ -29,44 +27,25 @@ impl<'pos> MoveGeneratorInternal for ClassicalMoveGenerator<'pos> {
let mut all_moves = BitBoard::empty();
// Find the first occupied square along the northward ray. Do this by
// looking at the squares along that ray in trailing (south to north)
// order.
let ray = BitBoard::ray(square, Direction::North);
if let Some(first_occupied_square) = (ray & blockers).occupied_squares_trailing().next() {
let remainder = BitBoard::ray(first_occupied_square, Direction::North);
let attack_ray = ray & !remainder;
all_moves |= attack_ray;
} else {
all_moves |= ray;
macro_rules! update_moves_with_ray {
($direction:ident, $occupied_squares:tt) => {
let ray = BitBoard::ray(square, Direction::$direction);
if let Some(first_occupied_square) =
BitBoard::$occupied_squares(&(ray & blockers)).next()
{
let remainder = BitBoard::ray(first_occupied_square, Direction::$direction);
let attack_ray = ray & !remainder;
all_moves |= attack_ray;
} else {
all_moves |= ray;
}
};
}
let ray = BitBoard::ray(square, Direction::East);
if let Some(first_occupied_square) = (ray & blockers).occupied_squares_trailing().next() {
let remainder = BitBoard::ray(first_occupied_square, Direction::East);
let attack_ray = ray & !remainder;
all_moves |= attack_ray;
} else {
all_moves |= ray;
}
let ray = BitBoard::ray(square, Direction::South);
if let Some(first_occupied_square) = (ray & blockers).occupied_squares().next() {
let remainder = BitBoard::ray(first_occupied_square, Direction::South);
let attack_ray = ray & !remainder;
all_moves |= attack_ray;
} else {
all_moves |= ray;
}
let ray = BitBoard::ray(square, Direction::West);
if let Some(first_occupied_square) = (ray & blockers).occupied_squares().next() {
let remainder = BitBoard::ray(first_occupied_square, Direction::West);
let attack_ray = ray & !remainder;
all_moves |= attack_ray;
} else {
all_moves |= ray;
}
update_moves_with_ray!(North, occupied_squares_trailing);
update_moves_with_ray!(East, occupied_squares_trailing);
update_moves_with_ray!(South, occupied_squares);
update_moves_with_ray!(West, occupied_squares);
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
let capture_moves_bb = all_moves & opposing_pieces;