Exemplo n.º 1
0
    def get_theoretical_ep_right(self, x):
        """Checks if a player could have an ep-move in theory from
        looking just at the piece positions.

        :param file:
            The file to check as a letter between `"a"` and `"h"`.

        :return:
            A boolean indicating whether the player could theoretically
            have that en-passant move.

        """
        if x < 0 or x > 7:
            raise ValueError(x)

        '''
        3 states of en-passant
        p.  pP  ..
        ..  ..  .p
        .P  ..  ..
        '''

        # Check there is a pawn on the right rank for e.p.
        y = 3 if self.fen._to_move == WHITE else 4
        x88 = X88.from_x_and_y(x, y) 

        piece = self._pieces[x88]
        if not piece:
            return False

        # If the square is not an opposite colored pawn then its not possible.
        ocolor = Piece.opposite_color(self.fen._to_move)
        if not Piece.is_klass_and_color(piece, PAWN, ocolor):
            return False

        # If the square below the pawn is not empty then it not possible.
        y = 2 if self.turn == WHITE else 5
        x88 = X88.from_x_and_y(x, y) 
        if self[x88]:
            return False

        # If there is not pawn of opposite color on a neighboring file then its not possible.
        xs = [_x for _x in range(8) if _x>=0 and  _x<8 and abs(x-_x) == 1]
        for _x in xs:
            x88 = X88.from_x_and_y(_x, y) 
            piece = self._pieces[x88] 
            if Piece.is_klass_color(piece, PAWN, Piece.opposite_color(self.fen._to_move)):
                return True
        # Else its just not possible.
        return False