def legal_drop_squares_mask(self): king_bb = self.kings & self.occupied_co[self.turn] if not king_bb: return ~self.occupied king_square = chess.msb(king_bb) king_attackers = self.attackers_mask(not self.turn, king_square) if not king_attackers: return ~self.occupied elif chess.popcount(king_attackers) == 1: return chess.BB_BETWEEN[king_square][chess.msb(king_attackers)] & ~self.occupied else: return chess.BB_VOID
def legal_drop_squares_mask(self): king = self.king(self.turn) if king is None: return ~self.occupied king_attackers = self.attackers_mask(not self.turn, king) if not king_attackers: return ~self.occupied elif chess.popcount(king_attackers) == 1: return chess.BB_BETWEEN[king][chess.msb(king_attackers)] & ~self.occupied else: return chess.BB_VOID
def legal_drop_squares_mask(self) -> chess.Bitboard: king = self.king(self.turn) if king is None: return ~self.occupied king_attackers = self.attackers_mask(not self.turn, king) if not king_attackers: return ~self.occupied elif chess.popcount(king_attackers) == 1: return chess.between(king, chess.msb(king_attackers)) & ~self.occupied else: return chess.BB_EMPTY
def is_variant_end(self) -> bool: if not self.kings & chess.BB_RANK_8: return False black_kings = self.kings & self.occupied_co[chess.BLACK] if self.turn == chess.WHITE or black_kings & chess.BB_RANK_8 or not black_kings: return True # White has reached the backrank. The game is over if black can not # also reach the backrank on the next move. Check if there are any # safe squares for the king. black_king = chess.msb(black_kings) targets = chess.BB_KING_ATTACKS[black_king] & chess.BB_RANK_8 & ~self.occupied_co[chess.BLACK] return all(self.attackers_mask(chess.WHITE, target) for target in chess.scan_forward(targets))
def is_variant_end(self): if not self.kings & chess.BB_RANK_8: return False if self.turn == chess.WHITE or self.kings & self.occupied_co[chess.BLACK] & chess.BB_RANK_8: return True black_kings = self.kings & self.occupied_co[chess.BLACK] if not black_kings: return True black_king = chess.msb(black_kings) # White has reached the backrank. The game is over if black can not # also reach the backrank on the next move. Check if there are any # safe squares for the king. targets = chess.BB_KING_ATTACKS[black_king] & chess.BB_RANK_8 return all(self.attackers_mask(chess.WHITE, target) for target in chess.scan_forward(targets))