Compare commits

..

2 Commits

Author SHA1 Message Date
Nate Bowman
0d40fe5dc0 Add decay for huntables 2026-11-06 20:13:44 -05:00
Nate Bowman
85e441927b Remove some helpers from test file
No longer need them now that I realized I can just cheat to set up the
world how I want it for the tests
2026-11-06 20:06:05 -05:00
2 changed files with 29 additions and 109 deletions

View File

@@ -186,6 +186,7 @@ class Gather():
def compute_next_gather_rate_decrease(self, task, villagers):
rate = self.gather_rates[task]
decay = self.decay_rates[task]
if task == Tasks.FARM:
available = self.farms[0]
@@ -193,14 +194,12 @@ class Gather():
else:
available = self.gatherable_amounts[task]
try:
next_decrease = available/(villagers*rate)
if rate == 0 or (villagers == 0 and decay == 0):
next_decrease = None
else:
next_decrease = available/(villagers*rate + decay)
# rounding error will give 1 extra second of gathering
next_decrease = math.ceil(next_decrease)
except ZeroDivisionError:
# either villagers or rate was 0, so no next decrease should
# be scheduled
next_decrease = None
return next_decrease
@@ -300,6 +299,11 @@ class Gather():
amount_gathered = count*rate*mult*duration
self.resources[resource] += amount_gathered
for task in self.decay_rates.keys():
self.gatherable_amounts[task] -= self.decay_rates[task]*duration
if self.gatherable_amounts[task] < 0:
self.gatherable_amounts[task] = 0
def __init__(self):
self.resources = [200, 200, 100, 200]
@@ -329,6 +333,12 @@ class Gather():
self.original_gather_rates = copy.deepcopy(self.gather_rates)
self.decay_rates = defaultdict(int, {
Tasks.SHEEP: 0.25,
Tasks.BOAR: 0.4,
Tasks.HUNT: 0.25,
})
self.gathered_resources = {
Tasks.BERRIES: {Resources.FOOD: 1},
Tasks.SHEEP: {Resources.FOOD: 1},

View File

@@ -10,85 +10,6 @@ from aoe.gameplay import *
class TestWorld(unittest.TestCase):
@staticmethod
def get_to_feudal(game):
walking = 35 # to match mill and camp
final_time = 430 # sufficient time to gather boar and age up
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
game.build(0, Buildings.MILL, Tasks.IDLE, Tasks.BOAR)
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.BOAR)
game.increase_age(300)
game.play_until(final_time)
return final_time
@staticmethod
def get_to_castle(game):
walking = 1
current_time = TestWorld.get_to_feudal(game)
wood_gather_per_60 = 23.4
wood_needed = 175 + 150
wood_duration = int(wood_needed/(wood_gather_per_60*2) + 1)*60
boar_amount_no_decay = 340
boar_per_60 = 24.6
boar_duration = int(boar_amount_no_decay/boar_per_60)*60
food_needed = 1000
boars_needed = int(food_needed/boar_amount_no_decay + 1)
# we can use infinite-boars cheat if needed
for i in range(boars_needed):
game.lure_huntable_with_villager(current_time + i*walking,
Tasks.IDLE,
walking)
game.assign_villager(current_time + (i + 1)*walking,
Tasks.BOAR,
Tasks.IDLE)
game.assign_villager(current_time + boars_needed*walking,
Tasks.IDLE,
Tasks.BOAR)
game.assign_villager(current_time, Tasks.IDLE, Tasks.WOOD, 2)
gather_time = max((boar_duration + walking)*boars_needed,
wood_duration)
current_time += gather_time
# just so I know where they all are (i.e., wood)
game.assign_villager(current_time, Tasks.BOAR, Tasks.WOOD)
game.build(current_time, Buildings.MININGCAMP, Tasks.WOOD, Tasks.WOOD)
current_time += 35
game.assign_villager(current_time, Tasks.WOOD, Tasks.GOLD, 3)
gold_per_60 = 22.8
gold_needed = 100
gold_duration = int(gold_needed/(gold_per_60*3) + 1)*60
current_time += gold_duration
game.build(current_time, Buildings.MARKET, Tasks.GOLD, Tasks.GOLD)
game.build(current_time, Buildings.BLACKSMITH, Tasks.GOLD, Tasks.GOLD)
market_build = 60
current_time += market_build
game.increase_age(current_time)
game.assign_villager(current_time, Tasks.GOLD, Tasks.IDLE, 3)
current_time += 160
game.play_until(current_time)
return current_time
@staticmethod
def equal_to_tolerance(v1, v2, atol):
return (abs(v1 - v2) <= atol)
@@ -291,7 +212,7 @@ class TestWorld(unittest.TestCase):
self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world)
def test_gather_boar_limited_no_decay(self):
def test_gather_boar_limited(self):
walking = 20
game = Gameplay()
@@ -300,8 +221,13 @@ class TestWorld(unittest.TestCase):
game.play_until(1000)
boar_total = 340
boar_per_60 = 24.6
boar_decay_per_60 = 0.4*60
boar_gone_time = boar_total/(boar_decay_per_60 + boar_per_60*3)
self.assertResourcesMatch([200 + boar_total, 200, 100, 200], game.world)
boar_eaten = boar_gone_time*boar_per_60*3
self.assertResourcesMatch([200 + boar_eaten, 200, 100, 200], game.world)
def test_age_increase(self):
@@ -311,6 +237,7 @@ class TestWorld(unittest.TestCase):
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
game.build(0, Buildings.MILL, Tasks.IDLE, Tasks.BOAR)
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.BOAR)
game.lure_huntable_with_villager(walking, Tasks.BOAR, walking)
game.increase_age(300)
game.play_until(400)
self.assertEqual(Ages.DARK, game.world.age)
@@ -328,36 +255,19 @@ class TestWorld(unittest.TestCase):
def test_monk_get_relic(self):
game = Gameplay()
current_time = TestWorld.get_to_castle(game)
game.world.age = Ages.CASTLE
game.world.resources = [1000, 1000, 1000, 1000]
game.world._add_building(Buildings.MONASTERY, {}, {})
game.assign_villager(current_time, Tasks.IDLE, Tasks.WOOD, 3)
# add some long amount of time so we are sure to have enough wood
current_time += 500
game.build(current_time,
Buildings.MONASTERY,
Tasks.WOOD,
Tasks.WOOD)
current_time += 40
game.assign_villager(current_time, Tasks.WOOD, Tasks.GOLD, 3)
gold_for_monk = 100
gold_per_60 = 22.8
gold_duration = int(gold_for_monk/(gold_per_60*3) + 1)*60
current_time += gold_duration
game.queue_unit(current_time, Units.MONK)
game.assign_villager(current_time, Tasks.GOLD, Tasks.IDLE, 3)
game.queue_unit(0, Units.MONK)
current_time = 51
game.play_until(current_time)
initial_gold = game.world.gather.resources[2]
current_time += 51
game.get_relic(current_time, walking_time=20)
current_time += 20
game.play_until(current_time + 60)
relic_gold_per_60 = 30