Compare commits

..

6 Commits

Author SHA1 Message Date
Nate Bowman
54050235f0 Add functions to gameplay class 2026-11-06 19:16:22 -05:00
Nate Bowman
622bdc38fb Remove runner file
Tests file shows examples of how to run the simulator
2026-11-06 19:14:52 -05:00
Nate Bowman
e67085aab7 Add boar luring
No decay accounted for yet
2026-11-06 19:13:57 -05:00
Nate Bowman
c6550fb007 Fix moving to next age 2026-11-06 19:09:15 -05:00
Nate Bowman
9e45d182b0 Add missing function 2026-11-06 19:08:39 -05:00
Nate Bowman
1f19740355 Fix bug in production queue
Queue was losing initial task
2026-11-06 19:06:53 -05:00
5 changed files with 62 additions and 82 deletions

View File

@@ -49,12 +49,31 @@ class Gameplay():
(initial_task,)))
def queue_unit(self, action_time, unit):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_unit, (unit,)))
def assign_villager(self, action_time, old_task, new_task, count=1):
self._check_time(action_time)
self.actions[action_time].append((self.world.assign_villager,
(old_task, new_task, count,)))
def lure_huntable_with_villager(self,
action_time,
previous_task,
walking_time=30):
self._check_time(action_time)
self.actions[action_time].append((self.world.lure_huntable_with_villager,
(previous_task, walking_time)))
def increase_age(self, action_time):
self._check_time(action_time)
self.actions[action_time].append((self.world.increase_age, ()))
def _check_time(self, action_time):
# TODO will it work if we do something at current time?
if self.world.current_time > action_time:

View File

@@ -141,7 +141,11 @@ class Gather():
def check_gather(self, world, task, count=1):
if task in [Tasks.IDLE, Tasks.BUILD]:
if task in [
Tasks.IDLE,
Tasks.BUILD,
Tasks.LURE,
]:
return
required = self.required_gather_buildings[task]
@@ -266,10 +270,18 @@ class Gather():
return len(self.farms)
def add_huntable(self):
self.improve_gather_rate_by_building(Tasks.LURE, None)
def gather_resources_for_duration(self, villager_tasks, duration):
# assumes there are sufficient resources in gatherable_amounts
for task, count in villager_tasks.items():
if task in [Tasks.BUILD, Tasks.IDLE]:
if task in [
Tasks.BUILD,
Tasks.LURE,
Tasks.IDLE,
]:
continue
rate = self.gather_rates[task]
@@ -372,7 +384,7 @@ class Gather():
# 4 deer
Tasks.BERRIES: 6*125,
Tasks.SHEEP: 8*100,
Tasks.BOAR: 2*340,
Tasks.BOAR: 0,
Tasks.HUNT: 4*140,
Tasks.FARM: 0,
# TODO next two should be shared
@@ -401,8 +413,9 @@ class Gather():
Tasks.GOLD: 4*800,
Tasks.STONE: 4*350,
Tasks.BERRIES: 6*125,
Tasks.HUNT: 4*140}
Tasks.HUNT: 4*140},
#Buildings.FISHTRAP: {Tasks.WOOD: 100},
Tasks.LURE: {Tasks.BOAR: 340},
}
self.gather_decrease_rates = {

View File

@@ -53,6 +53,7 @@ class Tasks(Enum):
SHEEP = auto()
BOAR = auto()
HUNT = auto()
LURE = auto()
FARM = auto()
FISH_VILLAGER = auto()
FISH_SHIP_SHORE = auto()

View File

@@ -65,6 +65,10 @@ class World():
self.gather.spend_resources(cost)
def has_building(self, building):
return building in self.buildings
def _remove_event_at_time(self, removed_event, scheduled_time):
if not scheduled_time:
return
@@ -76,7 +80,7 @@ class World():
def _schedule_next_gather_rate_decrease(self, task):
if task in [Tasks.IDLE, Tasks.BUILD]:
if task in [Tasks.IDLE, Tasks.BUILD, Tasks.LURE]:
return
# remove old decrease
@@ -129,6 +133,18 @@ class World():
self._schedule_next_gather_rate_decrease(task)
def lure_huntable_with_villager(self, previous_task, walking_time=30):
update_time = self.current_time + walking_time
self.events[update_time].append((self._add_huntable, ()))
self.assign_villager(previous_task, Tasks.LURE)
def _add_huntable(self):
self.gather.add_huntable()
self.assign_villager(Tasks.LURE, Tasks.BOAR)
def assign_villager(self, previous_task, new_task, count=1):
# new_task of None means kill the villager
@@ -273,10 +289,10 @@ class World():
while (self.get_effective_population() < pop_space and
i < len(self.production_queue)):
thing = self.production_queue[i]
thing, task = self.production_queue[i]
if self.housing.check_housing(self, thing) and \
self.production.check_production(self, thing):
self._start_producing(thing)
self._start_producing(thing, task)
del self.production_queue[i]
else:
i += 1
@@ -298,18 +314,18 @@ class World():
i = 0
while i < len(self.production_queue):
thing = self.production_queue[i]
thing, task = self.production_queue[i]
if self.production.building[thing] == building and \
self.housing.check_housing(self, thing):
self._start_producing(thing)
self._start_producing(thing, task)
del self.production_queue[i]
break
i += 1
def _use_housing_and_production(self, thing):
self.housing.check_housing(self, thing)
self.production.check_production(self, thing)
self.housing.check_housing(self, thing)
building = self.production.building[thing]
if building is not None:
@@ -350,7 +366,7 @@ class World():
try:
self._use_housing_and_production(thing)
except ProductionBuildingNotAvailableException:
self.production_queue.append(thing)
self.production_queue.append((thing, initial_task))
else:
update_time = self.current_time + self.build_times.build_times[thing]
self.events[update_time].append((self._add_thing, (thing, initial_task,)))
@@ -390,9 +406,9 @@ class World():
if self.age == Ages.IMPERIAL:
raise Exception("no.")
new_age = self.age + 1
new_age = Ages(self.age + 1)
self.dependencies.check_dependencies(new_age)
self.dependencies.check_dependencies(self, new_age)
self.pay_cost(new_age)
update_time = self.current_time + self.build_times.build_times[new_age]

View File

@@ -1,69 +0,0 @@
from aoe.exceptions import *
from aoe.types import *
from aoe.gameplay import *
#import ipdb; breakpoint()
# for testing
# TODO need to go back through old tasks when new housing is added
# TODO wherever we test against Age, it's probably wrong
# TODO add building to production_available when finished
# TODO need some warning, penalty, etc. if villager is assigned to task
# without appropriate building (e.g., mining with no camp)
# TODO building time assumes just 1 vil is working for now
# TODO need efficiency penalties on, e.g., "stale" lumber camp
# Set up world
game = Gameplay()
# should work even before we do anything
#game.print_status()
game.queue_villager(5, Tasks.WOOD) # first number is time in seconds
# should generate exception
#game.assign_villager(40, Tasks.SHEEP, Tasks.WOOD)
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
game.assign_villager(2, Tasks.IDLE, Tasks.SHEEP, 2)
# should generate exception
#game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
# should generate exception
#game.build(45, Buildings.STABLE, Tasks.WOOD, Tasks.IDLE)
#game.build(45, Buildings.LUMBERCAMP, Tasks.WOOD, Tasks.IDLE)
game.build(45, Buildings.LUMBERCAMP, Tasks.WOOD, Tasks.WOOD)
game.queue_research(45, Research.LOOM)
game.queue_villager(45, Tasks.WOOD)
game.queue_villager(45, Tasks.WOOD)
game.play_until(46)
game.print_status()
game.build(100, Buildings.HOUSE, [Tasks.SHEEP, Tasks.WOOD], [Tasks.IDLE]*2)
#game.assign_villager(Build.Stable(), "food", wait_until_finished=True)
'''
game.queue_unit(s1, Scout)
'''
game.assign_villager(130, Tasks.IDLE, Tasks.WOOD, 2)
# should generate exception
#game.build(200, Buildings.FARM, [Tasks.SHEEP], [Tasks.WOOD])
game.build(200, Buildings.MILL, [Tasks.SHEEP], [Tasks.WOOD])
game.build(250, Buildings.FARM, [Tasks.SHEEP, Tasks.WOOD], [Tasks.IDLE]*2)
# Evaluate game
game.play_until(800)
game.print_status()
# should generate exception
#game.assign_villager(0, Tasks.SHEEP, Tasks.WOOD)