-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_many_instances.py
56 lines (44 loc) · 1.67 KB
/
test_many_instances.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
#!/usr/bin/env python3
from __future__ import print_function
from multiprocessing import Process
from random import choice
import vizdoom as vzd
from argparse import ArgumentParser
DEFAULT_CONFIG = "../../scenarios/basic.cfg"
def play(process, instances, config_file):
games = []
for i in range(instances):
game = vzd.DoomGame()
game.load_config(config_file)
game.set_mode(vzd.Mode.PLAYER)
game.set_window_visible(False)
game.init()
games.append(game)
print("Process {}: Game {} started...".format(process, i))
actions = [[True, False, False],
[False, True, False],
[False, False, True]]
for g in games:
g.new_episode()
while not g.is_episode_finished():
g.make_action(choice(actions))
for g in games:
g.close()
if __name__ == '__main__':
parser = ArgumentParser("Test for N instances in P processes.")
parser.add_argument(dest="config",
default=DEFAULT_CONFIG,
nargs="?",
help="Path to the configuration file of the scenario."
" Please see "
"../../scenarios/*cfg for more scenarios.")
parser.add_argument("-i", "--instances", default=128, help="Number of instances per process.")
parser.add_argument("-p", "--processes", default=4, help="Number of processes.")
args = parser.parse_args()
processes= []
for p in range(args.processes):
p = Process(target=play, args=[p, args.instances, args.config])
p.start()
processes.append(p)
for p in processes:
p.join()