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.fen.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_and_color( piece, PAWN, Piece.opposite_color(self.fen._to_move)): return True # Else its just not possible. return False
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.fen.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_and_color(piece, PAWN, Piece.opposite_color(self.fen._to_move)): return True # Else its just not possible. return False
def __init__(self, label): if len(label) != 2: raise ValueError(square) try: x = self.files.index(label[0]) y = self.ranks.index(label[1]) except ValueError: raise ValueError(label) self._x88 = X88.from_x_and_y(x, y)
def test_from_x_and_y(self): self.assertEqual(X88.from_x_and_y(0, 0), 0)
def test_from_x_and_y(self): self.assertEqual(X88.from_x_and_y(0,0), 0)