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
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
def path_finder_w(robot_name): global final_dest x_pos, y_pos = robot.world.get_position() edge_found = False flag, output = robot.do_left_turn(robot_name) print(output) while edge_found is False: w_wall_x, w_wall_y = find_w_wall() # print("somewhere 1") move_to_wall_w(w_wall_x, w_wall_y, robot_name) x_pos, y_pos = robot.world.get_position() if x_pos == -100: # print("edgeZN") edge_found = True break door_y = find_door_w(w_wall_x) move_to_door_w(door_y, robot_name) x_pos, y_pos = robot.world.get_position() #print("end of loop") return "Zen"
def test_do_left_turn(self): with captured_io(StringIO("left\n")): self.assertEqual(robot.do_left_turn("HAL"), (True, " > HAL turned left."))
def test_do_left_turn(self): output5 = True, ' > RON turned left.' self.assertEqual(do_left_turn("RON"), output5)