From 1b9266ff09a05604e5622da7b4c99f784acf089d Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Sun, 15 Nov 2026 20:17:31 -0500 Subject: [PATCH] Allow queuing villagers via task list This is helpful for testing build orders. --- aoe/gameplay.py | 10 ++++++++++ tests/test.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/aoe/gameplay.py b/aoe/gameplay.py index 21c5d9d..183d8f1 100644 --- a/aoe/gameplay.py +++ b/aoe/gameplay.py @@ -55,6 +55,16 @@ class Gameplay(): (research,))) + def queue_villagers_by_task_list(self, from_time, initial_tasks): + train_time = self.world.build_times.build_times[Units.VILLAGER] + + if not isinstance(initial_tasks, list): + initial_tasks = [initial_tasks] + + for i in range(len(initial_tasks)): + self.queue_villager(from_time + i*train_time, initial_tasks[i]) + + def queue_villagers_over_time(self, from_time, until_time, initial_task): train_time = self.world.build_times.build_times[Units.VILLAGER] duration = max(0, until_time - from_time) diff --git a/tests/test.py b/tests/test.py index e83464b..c023069 100644 --- a/tests/test.py +++ b/tests/test.py @@ -899,3 +899,53 @@ class TestWorld(unittest.TestCase): 100, 200], game.world) + + + def test_queue_with_task_list(self): + game = Gameplay() + + task_build_lumber = (Tasks.BUILD, + {'building': Buildings.LUMBERCAMP, + 'villagers_to': Tasks.WOOD}) + + build_order = [ + Tasks.SHEEP, + Tasks.SHEEP, + Tasks.SHEEP, + task_build_lumber, + ] + + game.queue_villagers_by_task_list(0, build_order) + game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP) + game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.SHEEP) + game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.SHEEP) + + game.play_until_last_action(extra_time=(25 + 35 + 60)) + + self.assertEqual(4, len(game.world.buildings)) + + train = 25 + build_lumber = 35 + build_house = 25 + + duration = 4*train + build_lumber + 60 + + sheep_rate_per_60 = 19.8 + + vil0 = sheep_rate_per_60*(duration/60) + vil1 = sheep_rate_per_60*((duration - build_house)/60) + vil2 = vil1 + vil3 = sheep_rate_per_60*((duration - train)/60) + vil4 = sheep_rate_per_60*((duration - 2*train)/60) + vil5 = sheep_rate_per_60*((duration - 3*train)/60) + + gathered_food = vil0 + vil1 + vil2 + vil3 + vil4 + vil5 + + wood_rate_per_60 = 23.4 + gathered_wood = wood_rate_per_60 + + self.assertResourcesMatch([gathered_food, + 50 + gathered_wood, + 100, + 200], + game.world)