[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:
parent
edf7d1cd2f
commit
626ac6245e
1 changed files with 17 additions and 38 deletions
|
@ -1,7 +1,5 @@
|
||||||
// Eryn Wells <eryn@erynwells.me>
|
// Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
use std::io::empty;
|
|
||||||
|
|
||||||
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
|
use super::{move_generator_declaration, MoveGeneratorInternal, MoveSet};
|
||||||
use crate::{
|
use crate::{
|
||||||
bitboard::BitBoard,
|
bitboard::BitBoard,
|
||||||
|
@ -29,44 +27,25 @@ impl<'pos> MoveGeneratorInternal for ClassicalMoveGenerator<'pos> {
|
||||||
|
|
||||||
let mut all_moves = BitBoard::empty();
|
let mut all_moves = BitBoard::empty();
|
||||||
|
|
||||||
// Find the first occupied square along the northward ray. Do this by
|
macro_rules! update_moves_with_ray {
|
||||||
// looking at the squares along that ray in trailing (south to north)
|
($direction:ident, $occupied_squares:tt) => {
|
||||||
// order.
|
let ray = BitBoard::ray(square, Direction::$direction);
|
||||||
let ray = BitBoard::ray(square, Direction::North);
|
if let Some(first_occupied_square) =
|
||||||
if let Some(first_occupied_square) = (ray & blockers).occupied_squares_trailing().next() {
|
BitBoard::$occupied_squares(&(ray & blockers)).next()
|
||||||
let remainder = BitBoard::ray(first_occupied_square, Direction::North);
|
{
|
||||||
let attack_ray = ray & !remainder;
|
let remainder = BitBoard::ray(first_occupied_square, Direction::$direction);
|
||||||
all_moves |= attack_ray;
|
let attack_ray = ray & !remainder;
|
||||||
} else {
|
all_moves |= attack_ray;
|
||||||
all_moves |= ray;
|
} else {
|
||||||
|
all_moves |= ray;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let ray = BitBoard::ray(square, Direction::East);
|
update_moves_with_ray!(North, occupied_squares_trailing);
|
||||||
if let Some(first_occupied_square) = (ray & blockers).occupied_squares_trailing().next() {
|
update_moves_with_ray!(East, occupied_squares_trailing);
|
||||||
let remainder = BitBoard::ray(first_occupied_square, Direction::East);
|
update_moves_with_ray!(South, occupied_squares);
|
||||||
let attack_ray = ray & !remainder;
|
update_moves_with_ray!(West, occupied_squares);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
||||||
let capture_moves_bb = all_moves & opposing_pieces;
|
let capture_moves_bb = all_moves & opposing_pieces;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue