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