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)
Пример #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)
 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)
Пример #4
0
    def test_obstacle_postions(self):
        """tests that the obstacle_positons function prints out the coordinates of the obstacles"""
        obstacles.ob_be_gone()
        obstacles.random.randint = lambda a, b: 1
        obstacles.get_obstacles()
        with patch('sys.stdout', new=StringIO()) as fake_out:
            obstacles.obstacle_positions()

        self.assertEqual(
            fake_out.getvalue(), """There are some obstacles:
- At position 1,1 (to 5,5)
- At position 1,1 (to 5,5)\n""")
    def test_world_obstacle(self):
        """tests that the robot doesnt move over obstacles"""
        obstacles.random.randint = lambda a, b: 1
        obstacles.get_obstacles()
        #result = obstacles.is_position_blocked(1,1)
        #obstacles.ob_be_gone()
        with patch('sys.stdout', new=StringIO()) as fake_out:
            world.text.world.check_position_range(3, 1, ["forward", "3"],
                                                  "BMO", False)

        self.assertEqual(
            fake_out.getvalue(), """Sorry, there is an obstacle in the way.
 > BMO now at position (0,0).\n""")
def the_matrix(name, start, direction):
    """is responsible for creating a scaled down matrix that represents 
    the maze in the form of 1s for the obstacles and 0s for the path"""
    mazz = obstacles.get_obstacles()
    ob = []
    for i in mazz:
        if (i[0] % 5) == 0 and (i[1] % 5) == 0:
            ob.append((int((i[0] + 100) / 5), (int((i[1] + 200) / 5))))
    ob.sort()
    maz = numpy.array(ob)
    matrix = numpy.zeros((80, 40), dtype=int)
    try:
        matrix[maz[:, 1], maz[:, 0]] = 1
    except:
        pass
    m = []
    for i in range(len(matrix)):
        m.append([])
        for j in range(len(matrix[i])):
            m[-1].append(0)
    i, j = start
    m[i][j] = 1

    end = maze_direction(direction, matrix)
    draw_matrix(name, direction, end, matrix, m, [])
Пример #7
0
def setup_world(robot_name):
    """
    initialise global variables
    """
    global position_x, position_y, current_direction_index, obstacle_list
    print(f"{robot_name}: Loaded {obs_module}.")
    obstacle_list = obstacles.get_obstacles()
    position_x = 0
    position_y = 0
    current_direction_index = 0

    make_obstacles()
Пример #8
0
def text_or_turtle():
    """allows the user to pick between  text or turtle  on the commandline"""
    global env

    if len(sys.argv) > 1 and sys.argv[1] == "turtle":
        env = True
        world.turtle.world.set_turtle_enviroment()
        if len(sys.argv) > 2:
            maze_ob = (f"maze.{sys.argv[2]}")
            obstacles.use_maze(maze_ob)
            # world.turtle.world.create_obstacles()
        else:
            obstacles.get_obstacles()
            # world.turtle.world.create_obstacles()

    elif len(sys.argv) > 1 and sys.argv[1] == "text":
        env = False
        if len(sys.argv) > 2:
            obstacles.use_maze(f"maze.{sys.argv[2]}")
        else:
            obstacles.get_obstacles()

    elif len(sys.argv) == 1:
        env = False
        obstacles.get_obstacles()
Пример #9
0
def setup_world(robot_name):
    """
    initialising the module
    """
    global robo_turtle, obstacle_list
    print(f"{robot_name}: Loaded {obs_module}.")
    obstacle_list = obstacles.get_obstacles()
    robo_turtle = turtle.Turtle()
    screen = turtle.Screen()
    screen.tracer(False)
    screen.setup((max_x - min_x) * 4, (max_y - min_y) * 4)
    screen.setworldcoordinates(min_x, min_y, max_x, max_y)
    robo_turtle.color("red")
    make_obstacles()
    make_border()
    screen.tracer(True)
Пример #10
0
def print_obs():
    '''
    This prints the list of obstacles
    '''

    x = obstacles.get_obstacles()

    if x:
        print("There are some obstacles:")
        for i in x:
            var1 = i[0]
            var2 = i[1]
            print("- At position {},{} (to {},{})".format(
                var1, var2,
                int(var1) + 4,
                int(var2) + 4))
    else:
        return None
Пример #11
0
def create_obs():
    '''
    This displays the obstacles on the turtle screen 
    '''
    my_obs_turt = turtle.Turtle()
    my_obs_turt.hideturtle()
    my_obs_turt.color('red')
    list_of_coords = obstacles.get_obstacles()
    print(list_of_coords)
    my_obs_turt.speed(20)
    my_obs_turt.penup()
    for i in range(len(list_of_coords)):
        my_obs_turt.setposition(list_of_coords[i])
        my_obs_turt.begin_fill()
        for j in range(4):
            my_obs_turt.pendown()
            my_obs_turt.forward(5)
            my_obs_turt.right(90)
        my_obs_turt.end_fill()
        my_obs_turt.penup()
Пример #12
0
 def test_obstacle_list(self):
     """tests that the get_obstacles function returns a list of tupels"""
     obstacles.ob_be_gone()
     obstacles.random.randint = lambda a, b: 1
     result = obstacles.get_obstacles()
     self.assertEqual(result, [(1, 1)])
Пример #13
0
 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))
Пример #14
0
 def test_get_obstacles(self):
     result = obstacles.get_obstacles()
     self.assertEqual(10 >= len(result) >= 0, True)