Created
January 12, 2017 15:01
-
-
Save Anmint/d2f142240bcfe0405526c217d141267d to your computer and use it in GitHub Desktop.
Simulation of bonus/penalty dice in CoC 7th
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
# -*- coding: utf-8 -*- | |
import numpy as np | |
from numpy.random import * | |
import matplotlib.pyplot as plt | |
from matplotlib.font_manager import FontProperties | |
def main(): | |
LOOP_TIME = 10000 | |
# Roll three dices for bonus and penalty rule in CoC 7th | |
Rhigh1 = randint(0,10,LOOP_TIME) | |
Rhigh2 = randint(0,10,LOOP_TIME) | |
Rlow = randint(0,10,LOOP_TIME) | |
# Calculate dice value with two 10-sided dices | |
R = PadHundred(Rhigh1 * 10 + Rlow) | |
RBns = PadHundred(np.fmin(Rhigh1,Rhigh2) * 10 + Rlow) | |
RPena = PadHundred(np.fmax(Rhigh1,Rhigh2) * 10 + Rlow) | |
# Preparation of plot | |
x = np.arange(1,99,1) | |
y_normal = np.empty(98) | |
y_oldBonus = np.empty(98) | |
y_newBonus = np.empty(98) | |
y_oldPena = np.empty(98) | |
y_newPena = np.empty(98) | |
# Evaluation of dice roll | |
for i in range(1,99): | |
y_normal[i-1] = len(np.where(i >= R)[0]) / LOOP_TIME | |
y_oldBonus[i-1] = len(np.where((i + 10) >= R)[0]) / LOOP_TIME | |
y_newBonus[i-1] = len(np.where(i >= RBns)[0]) / LOOP_TIME | |
y_oldPena[i-1] = len(np.where((i - 10) >= R)[0]) / LOOP_TIME | |
y_newPena[i-1] = len(np.where(i >= RPena)[0]) / LOOP_TIME | |
# Plot | |
plt.plot(x, y_normal, label="Normal dice roll") | |
plt.plot(x, y_oldBonus, label="Skill + 10") | |
plt.plot(x, y_newBonus, label="One bonus dice") | |
plt.plot(x, y_oldPena, label="Skill - 10") | |
plt.plot(x, y_newPena, label="One penalty dice") | |
plt.legend(loc="upper left") | |
plt.xlabel("Skill point", fontsize=16) | |
plt.ylabel("Probability", fontsize=16) | |
plt.show() | |
def PadHundred(Ary): | |
""" | |
Return numpy.array which 0 were converted to 100 | |
""" | |
zeros = np.where(Ary == 0)[0] | |
for i in zeros: | |
Ary[i] = 100 | |
return Ary | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment