This commit is contained in:
Auric Vente
2024-07-18 21:08:11 -06:00
parent fa1f5301ae
commit c95dab8e57
9 changed files with 120 additions and 48 deletions

View File

@@ -1,4 +1,6 @@
from __future__ import annotations
import random
from typing import ClassVar, Any
from .config import Config
@@ -76,7 +78,7 @@ class Ants:
ant.color = Utils.random_color()
Ants.ants.append(ant)
Storage.save_ants(Ants.ants)
Ants.save()
Utils.print(f"Ant hatched: {ant.name}")
@staticmethod
@@ -85,4 +87,17 @@ class Ants:
@staticmethod
def get_names() -> list[str]:
return [ant.name for ant in Ants.ants]
return [ant.name for ant in Ants.ants]
@staticmethod
def save() -> None:
Storage.save_ants(Ants.ants)
@staticmethod
def get_lazy() -> Ant:
return min(Ants.ants, key=lambda ant: ant.updated)
@staticmethod
def get_other(ant: Ant) -> Ant:
ants = [a for a in Ants.ants if a.name != ant.name]
return random.choice(ants)