def test_is_path_blocked(self):
     obstacles.random.randint = lambda a, b: 1
     obstacles.get_obstacles()
     result = obstacles.is_path_blocked(1, 0, 1, 5)
     self.assertEqual(result, True)
     result = obstacles.is_path_blocked(10, 10, 10, 20)
     self.assertEqual(result, False)
Exemple #2
0
def update_position(steps):
    """
    Update the current x and y positions given the current direction, and specific nr of steps
    :param steps:
    :return: True if the position was updated, else False
    """

    global position_x, position_y
    new_x = position_x
    new_y = position_y

    if directions[current_direction_index] == 'forward':
        new_y = new_y + steps
    elif directions[current_direction_index] == 'right':
        new_x = new_x + steps
    elif directions[current_direction_index] == 'back':
        new_y = new_y - steps
    elif directions[current_direction_index] == 'left':
        new_x = new_x - steps

    if not is_position_allowed(new_x, new_y):
        return "unsafe"
    elif obstacles.is_path_blocked(position_x, position_y, new_x, new_y):
        return "obstacle"
    else:
        position_x = new_x
        position_y = new_y
        return "safe"
Exemple #3
0
 def test_is_path_blocked(self):
     """tests that the is_path_blocked function returns True if there is an obstacle in the path"""
     obstacles.random.randint = lambda a, b: 1
     obstacles.get_obstacles()
     result = obstacles.is_path_blocked(2, 0, 2, 20)
     obstacles.ob_be_gone()
     self.assertEqual(result, True)
Exemple #4
0
def update_position(steps):
    """
    Update the current x and y positions given the current direction, and specific nr of steps
    :param steps:
    :return: True if the position was updated, else False
    """

    global robo_turtle
    robo_turtle._tracer(False)
    new_x = robo_turtle.xcor()
    new_y = robo_turtle.ycor()
    if robo_turtle.heading() == 90:
        new_y = new_y + steps
    elif robo_turtle.heading() == 0:
        new_x = new_x + steps
    elif robo_turtle.heading() == 270:
        new_y = new_y - steps
    elif robo_turtle.heading() == 180:
        new_x = new_x - steps

    if not is_position_allowed(new_x, new_y):
        return "unsafe"
    elif obstacles.is_path_blocked(robo_turtle.xcor(), robo_turtle.ycor(),
                                   new_x, new_y):
        return "obstacle"
    else:
        robo_turtle.setpos(new_x, new_y)
        robo_turtle._tracer(True)
        return "safe"
def check_position_range(move_y, move_x, move, name, silent):
    """makes sure the robot is within the set range and that it doesnt move over obstacles """
    global x
    global y

    range_x = x + move_x
    range_y = y + move_y
    block = obstacles.is_position_blocked(range_x,range_y)
    blocked = obstacles.is_path_blocked(x,y ,range_x,range_y)

    if range_x > 100 or range_x < -100 or range_y > 200 or range_y < -200 :
        print(f"{name}: Sorry, I cannot go outside my safe zone.")
        move_x = 0
        move_y = 0
        return track_position(move_y, move_x, name, silent)

    elif block == True or blocked == True:
        print("Sorry, there is an obstacle in the way.")
        move_x = 0
        move_y = 0
        return track_position(move_y, move_x, name, silent)

    elif move[0] == "sprint":
        return track_position(move_y, move_x, name, silent)

    else:    
        return track_position(move_y, move_x, name, silent)
 def test_is_path_blocked(self):
     obstacles.set_obstacles([(5, 0), (10, 15)])
     self.assertEqual(obstacles.is_path_blocked(5, 5, 5, -2), True)
Exemple #7
0
    def test_ob_blocked_2(self):

        obs.obstacles = [(-60, 180)]

        result = obs.is_path_blocked((0), (40), (-20), (40))
        self.assertFalse(result)
Exemple #8
0
 def test_is_path_blocked(self):
     obstacles.obstacle_list = [(1, 1)]
     self.assertEqual(obstacles.is_path_blocked(0 , 2, 50, 2), True)
 def test_path_blocked_y(self):
     obstacles.random.randint = lambda a, b: 1
     obslist = obstacles.get_obstacles()
     self.assertTrue(obstacles.is_path_blocked(2, 0, 2, 50))
 def test_path_blocked_x(self):
     obstacles.random.randint = lambda a, b: 1
     self.assertTrue(obstacles.is_path_blocked(0, 2, 50, 2))
 def test_not_path_is_block_2(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(7, 0, 7, 20), False)
 def test_path_is_blocked_2(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(-1, 12, 10, 12), True)
 def test_not_path_is_block_1(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(-1, 7, 10, 1), False)
 def test_path_is_blocked_1(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(2, 0, 2, 17), True)