interrupts zijn eleganter nu ReeEEeeeEEE :lenny: hoe lang kan ik dit eigenlijk maken ik heb dat nog nooit echt geprobeerd
This commit is contained in:
parent
a910266296
commit
ff7cc3f8f3
1 changed files with 11 additions and 7 deletions
|
@ -228,11 +228,15 @@ class Model:
|
||||||
This functions runs the simulation
|
This functions runs the simulation
|
||||||
"""
|
"""
|
||||||
print(chr(27) + "[2J")
|
print(chr(27) + "[2J")
|
||||||
|
# actual simulation runs inside try except to catch keyboard interrupts and always print stats
|
||||||
|
try:
|
||||||
for t in range(self.time_steps):
|
for t in range(self.time_steps):
|
||||||
print("Simulating timestep: {}".format(t), end='\r')
|
print("Simulating timestep: {}".format(t), end='\r')
|
||||||
self.step()
|
self.step()
|
||||||
if self.graphical:
|
if self.graphical:
|
||||||
self.draw(t)
|
self.draw(t)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
print(chr(27) + "[2J")
|
print(chr(27) + "[2J")
|
||||||
self.compile_stats()
|
self.compile_stats()
|
||||||
|
@ -315,6 +319,6 @@ class Human(IntEnum):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
model = Model(graphical=False)
|
model = Model(graphical=True)
|
||||||
model.run()
|
model.run()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue