-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_bots.py
44 lines (36 loc) · 1.25 KB
/
create_bots.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
import argparse
from multiprocessing.dummy import Pool as ThreadPool
from subprocess import Popen, PIPE
def parse_arguments():
parser = argparse.ArgumentParser(description="Create multiple bots for testing.")
parser.add_argument(
"--num-warriors", "-w", help="Number of warrior bots.", type=int, required=True
)
parser.add_argument(
"--num-psychics", "-p", help="Number of warrior bots.", type=int, required=True
)
args = parser.parse_args()
return args
def function_create_cmds(cmd):
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
(output, error) = proc.communicate()
return output
if __name__ == "__main__":
args = parse_arguments()
num_warriors = args.num_warriors
num_psychics = args.num_psychics
num_bots = num_warriors + num_psychics
cmds_warrior = [
f"python test_client.py --unit-class warrior --nickname warrior-{k}"
for k in range(num_warriors)
]
cmds_psychic = [
f"python test_client.py --unit-class psychic --nickname psychic-{k}"
for k in range(num_psychics)
]
cmds = cmds_warrior + cmds_psychic
pool = ThreadPool(num_bots)
results = pool.map(function_create_cmds, cmds)
pool.close()
pool.join()
print(results)