コード例 #1
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)
コード例 #2
0
def robot_start():
    """This is the entry point for starting my robot"""

    global position_x, position_y, current_direction_index, history
    obstacles.list_of_obstacles.clear()

    robot_name = get_robot_name()
    obstacles.create_obstacles()
    obstacles.get_obstacles()
    output(robot_name, "Hello kiddo!")

    if len((obstacles.list_of_obstacles)) != 0 and len(
            sys.argv) > 1 and sys.argv[1] != 'turtle':
        world.show_obstacles()
    if len(sys.argv) == 1:
        world.show_obstacles()

    if len(sys.argv) > 1 and sys.argv[1] == 'turtle':
        world.draw_obstacles()

    world.position_x = 0
    world.position_y = 0
    world.current_direction_index = 0
    history = []

    command = get_command(robot_name)
    while handle_command(robot_name, command):
        command = get_command(robot_name)

    output(robot_name, "Shutting down..")
    obstacles.list_of_obstacles.clear()
コード例 #3
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)
コード例 #4
0
    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""") 
コード例 #5
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()
        #obstacles.ob_be_gone()
        self.assertEqual(
            fake_out.getvalue(), """There are some obstacles:
- At position 1,1 (to 5,5)
- At position 1,1 (to 5,5)\n""")
コード例 #6
0
def show_obstacles():
    """
    prints out the obstacles on the turtle screen
    """

    obs.get_obstacles()
    for ob in obs.obstacles:
        t.goto(ob)
        t.pd()
        t.goto(ob[0], ob[1])
        t.goto(ob[0] + 4, ob[1])
        t.goto(ob[0] + 4, ob[1] + 4)
        t.goto(ob[0], ob[1] + 4)
        t.goto(ob[0], ob[1])
        t.pu()

    t.home()
    t.lt(90)
コード例 #7
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
コード例 #8
0
ファイル: world.py プロジェクト: tinoking63/Projects
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()
    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()
コード例 #9
0
def create_obstacles():
    """Creates the obstacles in the turtle enviroment"""
    ob = obstacles.get_obstacles()
    orb = turtle.Turtle()
    orb.speed(50)
    for i in ob:
        val_x = i[0]
        val_y = i[1]
        orb.penup()
        orb.setposition(val_x, val_y)
        orb.pendown()
        orb.begin_fill()
        for r in range(4):
            orb.color("olive")
            orb.forward(5)
            orb.left(90)
        orb.end_fill()

    orb.hideturtle()
コード例 #10
0
def robot_start():
    """This is the entry point for starting my robot"""

    global history

    block = obstacles.get_obstacles()
    robot_name = get_robot_name()
    output(robot_name, "Hello kiddo!")
    if len(block) > 0:
        world.print_obstacles(block)

    history = []

    command = get_command(robot_name)
    while handle_command(robot_name, command):
        command = get_command(robot_name)

    history.clear()
    world.reset_position()
    output(robot_name, "Shutting down..")
コード例 #11
0
 def test_obstacle_list(self):
     """tests that the get_obstacles function returns a list of tupels"""
     obstacles.random.randint = lambda a, b: 1
     result = obstacles.get_obstacles()
     self.assertEqual(result, [(1, 1)])
コード例 #12
0
robot.penup()
robot.setposition(-101, -201)
robot.pendown()
robot.pencolor('red')
robot.pensize(3)
for i in range(4):
    if i % 2 == 0:
        robot.forward(201)
        robot.left(90)
    else:
        robot.forward(401)
        robot.left(90)
robot.penup()

#Create obstacles
obstacles_list = obstacles.get_obstacles()
for square in obstacles_list:
    robot.pencolor("red")
    robot.begin_fill()
    robot.goto(square[0], square[1])
    robot.pendown()
    robot.goto(square[0] + 4, square[1])
    robot.goto(square[0] + 4, square[1] + 4)
    robot.goto(square[0], square[1] + 4)
    robot.goto(square[0], square[1])
    robot.penup()
robot.hideturtle()

move_robot = turtle.Turtle()
move_robot.setheading(90)
コード例 #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
    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)
コード例 #15
0
 def test_get_obstacles(self):
     with patch('sys.stdout', new=StringIO()) as simulate_output:
         obstacles.num_obstacles = 0
         robot.robot_start()
     self.assertEqual(len(obstacles.get_obstacles()), 0)