-
Notifications
You must be signed in to change notification settings - Fork 0
/
floosball_methods.py
190 lines (174 loc) · 7.48 KB
/
floosball_methods.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from random import randint
import json
import math
import floosball_team as FloosTeam
import floosball_player as FloosPlayer
import floosball_game as FloosGame
import floosball_player as FloosPlayer
def calculateProbability(rating1, rating2):
return round(1.0 * 1.0 / (1 + 1.0 * math.pow(10, 1.0 * (rating1 - rating2) / 400)), 2)
def checkIfClinched(team1Wins, team2Wins, numOfGamesRemaining):
if team2Wins + numOfGamesRemaining < team1Wins:
return True
else:
return False
def checkIfEliminated(team1Wins, team2Wins, numOfGamesRemaining):
if team1Wins + numOfGamesRemaining < team2Wins:
return True
else:
return False
def getConfig():
fileObjext = open("config.json", "r")
jsonContent = fileObjext.read()
config = json.loads(jsonContent)
fileObjext.close()
return config
def saveConfig(value, key1, key2):
fileObjext = open("config.json", "r")
jsonContent = fileObjext.read()
config = json.loads(jsonContent)
fileObjext.close()
if key2 is None:
config[key1] = value
else:
config[key1][key2] = value
fileObjext = open("config.json", "w+")
fileObjext.write(json.dumps(config, indent=4))
fileObjext.close()
def _prepare_for_serialization(obj):
serialized_dict = dict()
if isinstance(obj, dict):
for k, v in obj.items():
if v is not None:
if isinstance(v, list):
tempDict = {}
y = 0
for item in v:
y += 1
tempDict[y] = _prepare_for_serialization(item)
serialized_dict[k] = tempDict
elif isinstance(v, dict):
tempDict = {}
for a, b in v.items():
if isinstance(b, dict):
tempDict2 = {}
for c, d in b.items():
if isinstance(d, dict):
tempDict3 = {}
for e, f in d.items():
if isinstance(f, list):
x = 0
for item in f:
x += 1
tempDict3[x] = _prepare_for_serialization(item)
elif isinstance(d, FloosPlayer.Player):
tempDict3[e] = f.name
elif isinstance(b, FloosTeam.Team):
tempDict3[e] = f.name
else:
tempDict3[e] = f.name if isinstance(f, FloosPlayer.Position) else f
tempDict2[c] = tempDict3
if isinstance(d, list):
z = 0
for item in d:
z += 1
tempDict2[z] = _prepare_for_serialization(item)
elif isinstance(d, FloosPlayer.Player):
tempDict2[c] = d.name
elif isinstance(d, FloosTeam.Team):
tempDict2[c] = d.name
elif isinstance(v, FloosPlayer.PlayerTier):
tempDict2[c] = v.name
elif isinstance(d, FloosPlayer.PlayerAttributes):
tempDict2[c] = _prepare_for_serialization(d)
else:
tempDict2[c] = d.name if isinstance(d, FloosPlayer.Position) else d
tempDict[a] = tempDict2
elif isinstance(b, list):
y = 0
for item in b:
y += 1
tempDict[y] = _prepare_for_serialization(item)
elif isinstance(b, FloosPlayer.Player):
tempDict[a] = b.name
elif isinstance(b, FloosTeam.Team):
tempDict[a] = b.name
elif isinstance(v, FloosPlayer.PlayerTier):
tempDict[a] = v.name
elif isinstance(b, FloosPlayer.PlayerAttributes):
tempDict[a] = _prepare_for_serialization(b)
else:
tempDict[a] = b.name if isinstance(b, FloosPlayer.Position) else b
serialized_dict[k] = tempDict
else:
if isinstance(v, FloosPlayer.Position):
serialized_dict[k] = v.name
elif isinstance(v, FloosPlayer.PlayerTier):
serialized_dict[k] = v.name
elif isinstance(v, FloosGame.PlayType):
serialized_dict[k] = v.name
elif isinstance(v, FloosTeam.Team):
serialized_dict[k] = v.name
elif isinstance(v, FloosPlayer.PlayerAttributes):
serialized_dict[k] = _prepare_for_serialization(v)
else:
serialized_dict[k] = v
elif isinstance(obj, list):
tempDict = {}
y = 0
for item in obj:
y += 1
tempDict[y] = _prepare_for_serialization(item)
serialized_dict[y] = tempDict
else:
for k, v in obj.__dict__.items():
if isinstance(v, list):
tempDict = {}
y = 0
for item in v:
y += 1
tempDict[y] = _prepare_for_serialization(item)
serialized_dict[k] = tempDict
elif isinstance(v, dict):
tempDict = {}
for a, b in v.items():
if isinstance(b, FloosPlayer.Player):
tempDict[a] = _prepare_for_serialization(b)
else:
tempDict[a] = b.name if isinstance(b, FloosPlayer.Position) else b
serialized_dict[k] = tempDict
else:
if isinstance(v, FloosPlayer.Position):
serialized_dict[k] = v.name
elif isinstance(v, FloosPlayer.PlayerTier):
serialized_dict[k] = v.name
elif isinstance(v, FloosGame.PlayType):
serialized_dict[k] = v.name
elif isinstance(v, FloosTeam.Team):
serialized_dict[k] = v.name
elif isinstance(v, FloosPlayer.PlayerAttributes):
serialized_dict[k] = _prepare_for_serialization(v)
else:
serialized_dict[k] = v
return serialized_dict
def getStat(min, max, weight):
x = randint(min,max)
if weight == 1:
if x >= 95:
return randint(95, 100)
elif x < 95 and x >= 75:
return randint(85, 94)
elif x < 75 and x >= 25:
return randint(75, 84)
else:
return randint(60, 74)
else:
return x
def getPower(x, y):
z = 1
while z < y:
if (x**z) >= y:
return z
else:
z += 1
return 0