-
Notifications
You must be signed in to change notification settings - Fork 5
/
simulation.py
65 lines (51 loc) · 1.58 KB
/
simulation.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
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 11 22:54:02 2018
@author: tonyd
"""
#run simulation
import numpy as np
from scipy.stats import norm
from BBallSim import BBallSim
matches = [('warriors', 'clippers')]
#ends at 3 jan
f = open('jan6.txt', 'w')
for i in matches:
win = 0
team1 = i[0]
team2 = i[1]
amount = 1500
score1 =0
score2 =0
percT1 =0
percT2=0
sim = BBallSim(team1, team2)
for i in range(amount):
# sim = BBallSim(team1, team2)
sim.gameLoop()
if sim.score[0] >sim.score[1]:
percT1 += 1
if sim.score[1] >sim.score[0]:
percT2 +=1
score1 += sim.score[0]
score2 += sim.score[1]
sim.resetScore()
f.write(f"{team1} {score1/amount} {100*(percT1/amount)}% \n")
f.write(f"{team2} {score2/amount} {100*(percT2/amount)}% \n")
#print(f"{score1/amount +score2/amount }")
f.write(f"({round(score1/amount -score2/amount) })\n")
p = (percT1/amount) * (1-(percT1/amount))/np.sqrt(amount)
inter = norm.ppf(.95)*p
Lconf = (percT1/amount) - inter
Rconf = (percT1/amount) + inter
f.write(f"90% confidence interval : {Lconf*100} and {Rconf*100} \n")
p2 = (percT2/amount) * (1-(percT2/amount))/np.sqrt(amount)
inter2 = norm.ppf(.95)*p2
Lconf2 = (percT2/amount) - inter2
Rconf2 = (percT2/amount) + inter2
f.write(f"90% confidence interval : {Lconf2*100} and {Rconf2*100} \n")
f.write('..\n')
f.write('..\n')
print('....working')
print('...done')
f.close()