Mods
This commit is contained in:
parent
ba736560da
commit
0ad23a8d7d
10
README.md
10
README.md
|
@ -32,21 +32,15 @@ You watch who gets the most triumphs or the most hits.
|
||||||
|
|
||||||
The ant with the highest score is shown in the footer.
|
The ant with the highest score is shown in the footer.
|
||||||
|
|
||||||
Clicking the footer scrolls to the bottom.
|
|
||||||
|
|
||||||
There is a filter to filter updates.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Just open it, hatch some ants, and place it somewhere in your monitor.
|
Just open it, hatch some ants, and place it somewhere in your monitor.
|
||||||
|
|
||||||
## Algorithm
|
## Algorithm
|
||||||
|
|
||||||
A random ant from ants that haven't had an update in at least 10 minutes is picked.
|
A random ant is picked based on weights (oldest update date weighs more).
|
||||||
|
|
||||||
Or any ant is picked if none meet that requirement.
|
Then a random number between 1 and 10 is picked.
|
||||||
|
|
||||||
Then a number between 1 and 10 is randomly picked.
|
|
||||||
|
|
||||||
For each number an action happens to produce an update.
|
For each number an action happens to produce an update.
|
||||||
|
|
||||||
|
|
|
@ -147,25 +147,21 @@ class Ants:
|
||||||
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
|
ages = [(now - ant.updated) for ant in Ants.ants]
|
||||||
# Filter ants where updated is older than 10 minutes
|
|
||||||
ants = [a for a in Ants.ants if (now - a.updated) >= mins]
|
|
||||||
|
|
||||||
if not len(ants):
|
# Normalize ages to create weights
|
||||||
ants = Ants.ants
|
total_age = sum(ages)
|
||||||
|
|
||||||
ants = [a for a in ants if a not in ignore]
|
if total_age == 0:
|
||||||
return random.choice(ants)
|
weights = [1] * len(Ants.ants) # If all ages are zero, use equal weights
|
||||||
|
else:
|
||||||
|
weights = [
|
||||||
|
int(age / total_age * 1000) for age in ages
|
||||||
|
] # Scale and cast to int
|
||||||
|
|
||||||
|
# Perform weighted random selection
|
||||||
|
return random.choices(Ants.ants, weights=weights, k=1)[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_current() -> Ant | None:
|
def get_current() -> Ant | None:
|
||||||
|
|
Loading…
Reference in New Issue