Skip to content

Commit 7dc6788

Browse files
Update cellular_automata/wa_tor.py
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
1 parent adcc4ff commit 7dc6788

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

cellular_automata/wa_tor.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ def balance_predators_and_prey(self) -> None:
208208

209209
prey_count, predator_count = len(prey), len(predators)
210210

211-
if prey_count > predator_count:
212-
for entity in prey[:DELETE_UNBALANCED_ENTITIES]:
213-
# Purge the first n entities of the prey
214-
self.planet[entity.coords[0]][entity.coords[1]] = None
215-
else:
216-
for entity in predators[:DELETE_UNBALANCED_ENTITIES]:
217-
# Purge the first n entities of the predators
218-
self.planet[entity.coords[0]][entity.coords[1]] = None
211+
entities_to_purge = (
212+
prey[:DELETE_UNBALANCED_ENTITIES]
213+
if prey_count > predator_count
214+
else predators[:DELETE_UNBALANCED_ENTITIES]
215+
)
216+
for entity in entities_to_purge:
217+
self.planet[entity.coords[0]][entity.coords[1]] = None
219218

220219
def get_surrounding_prey(self, entity: Entity) -> list[Entity]:
221220
"""

0 commit comments

Comments
 (0)