Пример #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
Пример #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
Пример #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)
Пример #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
Пример #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)
Пример #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)
Пример #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
Пример #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
Пример #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]))
Пример #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]))
Пример #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
Пример #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]))
Пример #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
Пример #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
Пример #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
Пример #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]))