-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_matches.py
39 lines (32 loc) · 1.14 KB
/
make_matches.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
import argparse
parser = argparse.ArgumentParser(description="Generate set of player pairs")
parser.add_argument("--deterministic", action="store_true", help="Keep the order of games and participants")
parser.add_argument("--type",
action="store",
choices=["pairs", "round-robin"],
default="pairs",
help="Special testing value"
)
parser.add_argument("participants", type=str, nargs="+")
args = parser.parse_args()
if not args.deterministic:
import random
random.shuffle(args.participants)
if args.type == "pairs":
if len(args.participants) % 2 != 0:
print("Even number of participants required.")
exit(2)
matches = [
[args.participants[i], args.participants[i+1]]
for i in range(0, len(args.participants), 2)
]
elif args.type == "round-robin":
matches = []
for i1, p1 in enumerate(args.participants):
for i2, p2 in enumerate(args.participants):
if i1 < i2:
matches.append([p1, p2])
if not args.deterministic:
random.shuffle(matches)
for pair in matches:
print(" ".join(f"{p:>{2+max(len(q) for q in args.participants)}}" for p in pair))