diff --git a/src/position.rs b/src/position.rs index 9967257..a5b65c7 100644 --- a/src/position.rs +++ b/src/position.rs @@ -828,15 +828,6 @@ impl Position { let forward = turn.forward(); - let x = lookup::bishop(king_square, blockers); - let y = lookup::rook(king_square, blockers); - let checkers = lookup::pawn_attack(turn, king_square) & theirs.pawn() - | lookup::knight(king_square) & theirs.knight() - | x & theirs.bishop() - | y & theirs.rook(); - - moves.checkers(checkers)?; - if moves.roles(Role::King) && global_mask_from.contains(king_square) { let attacked = { let blockers = blockers ^ ours.king(); @@ -894,9 +885,21 @@ impl Position { } } - if checkers.len() > 1 { + let x = lookup::bishop(king_square, blockers); + let y = lookup::rook(king_square, blockers); + let mut checkers = lookup::pawn_attack(turn, king_square) & theirs.pawn() + | lookup::knight(king_square) & theirs.knight() + | x & theirs.bishop() + | y & theirs.rook(); + moves.checkers(checkers)?; + let checker = checkers.next(); + if !checkers.is_empty() { return ControlFlow::Continue(()); } + let block_check = checker + .map(|checker| lookup::segment(king_square, checker)) + .unwrap_or(Bitboard(!0)); + let target_mask = global_mask_to & block_check; let blockers_x_ray = blockers & !(x | y); let pinned = ((lookup::bishop(king_square, blockers_x_ray) & theirs.bishop()) @@ -904,12 +907,6 @@ impl Position { .map(|sq| lookup::segment(king_square, sq)) .reduce_or(); - let checker = checkers.first(); - let block_check = checker - .map(|checker| lookup::segment(king_square, checker)) - .unwrap_or(Bitboard(!0)); - let target_mask = global_mask_to & block_check; - // pawns if moves.roles(Role::Pawn) { let kside = match turn {