def path_finder_s(robot_name): global final_dest x_pos, y_pos = robot.world.get_position() edge_found = False flag, output = robot.do_right_turn(robot_name) print(output) flag, output = robot.do_right_turn(robot_name) print(output) while edge_found is False: s_wall_x, s_wall_y = find_s_wall() #print(f"{s_wall_x}, {s_wall_y} somewhere 1") move_to_wall_s(s_wall_x, s_wall_y, robot_name) # print("somewhere 2") x_pos, y_pos = robot.world.get_position() if y_pos == -200: print("edgeZN") edge_found = True break # print(f"s_wall_y{s_wall_y}") door_x = find_door_s(s_wall_y) move_to_door_s(door_x, robot_name) # x_pos, y_pos = robot.world.get_position() #print("end of loop") return "Zen"
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_e(robot_name): global final_dest x_pos, y_pos = robot.world.get_position() flag, output = robot.do_right_turn(robot_name) print(output) edge_found = False while edge_found is False: e_wall_x, e_wall_y = find_e_wall() # print("somewhere 1") move_to_wall_e(e_wall_x, e_wall_y, robot_name) # print("somewhere 2") x_pos, y_pos = robot.world.get_position() if x_pos == 100: # print("edgeZN") edge_found = True break print(f"e-wally{e_wall_x}") door_y = find_door_e(e_wall_x) print(f"{door_y}door-x") # print("somewhere 3") move_to_door_e(door_y, robot_name) # print("somewhere 4") x_pos, y_pos = robot.world.get_position() #print("end of loop") return "Zen"
def test_do_right_turn(self): with captured_io(StringIO("right\n")): self.assertEqual(robot.do_right_turn("HAL"), (True, " > HAL turned right."))
def test_do_right_turn(self): output5 = True, ' > RON turned right.' self.assertEqual(do_right_turn("RON"), output5)