def test_is_position_blocked(self): obstacles.random.randint = lambda a, b: 1 obstacles.get_obstacles() result = obstacles.is_position_blocked(1, 1) self.assertEqual(result, True) result = obstacles.is_position_blocked(1, 10) self.assertEqual(result, 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)
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 obstacles.obs_true = False if obstacles.is_position_blocked(new_x, new_y) or obstacles.is_path_blocked( new_x, new_y, position_x, position_y): return "blocked" if is_position_allowed(new_x, new_y): position_x = new_x position_y = new_y return True 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 move[0] == "sprint": return track_position(move_y, move_x, name, silent) else: return track_position(move_y, move_x, name, silent)
def test_ob_blocked_4(self): obs.obstacles = [(60, 40)] result = obs.is_position_blocked((40), (40)) self.assertFalse(result)
def test_is_position_blocked(self): obstacles.create_random_obstacles() obstacles.obstacle_list = [(10,10), (100,100)] self.assertEqual(obstacles.is_position_blocked(11,11), True) self.assertEqual(obstacles.is_position_blocked(11,15), False)
def test_position_blocked(self): obstacles.random.randint = lambda a, b: 1 self.assertTrue(obstacles.is_position_blocked(2, 2))