コード例 #1
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
コード例 #2
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)
コード例 #3
0
ファイル: world.py プロジェクト: nogumbi/Toy-Robot
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
コード例 #4
0
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)
コード例 #5
0
def update_position(robot_name, 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
    also calls is_path_blocked with an obstacles flag to check the obstacles
    """

    global position_x, position_y, obstacles_flag
    obstacles_flag = False
    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 obs.is_path_blocked(position_x, position_y, new_x, new_y):
        obstacles_flag = True
        return False
    elif is_position_allowed(new_x, new_y):
        position_x = new_x
        position_y = new_y
        return True
    else:
        return False
コード例 #6
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, current_direction_index, directions, obstacles_ls
    #obstacles_ls = obstacles.get_obstacles()
    #print (f"world position{obstacles_ls}")
    # obstacles.set_obstacles(obstacles_ls)
    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_ls = obstacles.get_obstacles()

    if is_position_allowed(new_x, new_y) and (obstacles.is_path_blocked(
            position_x, position_y, new_x, new_y) == False):
        position_x = new_x
        position_y = new_y
        return True
    elif is_position_allowed(
            new_x, new_y) == False and (obstacles.is_path_blocked(
                position_x, position_y, new_x, new_y) == False):
        return "boundary"
    elif (obstacles.is_path_blocked(position_x, position_y, new_x,
                                    new_y) == True):
        return "found"
コード例 #7
0
 def test_is_path_blocked(self):
     obstacles.set_obstacles([(5,0),(10,15)])
     self.assertEqual(obstacles.is_path_blocked(5,5,5,-2),True)
コード例 #8
0
 def test_not_path_is_block_2(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(7, 0, 7, 20), False)
コード例 #9
0
 def test_path_is_blocked_2(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(-1, 12, 10, 12), True)
コード例 #10
0
 def test_not_path_is_block_1(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(-1, 7, 10, 1), False)
コード例 #11
0
 def test_path_is_blocked_1(self):
     obstacles.random_position = [(1, 11)]
     self.assertEqual(obstacles.is_path_blocked(2, 0, 2, 17), True)
コード例 #12
0
    def test_ob_blocked_1(self):

        obs.obstacles = [(60,40),(-100,5)]
        
        result = obs.is_path_blocked((0),(40),(70),(40))
        self.assertTrue(result)
コード例 #13
0
    def test_is_path_blocked(self):
        obstacles.random.randint = lambda a, b: 40
        obstacles.get_obstacles()

        self.assertEqual(obstacles.is_path_blocked(40, 20, 40, 70), True)
コード例 #14
0
ファイル: test_obstacles.py プロジェクト: tinoking63/Projects
 def test_path_blocked_fail(self):
     obstacles.list_co = [(12, 70)]
     self.assertFalse(obstacles.is_path_blocked(12, 17, 56, 67), True)
コード例 #15
0
ファイル: test_obstacles.py プロジェクト: tinoking63/Projects
 def test_path_blocked(self):
     obstacles.list_co = [(12, 16)]
     self.assertTrue(obstacles.is_path_blocked(12, 17, 56, 67), True)
コード例 #16
0
ファイル: test_obstacles.py プロジェクト: tinoking63/Projects
 def test_obstacles_fail(self):
     obstacles.list_co = [(4, 5)]
     self.assertFalse(obstacles.is_path_blocked(12, 65, 56, 67), False)
コード例 #17
0
 def test_is_path_blocked(self):
     with patch('sys.stdout', new=StringIO()) as simulate_output:
         obstacles.random.randint = lambda x, y: 0
         robot.robot_start()
     self.assertEqual(obstacles.is_path_blocked(0, 0, 0, 20), False)
コード例 #18
0
ファイル: test_obstacles.py プロジェクト: ginax17/toy-robot-4
 def test_path_blocked(self):
     self.assertFalse(obstacles.is_path_blocked(-2, 10, 34, 19), False)
コード例 #19
0
 def test_is_path_blocked(self):
     obstacles.list_of_obstacles = [(1, 1)]
     self.assertEqual(obstacles.is_path_blocked(0, 2, 8, 2), False)
     self.assertEqual(obstacles.is_path_blocked(0, 1, 4, 1), True)
コード例 #20
0
    def test_ob_blocked_2(self):

        obs.obstacles = [(-60,180)]
        
        result = obs.is_path_blocked((0),(40),(-20),(40))
        self.assertFalse(result)
コード例 #21
0
ファイル: test_obstacles.py プロジェクト: nogumbi/Toy-Robot
 def test_is_path_blocked(self):
     self.assertEqual(obstacles.is_path_blocked(0, 0, 0, 0), False)