Compare commits

...

2 Commits

Author SHA1 Message Date
Nate Bowman
0780fec1fb Fix bug in housing check and add test 2026-11-16 19:19:26 -05:00
Nate Bowman
1b9266ff09 Allow queuing villagers via task list
This is helpful for testing build orders.
2026-11-15 20:17:31 -05:00
3 changed files with 87 additions and 3 deletions

View File

@@ -55,6 +55,16 @@ class Gameplay():
(research,))) (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): def queue_villagers_over_time(self, from_time, until_time, initial_task):
train_time = self.world.build_times.build_times[Units.VILLAGER] train_time = self.world.build_times.build_times[Units.VILLAGER]
duration = max(0, until_time - from_time) duration = max(0, until_time - from_time)

View File

@@ -16,14 +16,14 @@ class Housing():
if world.get_effective_population() + required > pop_space: if world.get_effective_population() + required > pop_space:
raise YallGotHousedException raise YallGotHousedException
return True
def check_housing_safe(self, world, thing): def check_housing_safe(self, world, thing):
try: try:
self.check_housing(world, thing) return self.check_housing(world, thing)
except YallGotHousedException: except YallGotHousedException:
return False return False
else:
return True
def __init__(self): def __init__(self):

View File

@@ -899,3 +899,77 @@ class TestWorld(unittest.TestCase):
100, 100,
200], 200],
game.world) 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)
def test_production_queue_two_units(self):
game = Gameplay()
game.world._add_building(Buildings.BARRACKS, {}, {})
game.world._add_building(Buildings.HOUSE, {}, {})
training = 21
game.queue_unit(0, Units.MILITIA)
game.queue_unit(0, Units.MILITIA)
game.play_until(1)
self.assertEqual(4, game.world.population)
game.play_until(training)
self.assertEqual(5, game.world.population)
game.play_until(training + 10)
self.assertEqual(5, game.world.population)
game.play_until(2*training)
self.assertEqual(6, game.world.population)