-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunStatistic.py
128 lines (78 loc) · 2.3 KB
/
runStatistic.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import numpy as np;
import matplotlib.pyplot as plt;
from init.rents import rents, colors;
from random import randrange;
from init.costs import COSTS;
rolls = 250
trials = 10
def iterateNTurns(n):
history = []
doubles = 0
temp = COSTS.copy()
total = np.asanyarray(temp.reshape(-1))
propertyIndices = np.nonzero(np.array(rents))
position = 0
for i in range(n):
numA = randrange(5)
numB = randrange(5)
diceSum = 2 + numA + numB
position = (position + diceSum) % 40
if numA == numB:
doubles += 1
else:
doubles = 0
if doubles >= 3:
position = 30
doubles = 0
if(position == 20):
position = 30
total[position] += rents[position]
history.append(total.tolist())
matrix = np.matrix(history)
transpose = np.transpose(matrix)
filteredProperties = np.asarray(transpose)[propertyIndices]
return np.matrix(filteredProperties)
def mergeProfit(results):
results = np.asarray(results)
brown = sum(results[:2])
skyblue = sum(results[2:5])
pink = sum(results[5:8])
orange = sum(results[8:11])
red = sum(results[11:14])
yellow = sum(results[14:17])
green = sum(results[17:20])
blue = sum(results[20:22])
summary = [
brown,
skyblue,
pink,
orange,
red,
yellow,
green,
blue
]
return np.matrix(summary)
def plotResults(results):
results = np.asarray(results)
turns = np.arange(1,rolls + 1)
index = 0
for res in results:
plt.plot(turns,res, color = colors[index])
index += 1
plt.xlabel('Dice rolls')
plt.ylabel('Expected profit')
plt.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
plt.title("Mean profit observed after simulating " + str(trials) + " trials of " + str(rolls) + " dice rolls")
plt.show()
#print(turns)
def makeMean(rollsPerTrial,trials):
result = iterateNTurns(rollsPerTrial)
for i in range(trials - 1):
amount = iterateNTurns(rollsPerTrial)
result = result + amount
mean = (result / trials)
return mean
results = makeMean(rolls,trials)
results = mergeProfit(results)
plotResults(results)