Esempio n. 1
0
    def test_is_position_blocked_range(self):
        obstacles.random.randint = lambda a, b: 40
        obstacles.get_obstacles()

        self.assertEqual(obstacles.is_position_blocked(43, 43), True)
        self.assertEqual(obstacles.is_position_blocked(41, 42), True)
        self.assertEqual(obstacles.is_position_blocked(50, 50), False)
        self.assertEqual(obstacles.is_position_blocked(56, 56), False)
Esempio n. 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 obstacles.is_position_blocked(new_x, new_y):
        return 'obstacle'
    elif obstacles.is_path_blocked(position_x, position_y, new_x, new_y):
        return 'obstacle'
    elif is_position_allowed(new_x, new_y):
        position_x = new_x
        position_y = new_y
        return True
    return False
 def test_is_position_blocked(self):
     """tests that the is_postion_blocked function returns True if there is an obstacle in the postion"""
     obstacles.random.randint = lambda a, b: 1
     obstacles.get_obstacles()
     result = obstacles.is_position_blocked(1, 1)
     obstacles.ob_be_gone()
     self.assertEqual(result, True)
Esempio n. 4
0
def is_path_allowed(new_x, new_y):
    if obstacles.is_path_blocked(position_x, position_y, new_x, new_y):
        return True
    elif obstacles.is_position_blocked(new_x, new_y):
        return True
    else:
        return False
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 silent == True:
    #    return track_position(move_y, move_x, name, silent)

    elif move[0] == "sprint":
        #num = int(move[1])
        #while num > 0:
        #print(f" > {name} moved forward by {num} steps.")
        #num-= 1
        return track_position(move_y, move_x, name, silent)

    else:
        #print(f" > {name} moved {move[0].lower()} by {move[1]} steps.")
        return track_position(move_y, move_x, name, silent)
Esempio n. 6
0
    def test_ob_blocked_4(self):

        obs.obstacles = [(60,40)]
        
        result = obs.is_position_blocked((40),(40))
        self.assertFalse(result)
Esempio n. 7
0
    def test_ob_blocked_3(self):

        obs.obstacles = [(40,90)]
        
        result = obs.is_position_blocked((40),(90))
        self.assertTrue(result)
Esempio n. 8
0
    def test_is_position_blocked(self):
        obstacles.random.randint = lambda a, b: 40
        obstacles.get_obstacles()

        self.assertEqual(obstacles.is_position_blocked(40, 40), True)
        self.assertEqual(obstacles.is_position_blocked(39, 39), False)
Esempio n. 9
0
 def test_obstacles(self):
     obstacles.list_co = [(4, 5)]
     self.assertTrue(obstacles.is_position_blocked(8, 6), True)
Esempio n. 10
0
 def test_obstacles_true(self):
     obstacles.list_co = [(12, 16)]
     self.assertTrue(obstacles.is_position_blocked(13, 17), True)
Esempio n. 11
0
 def test_obstacles_fail_position(self):
     obstacles.list_co = [(4, 5)]
     self.assertFalse(obstacles.is_position_blocked(34, 12), True)
 def test_is_position_blocked(self):
     obstacles.list_of_obstacles = [(1, 1)]
     self.assertEqual(obstacles.is_position_blocked(9, 2), False)
     self.assertEqual(obstacles.is_position_blocked(1, 1), True)
Esempio n. 13
0
 def test_position_blocked(self):
     self.assertFalse(obstacles.is_position_blocked(22, 45), False)
Esempio n. 14
0
 def test_is_position_blocked(self):
     self.assertEqual(obstacles.is_position_blocked(0, 0), False)