# Commits

committed 42a6c17

clean trinity result probs evaluation.

• Participants

# File trinity.py

`+#!/usr/bin/env python3`
`+`
`+"""calculate trinity die rolling chances brute force."""`
`+`
`+from random import choice`
`+from collections import Counter, defaultdict`
`+from scipy import std, mean`
`+`
`+numtests = 100`
`+rollsperplayer = 30`
`+succ = set([7,8,9,10])`
`+botch = set([1])`
`+`
`+die = list(range(1,11))`
`+`
`+def roll(ndice):`
`+    return [choice(die) for i in range(ndice)]`
`+`
`+def check(r):`
`+    """return nsucc, nbotch"""`
`+    return len([i for i in r if i in succ]), len([i for i in r if i in botch])`
`+`
`+def success(succ, botch, min_succ):`
`+    return succ - botch >= min_succ`
`+`
`+def botched(succ, botch):`
`+    return succ - botch < 0`
`+`
`+def normedsucc(res, min_succ=1):`
`+    total = sum(res.values())`
`+    succ = sum([value for key, value in res.items() if success(*key, min_succ=min_succ)])`
`+    bot = sum([value for key, value in res.items() if botched(*key)])`
`+    return succ/total, bot/total`
`+    `
`+`
`+def test(ndice, numtests, min_succ=1):`
`+    res = Counter()`
`+    for i in range(numtests):`
`+        res[check(roll(ndice))] += 1`
`+    return normedsucc(res, min_succ)`
`+`
`+def display(r):`
`+    return "success: " + str(100*r[0]) + "%, botch: " + str(100*r[1]) + "%"`
`+`
`+if __name__ == "__main__":`
`+    results = defaultdict(list)`
`+    # gather mutltiple times`
`+    for num in range(numtests//rollsperplayer):`
`+        for min_succ in range(1,5):`
`+            for i in range(1,11):`
`+                results[(min_succ, i)].append(test(i, rollsperplayer, min_succ))`
`+    keys = list(results.keys())`
`+    keys.sort()`
`+    minsu = 1`
`+    print("=== min successes:", minsu, "===")`
`+    for i in keys:`
`+        if i[0] != minsu:`
`+            minsu = i[0]`
`+            print("\n=== min successes:", minsu, "===")`
`+        succ = [succ for succ,bot in results[i]]`
`+        botch = [bot for succ,bot in results[i]]`
`+        print("dice:", i[1], "succ:", mean(succ), "±", std(succ), end=" ")`
`+        print("botch:", mean(botch), "±", std(botch))`
`+`