def io_test(): io = IO() io.go_forward() io.read_sensors() io.go_left() io.read_sensors() io.go_forward() io.read_sensors() io.go_back() io.read_sensors() io.go_forward() io.read_sensors() io.go_right()
def Main(): map_var = Map(Ghost_mapping_type.none) io = IO() logic = Logic(map_var) button = Button() saver = Map_saver(map_var, button) saver.wait_for_load() print("READY") motors = { Moves.fwd: lambda: io.go_forward(), Moves.left: lambda: io.go_left(), Moves.right: lambda: io.go_right(), Moves.back: lambda: io.go_back() } mapping = { Moves.fwd: lambda: map_var.go_forward(), Moves.left: lambda: map_var.go_left(), Moves.right: lambda: map_var.go_right(), Moves.back: lambda: map_var.go_back() } motors[Moves.fwd]() mapping[Moves.fwd]() while (True): clr_sensor = io.directions_free() us_sensor = io.ghost_distance() map_var.write_sensor_values(clr_sensor, us_sensor) debug_print(map_var) move = logic.get_next_move() debug_print(map_var) switch[move]() if button.any(): saver.wait_for_load() ok = motors[move]() if (ok is False): io.after_crash() map_var.rotation += int(move) continue elif (ok is None): saver.wait_for_load() continue mapping[move]() saver.save_map()