コード例 #1
0
ファイル: testgridvec.py プロジェクト: Bam4d/gym-microrts
import gym_microrts

from gym_microrts.envs.vec_env import MicroRTSGridModeVecEnv
from gym_microrts import microrts_ai
from gym.envs.registration import register
from gym_microrts import Config
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.distributions.categorical import Categorical

try:
    env = MicroRTSGridModeVecEnv(
        num_envs=1,
        render_theme=2,
        ai2s=[microrts_ai.passiveAI],
        map_path="maps/16x16/basesWorkersTestAttack16x16.xml",
        reward_weight=np.array([10.0, 1.0, 1.0, 0.2, 1.0, 4.0]))
    # env = gym.make('MicrortsDefeatCoacAIShaped-v3').env
    # env = gym.wrappers.RecordEpisodeStatistics(env)
    # env.action_space.seed(0)
    obs = env.reset()
    env.render()
except Exception as e:
    e.printStackTrace()
# print("reward is", env.step([[[ 17,   2 ,  0 ,  3 ,  0 ,  1 ,  2, 0]]])[1])
# env.render()
# print("reward is", env.step([[[ 34  , 4 ,  1   ,2  , 1 ,  2  , 3 ,0]]])[1])
# env.render()

# print("reward is", env.step([[[ 14*16+14  , 1 ,  0   ,0  , 0 ,  0  , 0 ,0]]])[1])
コード例 #2
0
        save_code=True)
    wandb.tensorboard.patch(save=False)
    writer = SummaryWriter(f"/tmp/{experiment_name}")
    CHECKPOINT_FREQUENCY = 50

# TRY NOT TO MODIFY: seeding
device = torch.device(
    'cuda' if torch.cuda.is_available() and args.cuda else 'cpu')
random.seed(args.seed)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.backends.cudnn.deterministic = args.torch_deterministic
envs = MicroRTSGridModeVecEnv(
    num_selfplay_envs=args.num_selfplay_envs,
    num_bot_envs=args.num_bot_envs,
    max_steps=2000,
    render_theme=2,
    ai2s=[microrts_ai.coacAI for _ in range(args.num_bot_envs)],
    map_path="maps/16x16/basesWorkers16x16.xml",
    reward_weight=np.array([10.0, 1.0, 1.0, 0.2, 1.0, 4.0]))
envs = MicroRTSStatsRecorder(envs, args.gamma)
envs = VecMonitor(envs)
if args.capture_video:
    envs = VecVideoRecorder(envs,
                            f'videos/{experiment_name}',
                            record_video_trigger=lambda x: x % 1000000 == 0,
                            video_length=2000)
# if args.prod_mode:
#     envs = VecPyTorch(
#         SubprocVecEnv([make_env(args.gym_id, args.seed+i, i) for i in range(args.num_envs)], "fork"),
#         device
#     )
コード例 #3
0
    "coacAI": microrts_ai.coacAI,
    "naiveMCTSAI": microrts_ai.naiveMCTSAI,
    "mixedBot": microrts_ai.mixedBot,
    "rojo": microrts_ai.rojo,
    "izanagi": microrts_ai.izanagi,
    "tiamat": microrts_ai.tiamat,
    "droplet": microrts_ai.droplet,
    "guidedRojoA3N": microrts_ai.guidedRojoA3N
}
ai_names, ais = list(all_ais.keys()), list(all_ais.values())
ai_match_stats = dict(zip(ai_names, np.zeros((len(ais), 3))))
args.num_envs = len(ais)
envs = MicroRTSGridModeVecEnv(num_bot_envs=len(ais),
                              num_selfplay_envs=0,
                              render_theme=2,
                              ai2s=ais,
                              map_path="maps/16x16/basesWorkers16x16A.xml",
                              reward_weight=np.array(
                                  [10.0, 1.0, 1.0, 0.2, 1.0, 4.0]))
envs = MicroRTSStatsRecorder(envs)
envs = VecMonitor(envs)
if args.capture_video:
    envs = VecVideoRecorder(envs,
                            f'videos/{experiment_name}',
                            record_video_trigger=lambda x: x % 1000000 == 0,
                            video_length=2000)
assert isinstance(
    envs.action_space,
    MultiDiscrete), "only MultiDiscrete action space is supported"