Beispiel #1
0
def move_to_door_e(y_door, robot_name):
    x_pos, y_pos = robot.world.get_position()

    if y_pos < y_door:
        # move up
        flag, output = robot.do_left_turn(robot_name)
        print(output)
        steps = y_door - y_pos + 2
        flag, output = robot.do_forward(robot_name, steps)
        print(output)

        print(robot.world.show_position(robot_name))
        flag, output = robot.do_right_turn(robot_name)
        print(output)

    elif y_pos > y_door:
        # move down
        flag, output = robot.do_right_turn(robot_name)

        print(output)
        steps = y_pos - y_door
        flag, output = robot.do_forward(robot_name, steps)
        print(output)

        print(robot.world.show_position(robot_name))
        flag, output = robot.do_left_turn(robot_name)

        print(output)

    elif y_pos == y_door:
        if robot.obstacles.is_position_blocked(x_pos + 1, y_pos+1) is False:
            # move right 1 unit.
            flag, output = robot.do_right_turn(robot_name)

            print(output)
            flag, output = robot.do_forward(robot_name, 1)
            print(output)
            print(robot.world.show_position(robot_name))

            flag, output = robot.do_left_turn(robot_name)

            print(output)

        elif robot.obstacles.is_position_blocked(x_pos - 1, y_pos + 1) is False:
            # move left
            flag, output = robot.do_left_turn(robot_name)

            print(output)
            flag, output = robot.do_forward(robot_name, 1)
            print(output)
            print(robot.world.show_position(robot_name))

            flag, output = robot.do_right_turn(robot_name)
            print(output)

    return True
Beispiel #2
0
def move_to_door_s(x_door, robot_name):
    x_pos, y_pos = robot.world.get_position()

    if x_pos < x_door:
        # move right ++
        flag, output = robot.do_left_turn(robot_name)
        print(output)
        steps = x_door - x_pos + 2
        flag, output = robot.do_forward(robot_name, steps)
        print(output)
        print(robot.world.show_position(robot_name))
        flag, output = robot.do_right_turn(robot_name)
        print(output)

    elif x_pos > x_door:
        # move left --
        flag, output = robot.do_right_turn(robot_name)

        print(output)
        steps = x_pos - x_door + 2
        flag, output = robot.do_forward(robot_name, steps)
        print(output)
        print(robot.world.show_position(robot_name))
        flag, output = robot.do_left_turn(robot_name)
        print(output)

    elif x_pos == x_door:
        if robot.obstacles.is_position_blocked(x_pos + 1, y_pos+1) is False:
            # move right 1 unit.
            flag, output = robot.do_right_turn(robot_name)

            print(output)
            flag, output = robot.do_forward(robot_name, 1)
            print(output)
            print(robot.world.show_position(robot_name))

            flag, output = robot.do_left_turn(robot_name)

            print(output)

        elif robot.obstacles.is_position_blocked(x_pos - 1, y_pos + 1) is False:
            # move left
            flag, output = robot.do_left_turn(robot_name)

            print(output)
            flag, output = robot.do_forward(robot_name, 1)
            print(output)
            print(robot.world.show_position(robot_name))

            flag, output = robot.do_right_turn(robot_name)
            print(output)

    return True
Beispiel #3
0
 def test_do_sprint_one(self):
     robot.position_x = 0
     robot.position_y = 0
     robot_name = "KYLE"
     steps = 1
     output = do_forward(robot_name, 1)
     self.assertEqual(do_sprint(robot_name, steps), output)
Beispiel #4
0
def move_to_wall_w(w_wall_x, w_wall_y, robot_name):
    x_pos, y_pos = robot.world.get_position()
    #print(f"init pos: {x_pos}, {y_pos}")
    steps = x_pos - w_wall_x - 1
    flag, output = robot.do_forward(robot_name, steps)
    print(output)
    print(robot.world.show_position(robot_name))
Beispiel #5
0
 def test_do_forward(self):
     with captured_io(StringIO("forward 5\n")):
         self.assertEqual(robot.do_forward("HAL", 5),
                          (True, " > HAL moved forward by 5 steps."))
Beispiel #6
0
 def test_dont_do_forward(self):
     robot.position_x = 0
     robot.position_y = 0
     output2 = True, 'BRUCE: Sorry, I cannot go outside my safe zone.'
     self.assertEqual(do_forward("BRUCE", 240), output2)
Beispiel #7
0
 def test_do_forward(self):
     output1 = True, ' > BRUCE moved forward by 1 steps.'
     self.assertEqual(do_forward("BRUCE", 1), output1)