#!/usr/bin/env python3
from random import random, shuffle
from collections import namedtuple, defaultdict
from operator import mul
from itertools import starmap
from math import inf
save_targets = 'serp', 'torb', 'rob', 'kae'
def heal(doc, saved):
r = random()
for name, chance in zip(save_targets, doc.save):
r -= chance
if r <= 0:
saved[name] = True
return name
class Doc:
__slots__ = ('index', 'save')
def __init__(self, save):
self.index = -1
self.save = save
def sim():
players = ['Akai', 'Minato', 'Yuzuki', 'Oozora', 'Ookami', 'Urusha', 'Tsunomaki', 'Calliope', 'Ninomae', 'Gawr', 'Kureiji']
save_score = 1, 0.6, 0.4, 0.2, 0.1
# save_score = 1, 0, 0, 0, 0
heart = Doc((0.35, 0.25, 0.25, 0.15))
bloop = Doc((0.3, 0.3, 0.2, 0.2))
nurse = Doc((0.25, 0.25, 0.25, 0.25))
samples = {}
for kserp in range(11):
kserp_chance = kserp / 10
for ktorb in range(11):
ktorb_chance = ktorb / 10
if kserp_chance + ktorb_chance > 1:continue
for krob in range(11):
krob_chance = krob / 10
sum3 = kserp_chance + ktorb_chance + krob_chance
if sum3 > 1:continue
kkae_chance = 1 - sum3
nk = kserp_chance, ktorb_chance, krob_chance, kkae_chance
nk_blocked = 0
serp_saved = 0
torb_saved = 0
rob_saved = 0
kae_saved = 0
for x in range(1000):
shuffle(players)
heart.index = players.index('Akai')
bloop.index = players.index('Gawr')
nurse.index = players.index('Yuzuki')
saved = defaultdict(bool)
heal(heart, saved)
heal(bloop, saved)
heal(nurse, saved)
nk_choice = random()
nk_name = None
for name, nk_chance in zip(save_targets, nk):
nk_choice -= nk_chance
if nk_choice <= 0:
nk_name = name
break
nk_blocked += saved[nk_name]
if nk_name != 'serp' or saved[nk_name]:
serp_saved += 1
if nk_name != 'torb' or saved[nk_name]:
torb_saved += 1
if nk_name != 'rob' or saved[nk_name]:
rob_saved += 1
if nk_name != 'kae' or saved[nk_name]:
kae_saved += 1
samples[nk] = (nk_blocked, serp_saved, torb_saved, rob_saved, kae_saved)
min_key = None
min_val = None
min_score = inf
for k, v in samples.items():
score = sum(starmap(mul, zip(save_score, v)))
if score < min_score:
min_key = k
min_val = v
min_score = score
print(tuple(map(lambda x:round(x,2), min_key)), min_val, round(min_score))
sim()