Exemplo n.º 1
0
def main(strategy_str: 'str', df: 'object'):

    # Read the level data from server.
    com = Communicator()
    com.ReadServerMessage()

    # Create a plan to solve the level.
    TimeTracker.startTimer("Planning")
    planner = Plan(com.starting_state, com.goal_state, strategy_str)

    # Solve the level (resolve the plan and get a path from initial state to goal state).
    commands = planner.resolve()

    TimeTracker.stopTimer("Planning")

    TimeTracker.printTimes()

    for command in commands:
        print(str(command.jointaction), file=sys.stderr, flush=True)

    # Write results in CSV file if needed
    if df is not None:
        df = df.append(
            {
                'level':
                com.level_name,
                'strategy':
                strategy_str,
                'num_agents':
                len(planner.start_state.agents),
                'num_boxes':
                len(planner.start_state.boxes),
                'num_colors':
                len(set(planner.start_state.colors.values())),
                'solved':
                1,
                'num_steps':
                len(commands),
                'runtime':
                planner.strategy.time_spent(),
                'explored':
                planner.strategy.explored_count(),
                'frontier':
                planner.strategy.frontier_count(),
                'generated':
                planner.strategy.explored_count() +
                planner.strategy.frontier_count(),
                'mem':
                configuration.get_memory_usage()
            },
            ignore_index=True)

    # Send actions to server.
    com.send_commands_to_server(commands)

    # Level completed!
    return df