update move generation for pinned pieces
This commit is contained in:
parent
2426a0cdb3
commit
d500f525f7
2 changed files with 33 additions and 12 deletions
|
|
@ -136,6 +136,22 @@ static LINES: BySquare<BySquare<Bitboard>> = by_square!(a, BySquare([Bitboard(0)
|
|||
})
|
||||
});
|
||||
|
||||
static BISHOP_LINES: BySquare<Bitboard> = by_square!(sq, Bitboard(0), {
|
||||
let mut res = 0;
|
||||
loop_bishop_directions!(d, {
|
||||
res |= RAYS.get(sq).get(d).0;
|
||||
});
|
||||
Bitboard(res)
|
||||
});
|
||||
|
||||
static ROOK_LINES: BySquare<Bitboard> = by_square!(sq, Bitboard(0), {
|
||||
let mut res = 0;
|
||||
loop_rook_directions!(d, {
|
||||
res |= RAYS.get(sq).get(d).0;
|
||||
});
|
||||
Bitboard(res)
|
||||
});
|
||||
|
||||
static SEGMENTS: BySquare<BySquare<Bitboard>> = by_square!(a, BySquare([Bitboard(0); 64]), {
|
||||
by_square!(b, Bitboard(0), {
|
||||
let mut res = 0;
|
||||
|
|
@ -240,6 +256,14 @@ pub(crate) fn line(a: Square, b: Square) -> Bitboard {
|
|||
*LINES.get(a).get(b)
|
||||
}
|
||||
#[inline]
|
||||
pub(crate) fn bishop_lines(square: Square) -> Bitboard {
|
||||
*BISHOP_LINES.get(square)
|
||||
}
|
||||
#[inline]
|
||||
pub(crate) fn rook_lines(square: Square) -> Bitboard {
|
||||
*ROOK_LINES.get(square)
|
||||
}
|
||||
#[inline]
|
||||
pub(crate) fn segment(a: Square, b: Square) -> Bitboard {
|
||||
*SEGMENTS.get(a).get(b)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -995,13 +995,10 @@ impl Position {
|
|||
}
|
||||
|
||||
let blockers_x_ray = blockers & !(x | y);
|
||||
let pinned_diagonally = (lookup::bishop(king_square, blockers_x_ray) & theirs.bishop())
|
||||
.map(|sq| lookup::segment(king_square, sq))
|
||||
.reduce_or();
|
||||
let pinned_horizontally = (lookup::rook(king_square, blockers_x_ray) & theirs.rook())
|
||||
.map(|sq| lookup::segment(king_square, sq))
|
||||
.reduce_or();
|
||||
let pinned = pinned_diagonally | pinned_horizontally;
|
||||
let pinned = ((lookup::bishop(king_square, blockers_x_ray) & theirs.bishop())
|
||||
| (lookup::rook(king_square, blockers_x_ray) & theirs.rook()))
|
||||
.map(|sq| lookup::segment(king_square, sq))
|
||||
.reduce_or();
|
||||
|
||||
let checker = checkers.first();
|
||||
let block_check = checker
|
||||
|
|
@ -1173,8 +1170,8 @@ impl Position {
|
|||
|
||||
// pinned pieces
|
||||
{
|
||||
let aux = |moves: &mut T, role, mask| {
|
||||
for from in global_mask_from & *ours.get(role) & mask {
|
||||
let aux = |moves: &mut T, role, role_mask| {
|
||||
for from in global_mask_from & pinned & role_mask & *ours.get(role) {
|
||||
moves.extend(
|
||||
(global_mask_to & !us & pinned & lookup::line(king_square, from)).map(
|
||||
|to| RawMove {
|
||||
|
|
@ -1188,13 +1185,13 @@ impl Position {
|
|||
}
|
||||
};
|
||||
if moves.roles(Role::Bishop) {
|
||||
aux(moves, Role::Bishop, pinned_diagonally);
|
||||
aux(moves, Role::Bishop, lookup::bishop_lines(king_square));
|
||||
}
|
||||
if moves.roles(Role::Rook) {
|
||||
aux(moves, Role::Rook, pinned_horizontally);
|
||||
aux(moves, Role::Rook, lookup::rook_lines(king_square));
|
||||
}
|
||||
if moves.roles(Role::Queen) {
|
||||
aux(moves, Role::Queen, pinned);
|
||||
aux(moves, Role::Queen, !Bitboard::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue