forked from SDSMT-SC2AI/ResourceGather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
91 lines (80 loc) · 3.7 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import argparse, json, os, errno
def parse_args():
parser = argparse.ArgumentParser(description="StarCraft II agent A2C TensorFlow implementation")
parser.add_argument("--config",
default="config.json", type=str,
help="Configuration file")
parser.add_argument("--train",
default=True, type=bool,
help="To train or not to train")
parser.add_argument("--render",
default=False, type=bool,
help="Render feature layers with pygame")
parser.add_argument("--episodes",
default=200, type=int,
help="Total number of episodes to run agent with")
parser.add_argument("--game_steps_per_episode",
default=0, type=int,
help="Game steps per episode")
parser.add_argument("--step_mul",
default=1, type=int,
help="Game steps per agent step")
parser.add_argument("--agent",
default="Dummy", type=str,
help="ClassName of agent")
parser.add_argument("--agent_module",
default="agent", type=str,
help="Path to agent module")
parser.add_argument("--agent_race",
default="Z", type=str,
help="Race of agent")
parser.add_argument("--bot_race",
default="R", type=str,
help="Race of opponent bot")
parser.add_argument("--profile",
default=False, type=bool,
help="Whether to turn on code profiling")
parser.add_argument("--trace",
default=False, type=bool,
help="Whether to trace the code execution")
parser.add_argument("--num_envs",
default=4, type=int,
help="How many instances to run in parallel")
parser.add_argument("--save_replay",
default=True, type=bool,
help="Whether to save a replay on completion")
parser.add_argument("--map",
default=None, type=str,
help="Unused! The AGENT should define the map/maps!")
parser.add_argument("--base_output_dir",
default=".out", type=str,
help="Place to put program output")
parser.add_argument("--summary_dir",
default="summary", type=str,
help="Place to put summary relative to base output dir")
parser.add_argument("--checkpoint_dir",
default="checkpoints", type=str,
help="Place to put model checkpoints relative to base output dir")
parser.add_argument("--logging_dir",
default="out", type=str,
help="Place to put logging output relative to base output dir")
parser.add_argument("--test_dir",
default="test", type=str,
help="Place for test output relative to base output dir")
args = parser.parse_args()
try:
config_json = json.loads(args.config)
except json.JSONDecodeError:
print("Couldn't find a valid config file, using default arguments...")
config_json = None
if config_json is not None:
for k, v in config_json:
if vars(args)[k] == parser.get_default(k):
vars(args)[k] = v
return args
def ensure_dir(path):
try:
os.makedirs(path)
except OSError as e:
if e.errno is not errno.EEXIST:
raise