@@ -430,7 +430,6 @@ impl Board {
430430 // This "hack" is used to speed up the implementation of `Board::is_legal`.
431431 let stm = self . side_to_move ( ) ;
432432 let occupancies = self . occupancies ( ) ^ self . colored_pieces ( stm, PieceType :: King ) ;
433-
434433 let mut threats = pawn_attacks_setwise ( self . colored_pieces ( !stm, PieceType :: Pawn ) , !stm) ;
435434 self . state . piece_threats [ PieceType :: Pawn ] = threats;
436435
@@ -466,25 +465,28 @@ impl Board {
466465 | self . piece_threats ( PieceType :: Rook )
467466 | self . piece_threats ( PieceType :: Queen )
468467 | self . piece_threats ( PieceType :: King ) ;
469- }
470468
471- /// Updates the checkers bitboard to mark opponent pieces currently threatening our king,
472- /// and our pinned pieces that cannot move without leaving the king in check.
473- pub fn update_king_threats ( & mut self ) {
474- let stm = self . side_to_move ( ) ;
475- let our_king = self . king_square ( stm) ;
469+ let diagonal = self . pieces2 ( PieceType :: Bishop , PieceType :: Queen ) ;
470+ let orthogonal = self . pieces2 ( PieceType :: Rook , PieceType :: Queen ) ;
476471
477472 self . state . pinned = [ Bitboard :: default ( ) ; 2 ] ;
478473 self . state . pinners = [ Bitboard :: default ( ) ; 2 ] ;
479- self . state . checkers = ( pawn_attacks ( our_king, stm) & self . colored_pieces ( !stm, PieceType :: Pawn ) )
480- | ( knight_attacks ( our_king) & self . colored_pieces ( !stm, PieceType :: Knight ) ) ;
481-
482- let diagonal = self . pieces2 ( PieceType :: Bishop , PieceType :: Queen ) ;
483- let orthogonal = self . pieces2 ( PieceType :: Rook , PieceType :: Queen ) ;
484474
485475 for color in [ Color :: White , Color :: Black ] {
486476 let king = self . king_square ( color) ;
487477
478+ if color == stm {
479+ self . state . checkers = ( pawn_attacks ( king, stm) & self . colored_pieces ( !stm, PieceType :: Pawn ) )
480+ | ( knight_attacks ( king) & self . colored_pieces ( !stm, PieceType :: Knight ) ) ;
481+ } else {
482+ self . state . checking_squares [ PieceType :: Pawn ] = pawn_attacks ( king, !stm) ;
483+ self . state . checking_squares [ PieceType :: Knight ] = knight_attacks ( king) ;
484+ self . state . checking_squares [ PieceType :: Bishop ] = bishop_attacks ( king, self . occupancies ( ) ) ;
485+ self . state . checking_squares [ PieceType :: Rook ] = rook_attacks ( king, self . occupancies ( ) ) ;
486+ self . state . checking_squares [ PieceType :: Queen ] =
487+ self . checking_squares ( PieceType :: Bishop ) | self . checking_squares ( PieceType :: Rook ) ;
488+ }
489+
488490 let diagonal = diagonal & bishop_attacks ( king, self . colors ( !color) ) & self . colors ( !color) ;
489491 let orthogonal = orthogonal & rook_attacks ( king, self . colors ( !color) ) & self . colors ( !color) ;
490492
@@ -503,14 +505,6 @@ impl Board {
503505 }
504506 }
505507 }
506-
507- let their_king = self . king_square ( !stm) ;
508- self . state . checking_squares [ PieceType :: Pawn ] = pawn_attacks ( their_king, !stm) ;
509- self . state . checking_squares [ PieceType :: Knight ] = knight_attacks ( their_king) ;
510- self . state . checking_squares [ PieceType :: Bishop ] = bishop_attacks ( their_king, self . occupancies ( ) ) ;
511- self . state . checking_squares [ PieceType :: Rook ] = rook_attacks ( their_king, self . occupancies ( ) ) ;
512- self . state . checking_squares [ PieceType :: Queen ] =
513- self . checking_squares ( PieceType :: Bishop ) | self . checking_squares ( PieceType :: Rook ) ;
514508 }
515509
516510 pub fn update_hash_keys ( & mut self ) {
0 commit comments