From 177416ca96edf1c56e6e6b7c0b33919d61fb1a48 Mon Sep 17 00:00:00 2001 From: adjenk <1632694+adjenk@users.noreply.github.com> Date: Tue, 26 May 2026 18:18:43 +1000 Subject: [PATCH 1/2] Fix Python 3.14 compatibility and simulation bugs --- constants.py | 18 +++++++++--------- epidemiological_host.py | 8 ++++---- universe.py | 8 ++++++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/constants.py b/constants.py index 9ca60ee..80f7c41 100644 --- a/constants.py +++ b/constants.py @@ -4,9 +4,9 @@ class SimColor: -""" -Tuples corresponding to RGB colors -""" + """ + Tuples corresponding to RGB colors + """ LIGHT_GREY = (240, 240, 240) DARK_GREY = (30, 30, 50) BLACK = (0, 0, 0) @@ -17,9 +17,9 @@ class SimColor: class Disease: -""" -Constants for disease -""" + """ + Constants for disease + """ INFECTED = 0 RECOVERED = 1 UNEXPOSED = 2 @@ -34,9 +34,9 @@ class Disease: class Screen: -""" -Constants for Screen -""" + """ + Constants for Screen + """ WIDTH = 680 HEIGHT = 480 FONT_SIZE = 18 diff --git a/epidemiological_host.py b/epidemiological_host.py index c5f3c1b..425dde3 100644 --- a/epidemiological_host.py +++ b/epidemiological_host.py @@ -108,12 +108,12 @@ def detect_contact_with_other_host(self, other, time_step): other.contact_response.new_speed_y = -speed_p * sin(-theta) + other_speed_q * cos(-theta) def transmit_pathogen(self, interlocutor): - if interlocutor.condition is Disease.INFECTED \ - and self.condition is not Disease.RECOVERED: + if interlocutor.condition == Disease.INFECTED \ + and self.condition != Disease.RECOVERED: self.condition = Disease.INFECTED self.color = Disease.COLOR_MAP[self.condition] - if self.condition is Disease.INFECTED \ - and interlocutor.condition is not Disease.RECOVERED: + if self.condition == Disease.INFECTED \ + and interlocutor.condition != Disease.RECOVERED: interlocutor.condition = Disease.INFECTED interlocutor.color = Disease.COLOR_MAP[interlocutor.condition] diff --git a/universe.py b/universe.py index 09a0501..d9aabe3 100644 --- a/universe.py +++ b/universe.py @@ -145,6 +145,9 @@ def run(self): pygame.display.update() while self.is_epidemic_over: + for e in pygame.event.get(): + if e.type == pygame.QUIT: + self.quit() pygame.display.update() def progress_healing(self): @@ -162,7 +165,8 @@ def progress_healing(self): if host.condition is Disease.INFECTED: host.remaining_recovery -= 1 - + if host.remaining_recovery <= 0: + host.condition = Disease.RECOVERED host.color = Disease.COLOR_MAP[host.condition] @staticmethod @@ -192,7 +196,7 @@ def is_epidemic_over(self): Returns true if there are no infected hosts :return: Boolean """ - return self.get_population_count(Disease.INFECTED) is 0 + return self.get_population_count(Disease.INFECTED) == 0 if __name__ == "__main__": From 4d3d15a50a5bf627e599478b460d1b7f4d8df80b Mon Sep 17 00:00:00 2001 From: adjenk <1632694+adjenk@users.noreply.github.com> Date: Tue, 26 May 2026 19:11:22 +1000 Subject: [PATCH 2/2] Revert accidental change to epidemiological_host.py --- epidemiological_host.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/epidemiological_host.py b/epidemiological_host.py index 425dde3..c5f3c1b 100644 --- a/epidemiological_host.py +++ b/epidemiological_host.py @@ -108,12 +108,12 @@ def detect_contact_with_other_host(self, other, time_step): other.contact_response.new_speed_y = -speed_p * sin(-theta) + other_speed_q * cos(-theta) def transmit_pathogen(self, interlocutor): - if interlocutor.condition == Disease.INFECTED \ - and self.condition != Disease.RECOVERED: + if interlocutor.condition is Disease.INFECTED \ + and self.condition is not Disease.RECOVERED: self.condition = Disease.INFECTED self.color = Disease.COLOR_MAP[self.condition] - if self.condition == Disease.INFECTED \ - and interlocutor.condition != Disease.RECOVERED: + if self.condition is Disease.INFECTED \ + and interlocutor.condition is not Disease.RECOVERED: interlocutor.condition = Disease.INFECTED interlocutor.color = Disease.COLOR_MAP[interlocutor.condition]