This commit is contained in:
Auric Vente 2024-07-20 05:41:07 -06:00
parent 915a2dbbd3
commit f46be0a809
2 changed files with 28 additions and 4 deletions

View File

@ -99,7 +99,11 @@ class Ants:
if Ants.empty():
return
ant = Ants.get_random_ant()
ant = Ants.random_ant()
if not ant:
return
Ants.ants.remove(ant)
Ants.save()
@ -120,7 +124,10 @@ class Ants:
Window.confirm("Terminate all ants?", action)
@staticmethod
def get_random_ant() -> Ant:
def random_ant() -> Ant | None:
if Ants.empty():
return None
return random.choice(Ants.ants)
@staticmethod
@ -136,10 +143,19 @@ class Ants:
return len(Ants.ants) == 0
@staticmethod
def get_lazy() -> Ant | None:
def get_next() -> Ant | None:
if Ants.empty():
return None
if len(Ants.ants) == 1:
return Ants.ants[0]
ignore = []
current = Ants.get_current()
if current:
ignore.append(current)
now = Utils.now()
mins = 10 * 60
# Filter ants where updated is older than 10 minutes
@ -148,8 +164,16 @@ class Ants:
if not len(ants):
ants = Ants.ants
ants = [a for a in ants if a not in ignore]
return random.choice(ants)
@staticmethod
def get_current() -> Ant | None:
if Ants.empty():
return None
return max(Ants.ants, key=lambda ant: ant.updated)
@staticmethod
def set_status(ant: Ant, status: str, method: str) -> None:
from .game import Game

View File

@ -161,7 +161,7 @@ class Game:
if Ants.empty():
return
ant = Ants.get_lazy()
ant = Ants.get_next()
if not ant:
return