-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
239 lines (194 loc) · 7.44 KB
/
stats.py
File metadata and controls
239 lines (194 loc) · 7.44 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# STATS FILE: GAME OF WHY
# CHARIS CAT 2024
class Stats:
def __init__(self):
# Population
self.cellCounter = 0
# death statistics
self.cellDeathCounter = {}
self.cellDeathEscapeCounter = 0
self.cellDisintegrationCounter = 0
self.cellDisintegrationDeathCounter = 0
# birth statistics
self.cellBabyCounter = {}
self.cellBabysFailedCounter = {}
self.cellForcedSpawnCounter = 0
self.cellFailedForcedSpawnCounter = 0
# state statistits
self.cellStateChange = {}
self.cellStateChangeThisTurn = {}
self.cellStateStable = 0
self.cellStateStableThisTurn = 0
# Movement statistics
self.cellMovedCounter = 0
self.cellPushedCounter = 0
self.cellStoppedCounter = 0
# TURN STATISTICS
self.cellBabysThisTurn = {}
self.cellBabysFailedThisTurn = {}
self.cellDeathsThisTurn = {}
self.cellDeathEscapesThisTurn = 0
self.cellMovedThisTurn = 0
self.cellPushedThisTurn = 0
self.cellStoppedThisTurn = 0
self.cellAliveCount = 0
self.cellYouthCount = 0
self.cellElderlyCount = 0
self.cellAdultCount = 0
def beginTurn(self):
self.cellBabysThisTurn = {}
self.cellDeathsThisTurn = {}
self.cellDeathEscapesThisTurn = 0
self.cellBabysFailedThisTurn = {}
self.cellPushedThisTurn = 0
self.cellMovedThisTurn = 0
self.cellStoppedThisTurn = 0
self.cellAliveCount = 0
self.cellYouthCount = 0
self.cellElderlyCount = 0
self.cellAdultCount = 0
self.cellStateStableThisTurn = 0
self.cellStateChangeThisTurn = {}
def endTurn(self):
print(f"Turn Summary: There are currently {self.cellAliveCount} living cells. There were {self.getBabysCountThisTurn()} babies born, {self.getDeathsThisTurn()} cells died, and {self.cellDeathEscapesThisTurn} cells evaded death! ")
print(self)
def endRun(self):
print(self)
def __str__(self):
return f"""
Total Cell Count: {self.cellCounter+1}
# Death Statistics
Total Cell Death: {self.getTotalDeath()}
By Reason:
{"\n".join([f"{x}: {self.cellDeathCounter[x]}" for x in self.cellDeathCounter])}
Total Disintegrations: {self.cellDisintegrationCounter} (fully reclaimed: {self.cellDisintegrationDeathCounter})
Total Cell Escapes: {self.cellDeathEscapeCounter}
# Birth Statistics
Total Cell Babies: {self.cellBabyCounter}
By Reason:
{"\n".join([f"{x}: {self.cellBabyCounter[x]}" for x in self.cellBabyCounter])}
Total Cell Skipped Babies: {self.cellBabysFailedCounter}
By Reason:
{"\n".join([f"{x}: {self.cellBabysFailedCounter[x]}" for x in self.cellBabysFailedCounter])}
Total Cell Babies Spawned: {self.cellForcedSpawnCounter}
Total Cell Babies Unspawned: {self.cellFailedForcedSpawnCounter}
# Movement Statistics
Total Cell Movements: {self.cellMovedCounter}
Total Cell Pushed: {self.cellPushedCounter}
Total Cell Stopped: {self.cellStoppedCounter}
# State Statistics
Total State Changes: {self.getCellStateChangeTotal()}
By State:
{"\n".join([f"{x}: {self.cellStateChange[x]}" for x in self.cellStateChange])}
Total Stable Turns: {self.cellStateStable}
# Turn Statistics
Cell Babies: {self.cellBabysThisTurn}
Cell Skipped Babies: {self.cellBabysFailedThisTurn}
Cell Death: {self.getDeathsThisTurn()}
{"\n".join([f"{x}: {self.cellDeathsThisTurn[x]}" for x in self.cellDeathsThisTurn])}
Cell Escapes: {self.cellDeathEscapesThisTurn}
Cell Movements: {self.cellMovedThisTurn}
Cell Pushes: {self.cellPushedThisTurn}
Cell Stops: {self.cellStoppedThisTurn}
Cells Alive: {self.cellAliveCount} (Youth: {self.cellYouthCount}, Adults: {self.cellAdultCount}, Elderly: {self.cellElderlyCount})
Switched Cell States: {self.getCellStateChangesThisTurn()}
By State:
{"\n".join([f"{x}: {self.cellStateChangeThisTurn[x]}" for x in self.cellStateChangeThisTurn])}
Stable Cell States: {self.cellStateStableThisTurn}
"""
def addCellBaby(self, reason):
if reason in self.cellBabyCounter:
self.cellBabyCounter[reason] += 1
else:
self.cellBabyCounter[reason] = 1
if reason in self.cellBabysThisTurn:
self.cellBabysThisTurn[reason] += 1
else:
self.cellBabysThisTurn[reason] = 1
def addCellBabyFailed(self, reason):
if reason in self.cellBabysFailedCounter:
self.cellBabysFailedCounter[reason] += 1
else:
self.cellBabysFailedCounter[reason] = 1
if reason in self.cellBabysFailedThisTurn:
self.cellBabysFailedThisTurn[reason] += 1
else:
self.cellBabysFailedThisTurn[reason] = 1
def addCellDeath(self, reason):
if reason in self.cellDeathCounter:
self.cellDeathCounter[reason] += 1
else:
self.cellDeathCounter[reason] = 1
if reason in self.cellDeathsThisTurn:
self.cellDeathsThisTurn[reason] += 1
else:
self.cellDeathsThisTurn[reason] = 1
def addCellDeathEscape(self):
self.cellDeathEscapeCounter += 1
self.cellDeathEscapesThisTurn += 1
def addCellPush(self):
self.cellPushedCounter += 1
self.cellPushedThisTurn += 1
def addCellAlive(self):
self.cellAliveCount += 1
def addCellMove(self):
self.cellMovedCounter += 1
self.cellMovedThisTurn += 1
def addCellStop(self):
self.cellStoppedCounter += 1
self.cellStoppedThisTurn += 1
def addCellForcedSpawn(self):
self.cellForcedSpawnCounter += 1
def addCellFailedForcedSpawn(self):
self.cellFailedForcedSpawnCounter += 1
def addCellYouth(self):
self.cellYouthCount += 1
def addCellElderly(self):
self.cellElderlyCount += 1
def addCellAdult(self):
self.cellAdultCount += 1
def addCellDisintegration(self):
self.cellDisintegrationCounter += 1
def addCellDisintegrationDeath(self):
self.cellDisintegrationDeathCounter += 1
def getTotalDeath(self):
total = 0
for reason in self.cellDeathCounter:
total += self.cellDeathCounter[reason]
return total
def getDeathsThisTurn(self):
sum = 0
for reason in self.cellDeathsThisTurn:
sum += self.cellDeathsThisTurn[reason]
return sum
def getCellStateChangeTotal(self):
total = 0
for reason in self.cellStateChange:
total += self.cellStateChange[reason]
return total
def getCellStateChangesThisTurn(self):
sum = 0
for reason in self.cellStateChangeThisTurn:
sum += self.cellStateChangeThisTurn[reason]
return sum
def getBabysCountThisTurn(self):
sum = 0
for kind in self.cellBabysThisTurn:
sum += self.cellBabysThisTurn[kind]
return sum
def getCellNextID(self):
ret = self.cellCounter
self.cellCounter += 1
return ret
def addCellStateStable(self):
self.cellStateStable += 1
self.cellStateStableThisTurn += 1
def addCellStateChange(self, newState):
if newState in self.cellStateChange:
self.cellStateChange[newState] += 1
else:
self.cellStateChange[newState] = 1
if newState in self.cellStateChangeThisTurn:
self.cellStateChangeThisTurn[newState] += 1
else:
self.cellStateChangeThisTurn[newState] = 1