Finds if square on the board is occupied by a ``Piece``
        belonging to the opponent.

        :type: square: Location
        :type: position: Board
        :rtype: bool
963396
def contains_opposite_color_piece(self, square, position):
        
        return not position.is_square_empty(square) and \
            position.piece_at_square(square).color != self.color
1173102
def remove_piece_at(self, square: Square) -> Optional[Piece]:
        
        color = bool(self.occupied_co[WHITE] & BB_SQUARES[square])
        piece_type = self._remove_piece_at(square)
        return Piece(piece_type, color) if piece_type else None
782815
def moves_in_direction(self, direction, position):
        
        current_square = self.location

        while True:
            try:
                current_square = direction(current_square)
            except IndexError:
                return

            if self.contains_opposite_color_piece(current_square, position):
                yield self.create_move(current_square, notation_const.CAPTURE)

            if not position.is_square_empty(current_square):
                return

            yield self.create_move(current_square, notation_const.MOVEMENT)
724061
def tictactoe(w, i, player, opponent, grid=None):
    ""
    grid = grid or empty_grid
    while True:
        w.render_to_terminal(w.array_from_text(view(grid)))
        if is_won(grid):
            print(whose_move(grid), "wins.")
            break
        if not successors(grid):
            print("A draw.")
            break
        grid = player(w, i, grid)
        player, opponent = opponent, player
580210
def weighted_choice(self, board: Union[chess.Board, int], *, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
        
        total_weights = sum(entry.weight for entry in self.find_all(board, exclude_moves=exclude_moves))
        if not total_weights:
            raise IndexError()

        choice = random.randint(0, total_weights - 1)

        current_sum = 0
        for entry in self.find_all(board, exclude_moves=exclude_moves):
            current_sum += entry.weight
            if current_sum > choice:
                return entry

        assert False
1197319
def in_pathing_grid(self, pos: Union[Point2, Point3, Unit]) -> bool:
        
        assert isinstance(pos, (Point2, Point3, Unit))
        pos = pos.position.to2.rounded
        return self._game_info.pathing_grid[pos] == 0
1168348
def place_piece_at_square(self, piece, location):
        
        self.position[location.rank][location.file] = piece
        piece.location = location
348068
def is_checkmate(position, input_color):
    
    return position.no_moves(input_color) and \
        position.get_king(input_color).in_check(position)
645540
def disambiguate_pawns(possibilities)
      self.move.piece.match(/p/i) && !self.move.capture ?
        possibilities.reject {|p| self.board.position_for(p).match(/2|7/) } :
        possibilities
    end
1126268
def get_squares(self, player=None):
        """"""
        if player:
            return [k for k, v in enumerate(self.squares) if v == player]
        else:
            return self.squares
804416
def is_zeroing(self, move: Move) -> bool:
        """"""
        return bool(BB_SQUARES[move.from_square] & self.pawns or BB_SQUARES[move.to_square] & self.occupied_co[not self.turn])
258056
def controls(self, move):
    ''''''
    to_move = self.board.turn
    analysis_board = chess.Board(self.board.fen())
    analysis_board.push(move)
    squares = 0
    for square in chess.SQUARES:
      if move.to_square in analysis_board.attackers(to_move, square):
        squares |= chess.BB_SQUARES[square]
    return SquareSet(squares)
146278
def is_capture(self, move: Move) -> bool:
        """"""
        return bool(BB_SQUARES[move.to_square] & self.occupied_co[not self.turn]) or self.is_en_passant(move)
589050
def piece_map(self) -> Dict[Square, Piece]:
        
        result = {}
        for square in scan_reversed(self.occupied):
            result[square] = typing.cast(Piece, self.piece_at(square))
        return result
326800
def _is_surrounded(self, b):
        

        a = self
        if a.is_empty:
            return True

        if a.is_top and b.is_top:
            return True

        elif a.is_top:
            return False

        elif b.is_top:
            return True

        if b._surrounds_member(a.lower_bound) and b._surrounds_member(a.upper_bound):
            if ((b.lower_bound == a.lower_bound and b.upper_bound == a.upper_bound)
                or not a._surrounds_member(b.lower_bound) or not a._surrounds_member(b.upper_bound)):
                return True
        return False
913528
def contains(self, x, y):
        
        left, bottom, right, top = self.aarect().lbrt()
        return (left <= x <= right) and (bottom <= y <= top)
334242
def in_check_as_result(self, pos, move):
        
        test = cp(pos)
        test.update(move)
        test_king = test.get_king(move.color)

        return self.loc_adjacent_to_opponent_king(test_king.location, test)