-
-
Save sma/1d9402290a2b079bcff2d8b568b5be90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def random_name(n1, n2): return f"{pick(n1)} {pick(n2)}" | |
def pick(lst): return sample(lst, 1)[0] | |
def sample(lst, n=None): return random.sample(lst, n or len(lst)) | |
def d(n): return random.randint(1, n) | |
disciplines = ["Wettreiten", "Bogenschießen"] | |
realms = ["R1", "R2"] | |
names = { | |
"R1": ( | |
["Alrik", "Borik"], | |
["Allman", "Borger"], | |
), | |
"R2": ( | |
["Yla", "Zoe"], | |
["Yellow", "Zukzuk"], | |
), | |
} | |
participants = [{"n": random_name(*names[r]), "r": r} | |
for _ in range(d(10)+4) for r in realms] | |
for p in participants: | |
p['d'] = {di: d(6) for di in sample(disciplines, d(len(disciplines)))} | |
def fight(p1, p2, di): | |
qs1 = p1['d'][di] + d(6) | |
qs2 = p2['d'][di] + d(6) | |
return qs1 > qs2 or (qs1 == qs2 and d(2) == 1) | |
for di in disciplines: | |
ps = sample([p for p in participants if di in p['d']]) | |
while len(ps) > 1: | |
ps2 = [] | |
if len(ps) % 1: | |
ps2.append(ps.pop()) | |
for (p1, p2) in zip(ps[::2], ps[1::2]): | |
ps2.append(p1 if fight(p1, p2, di) else p2) | |
ps = ps2 | |
if len(ps) > 0: | |
print(f"Gewinner von {di} ist {ps[0]['n']} aus {ps[0]['r']}") | |
else: | |
print(f"{di} hat keinen Gewinner") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment