Beispiel #1
0
    def _can_move_diagonally_to(self, to: Point) -> bool:
        if self._check_illegal_move(to):
            return False

        me_x = self._pos.x
        me_y = self._pos.y

        x_direction = 1 if to.x > me_x else -1
        y_direction = 1 if to.y > me_y else -1

        # Move one space away as starting square
        row = me_x + x_direction
        col = me_y + y_direction

        # Keep advancing along empty spaces until end is hit
        while not to.equals(row, col):
            if self._board[row, col] is not None:
                return False
            row += x_direction
            col += y_direction

        return True
Beispiel #2
0
def test_equals_xy():
    p = Point(1, 4)
    assert p.equals(1, 4)
    assert not p.equals(2, 3)