Farama-Foundation / MicroRTS-Py

A simple and highly efficient RTS-game-inspired environment for reinforcement learning (formerly Gym-MicroRTS)
MIT License
234 stars 45 forks source link

Pcg V1.01 #78

Open xluox opened 2 years ago

xluox commented 2 years ago
vwxyzjn commented 2 years ago

Could you add some brief documentation in the README.md that explains how to run these?

vwxyzjn commented 2 years ago

Hey Yifu sorry for the delay.

I suggest do not modify the vec_env.py and instead use the following paradigm instead:

# pre-generate maps to a directory 
python pcg.py --width 16 --height 16 --num-maps 200 --output-dir pcg_maps
# run the training script with the pre-generated maps
python ppo_gridnet.py --track --maps-dir pcg_maps

In the ppo_gridnet.py, you can basically include all the map names in a maps variable, say, pcg_maps and then we can directly pass to the env creation API

    envs = MicroRTSGridModeVecEnv(
        num_selfplay_envs=args.num_selfplay_envs,
        num_bot_envs=args.num_bot_envs,
        partial_obs=args.partial_obs,
        max_steps=2000,
        render_theme=2,
        ai2s=[microrts_ai.coacAI for _ in range(args.num_bot_envs - 6)]
        + [microrts_ai.randomBiasedAI for _ in range(min(args.num_bot_envs, 2))]
        + [microrts_ai.lightRushAI for _ in range(min(args.num_bot_envs, 2))]
        + [microrts_ai.workerRushAI for _ in range(min(args.num_bot_envs, 2))],
        map_paths=[args.train_maps[0]],
        reward_weight=np.array([10.0, 1.0, 1.0, 0.2, 1.0, 4.0]),
        cycle_maps=pcg_maps,
    )
vwxyzjn commented 2 years ago

Thanks Yifu! Have you successfully run training with this?

xluox commented 2 years ago

Thanks Yifu! Have you successfully run training with this?

Yes

vwxyzjn commented 2 years ago

Everything looks good, except one last thing. Would you mind adding a section in the README.md file in the roof folder of this project to explain how to run things? Once you add that I think we are ready to merge.

Something like below (note that #76 is merged so you need to specify the evaluation maps now) Basically, we want to provide instructions so that people can run it with copy-and-paste commands.

Training with Procedural Content Generation

You can train the agent with procedurally generated maps now thanks to @xluox! Try running:

poetry run python pcg/pcg.py -xxxxx xxx
poetry run python ppo_gridnet.py \
    --train-maps maps/16x16/basesWorkers16x16B.xml maps/16x16/basesWorkers16x16C.xml maps/16x16/basesWorkers16x16D.xml maps/16x16/basesWorkers16x16E.xml maps/16x16/basesWorkers16x16F.xml \
    --eval-maps maps/16x16/basesWorkers16x16B.xml maps/16x16/basesWorkers16x16C.xml maps/16x16/basesWorkers16x16D.xml maps/16x16/basesWorkers16x16E.xml maps/16x16/basesWorkers16x16F.xml