Exemplo n.º 1
0
    def can_move_vertically_or_horizontally(self, source, destination):
        horizontal = x.index(source[0]) == x.index(
            destination[0]) and y.index(source[1]) != y.index(destination[1])
        vertical = x.index(source[0]) != x.index(destination[0]) and y.index(
            source[1]) == y.index(destination[1])

        return horizontal or vertical
Exemplo n.º 2
0
    def can_move(self, source, destination):
        x_distance = abs(x.index(source[0]) - x.index(destination[0]))
        y_distance = abs(y.index(source[1]) - y.index(destination[1]))

        return x_distance in [0, 1] and y_distance in [
            0, 1
        ] and x_distance + y_distance != 0
Exemplo n.º 3
0
    def can_move(self, _from, to):
        self.moved = True
        x_distance = abs(x.index(_from[0]) - x.index(to[0]))
        y_distance = abs(y.index(_from[1]) - y.index(to[1]))

        return bool(x_distance in [0, 1] and y_distance in [0, 1]
                    and x_distance + y_distance != 0)
Exemplo n.º 4
0
    def can_move(self, _from, to):
        self.moved = True
        x_distance = abs(x.index(_from[0]) - x.index(to[0]))
        y_distance = abs(y.index(_from[1]) - y.index(to[1]))

        return x_distance in [1, 2] and y_distance in [
            1, 2
        ] and x_distance != y_distance
Exemplo n.º 5
0
    def can_move(self, _from, to):
        self.moved = True
        if (self.color == 'white' and x.index(_from[0]) == x.index(to[0])
                and y.index(to[1]) - y.index(_from[1]) == 1):
            return True

        return (self.color == 'black' and x.index(_from[0]) == x.index(to[0])
                and y.index(to[1]) - y.index(_from[1]) == -1)
Exemplo n.º 6
0
    def can_move(self, _from, to):
        self.moved = True
        horizontal = x.index(_from[0]) == x.index(
            to[0]) and y.index(_from[1]) != y.index(to[1])
        vertical = x.index(_from[0]) != x.index(to[0]) and y.index(
            _from[1]) == y.index(to[1])

        return bool(horizontal or vertical)
Exemplo n.º 7
0
    def can_move(self, source, destination):
        if self.color == 'white' and x.index(source[0]) == x.index(destination[0]):
            ordinary_move = y.index(destination[1]) - y.index(source[1]) == 1
            two_square_move = not self.moved and y.index(destination[1]) - y.index(source[1]) == 2
            return ordinary_move or two_square_move

        if self.color == 'black' and x.index(source[0]) == x.index(destination[0]):
            ordinary_move = y.index(destination[1]) - y.index(source[1]) == -1
            two_square_move = not self.moved and y.index(destination[1]) - y.index(source[1]) == -2
            return ordinary_move or two_square_move
        return False
Exemplo n.º 8
0
    def can_move(self, source, destination):
        if self.color == 'white' and x.index(source[0]) == x.index(
                destination[0]):
            ordinary_move = y.index(destination[1]) - y.index(source[1]) == 1
            two_square_move = not self.moved and y.index(
                destination[1]) - y.index(source[1]) == 2
            return ordinary_move or two_square_move

        if self.color == 'black' and x.index(source[0]) == x.index(
                destination[0]):
            ordinary_move = y.index(destination[1]) - y.index(source[1]) == -1
            two_square_move = not self.moved and y.index(
                destination[1]) - y.index(source[1]) == -2
            return ordinary_move or two_square_move
        return False
Exemplo n.º 9
0
    def can_move(self, _from, to):
        self.moved = True
        # move as a Rook {{
        horizontal = x.index(_from[0]) == x.index(
            to[0]) and y.index(_from[1]) != y.index(to[1])
        vertical = x.index(_from[0]) != x.index(to[0]) and y.index(
            _from[1]) == y.index(to[1])

        if horizontal or vertical:
            return True
        # }}

        # move as a Bishop {{
        return abs(x.index(_from[0]) -
                   x.index(to[0])) == abs(y.index(to[1]) - y.index(_from[1]))
Exemplo n.º 10
0
 def can_move_diagonally(self, source, destination):
     return abs(x.index(source[0]) - x.index(destination[0])) == abs(
         y.index(destination[1]) - y.index(source[1]))
Exemplo n.º 11
0
 def __is_valid_pawn_move(self, _from, to):
     if not self.squares[_from].moved:
         return (x.index(_from[0]) == x.index(to[0]) and
                 abs(y.index(to[1]) - y.index(_from[1])) == 2)
     return False
Exemplo n.º 12
0
 def can_move(self, _from, to):
     self.moved = True
     return abs(x.index(_from[0]) -
                x.index(to[0])) == abs(y.index(to[1]) - y.index(_from[1]))
Exemplo n.º 13
0
 def __is_valid_pawn_move(self, _from, to):
     if not self.squares[_from].moved:
         return (x.index(_from[0]) == x.index(to[0])
                 and abs(y.index(to[1]) - y.index(_from[1])) == 2)
     return False
Exemplo n.º 14
0
    def can_move(self, source, destination):
        x_distance = abs(x.index(source[0]) - x.index(destination[0]))
        y_distance = abs(y.index(source[1]) - y.index(destination[1]))

        return x_distance in [1, 2] and y_distance in [1, 2] and x_distance != y_distance
Exemplo n.º 15
0
    def can_move_vertically_or_horizontally(self, source, destination):
        horizontal = x.index(source[0]) == x.index(destination[0]) and y.index(source[1]) != y.index(destination[1])
        vertical = x.index(source[0]) != x.index(destination[0]) and y.index(source[1]) == y.index(destination[1])

        return horizontal or vertical
Exemplo n.º 16
0
 def can_move_diagonally(self, source, destination):
     return abs(x.index(source[0]) - x.index(destination[0])) == abs(y.index(destination[1]) - y.index(source[1]))