diff --git a/aoe/gameplay.py b/aoe/gameplay.py index 74c3ed0..eb70ba5 100644 --- a/aoe/gameplay.py +++ b/aoe/gameplay.py @@ -34,99 +34,78 @@ class Gameplay(): self.actions[action_time].append((self.world.build, (building, villagers_from, - villagers_to,), - {})) + villagers_to,))) def market_buy(self, action_time, resource, amount): self._check_time(action_time) self.actions[action_time].append((self.world.market_buy, - (resource, amount), - {})) + (resource, amount))) def market_sell(self, action_time, resource, amount): self._check_time(action_time) self.actions[action_time].append((self.world.market_sell, - (resource, amount), - {})) + (resource, amount))) def queue_research(self, action_time, research): self._check_time(action_time) self.actions[action_time].append((self.world.queue_research, - (research,), - {})) + (research,))) - def queue_villagers_over_time(self, - from_time, - until_time, - initial_task, - **kwargs): + 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) for i in range(duration//train_time + 1): - self.queue_villager(from_time + i*train_time, - initial_task, - **kwargs) + self.queue_villager(from_time + i*train_time, initial_task) - def queue_villager(self, action_time, initial_task, **kwargs): + def queue_villager(self, action_time, initial_task): self._check_time(action_time) self.actions[action_time].append((self.world.queue_villager, - (initial_task,), - kwargs)) + (initial_task,))) def queue_fishing_ship(self, action_time, initial_task=Tasks.FISH_SHIP_DEEP): self._check_time(action_time) self.actions[action_time].append((self.world.queue_fishing_ship, - (initial_task,), - {})) + (initial_task,))) def queue_trade_cog(self, action_time): self._check_time(action_time) - self.actions[action_time].append((self.world.queue_trade_cog, - (), - {})) + self.actions[action_time].append((self.world.queue_trade_cog, ())) def queue_trade_cart(self, action_time): self._check_time(action_time) - self.actions[action_time].append((self.world.queue_trade_cart, - (), - {})) + self.actions[action_time].append((self.world.queue_trade_cart, ())) def queue_unit(self, action_time, unit): self._check_time(action_time) - self.actions[action_time].append((self.world.queue_unit, - (unit,), - {})) + 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,), - {})) + (old_task, new_task, count,))) def get_relic(self, action_time, walking_time=60): self._check_time(action_time) self.actions[action_time].append((self.world.get_relic, - (walking_time,), - {})) + (walking_time,))) def set_housed_is_error(self, action_time, is_error=True): self._check_time(action_time) self.actions[action_time].append((self.world.set_housed_is_error, - (is_error,), - {})) + (is_error,))) def lure_huntable_with_villager(self, @@ -135,15 +114,12 @@ class Gameplay(): walking_time=30): self._check_time(action_time) self.actions[action_time].append((self.world.lure_huntable_with_villager, - (previous_task, walking_time), - {})) + (previous_task, walking_time))) def increase_age(self, action_time): self._check_time(action_time) - self.actions[action_time].append((self.world.increase_age, - (), - {})) + self.actions[action_time].append((self.world.increase_age, ())) def _check_time(self, action_time): @@ -174,12 +150,12 @@ class Gameplay(): def _handle_actions(self): - for func, args, kwargs in self.actions[self.world.current_time]: + for func, args in self.actions[self.world.current_time]: try: - func(*args, **kwargs) + func(*args) except Exception as e: raise type(e)( - f'Error in {func.__name__}{args}{kwargs}' + f'Error in {func.__name__}{args}' f' at time {self.world.current_time}.') from e del self.actions[self.world.current_time] diff --git a/aoe/world.py b/aoe/world.py index 7903012..4f59c30 100644 --- a/aoe/world.py +++ b/aoe/world.py @@ -128,12 +128,10 @@ class World(): next_decrease += self.current_time if task in Gather.FARM_LIKE_TASKS: self.events[next_decrease].append((self._remove_consumable_building, - (task,), - {})) + (task,))) else: self.events[next_decrease].append((self._decrease_gather_rate_by_overuse, - (task,), - {})) + (task,))) self.rate_decrease_event_times[task] = next_decrease @@ -172,7 +170,7 @@ class World(): 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.events[update_time].append((self._add_huntable, ())) self.assign_villager(previous_task, Tasks.LURE) @@ -275,7 +273,7 @@ class World(): update_time = self.current_time + walking_time - self.events[update_time].append((self._add_relic, (), {})) + self.events[update_time].append((self._add_relic, ())) def _add_relic(self): @@ -322,8 +320,7 @@ class World(): self.events[update_time].append((self._add_building, (building, villagers_to_count, - building_tasks,), - {})) + building_tasks,))) def _add_building(self, building, villagers_to, tasks_improved): @@ -424,12 +421,12 @@ class World(): i += 1 - def _free_production_building_of_thing(self, thing, **kwargs): + def _free_production_building_of_thing(self, thing): building = self.production.building[thing] self._free_production_building(building) - def _free_production_building(self, building, **kwargs): + def _free_production_building(self, building): # This will not respect the order of a queue in a particular building. # For example, if there is a TC with the queue [villager, loom] and # there is no available housing, the TC will research loom. In the @@ -442,10 +439,10 @@ class World(): i = 0 while i < len(self.production_queue): - thing, task, kwargs = self.production_queue[i] + thing, task = self.production_queue[i] if self.production.building[thing] == building and \ house_check(self, thing): - self._start_producing(thing, task, **kwargs) + self._start_producing(thing, task) del self.production_queue[i] break i += 1 @@ -474,7 +471,7 @@ class World(): self._free_housing() - def _add_thing(self, thing, initial_task, **kwargs): + def _add_thing(self, thing, initial_task): self.units_being_built -= self.housing.required[thing] self.population += self.housing.required[thing] @@ -489,18 +486,7 @@ class World(): self.villager_tasks[Tasks.IDLE] += 1 if not initial_task: initial_task = Tasks.IDLE - - if initial_task == Tasks.LURE: - self.lure_huntable_with_villager(Tasks.IDLE, **kwargs) - elif initial_task == Tasks.BUILD: - if 'building_task' not in kwargs.keys(): - kwargs['building_task'] = None - self.build(kwargs['building'], - Tasks.IDLE, - kwargs['villagers_to'], - kwargs['building_task']) - else: - self.assign_villager(Tasks.IDLE, initial_task) + self.assign_villager(Tasks.IDLE, initial_task) elif thing == Units.MONK: self.villager_tasks[Tasks.MONK_IDLE] += 1 self._get_next_waiting_relic() @@ -514,7 +500,7 @@ class World(): self.villager_tasks[Tasks.TRADECART] += 1 - def _start_producing(self, thing, initial_task, **kwargs): + def _start_producing(self, thing, initial_task): try: self._use_housing_and_production(thing) except Exception as e: @@ -522,22 +508,20 @@ class World(): is_housing = isinstance(e, YallGotHousedException) if is_prod or (is_housing and not self.housed_is_error): - self.production_queue.append((thing, initial_task, kwargs)) + self.production_queue.append((thing, initial_task)) else: raise(e) else: update_time = self.current_time + self.build_times.build_times[thing] - self.events[update_time].append((self._add_thing, - (thing, initial_task,), - kwargs)) + self.events[update_time].append((self._add_thing, (thing, initial_task,))) - def _queue_thing(self, thing, initial_task=None, **kwargs): + def _queue_thing(self, thing, initial_task=None): self.dependencies.check_dependencies(self, thing) self.costs.compute_cost(thing) self.pay_cost(thing) - self._start_producing(thing, initial_task, **kwargs) + self._start_producing(thing, initial_task) def queue_research(self, research): @@ -548,8 +532,8 @@ class World(): self._queue_thing(unit) - def queue_villager(self, initial_task, **kwargs): - self._queue_thing(Units.VILLAGER, initial_task, **kwargs) + def queue_villager(self, initial_task): + self._queue_thing(Units.VILLAGER, initial_task) def queue_fishing_ship(self, initial_task=Tasks.FISH_SHIP_DEEP): @@ -565,13 +549,12 @@ class World(): def _handle_events(self): - for func, args, kwargs in self.events[self.current_time]: + for func, args in self.events[self.current_time]: try: - func(*args, **kwargs) + func(*args) except Exception as e: raise type(e)( f'Error in {func.__name__}{args}' - f' with keyword arguments {kwargs}' f' at time {self.current_time}.' f' Note that the actual gameplay command that caused' f' the error may not have been issued at' @@ -596,7 +579,7 @@ class World(): self.pay_cost(new_age) update_time = self.current_time + self.build_times.build_times[new_age] - self.events[update_time].append((self._update_age, (new_age,), {})) + self.events[update_time].append((self._update_age, (new_age,))) def _deal_with_civ(self): diff --git a/tests/test.py b/tests/test.py index 4683292..3d66a6a 100644 --- a/tests/test.py +++ b/tests/test.py @@ -251,32 +251,6 @@ class TestWorld(unittest.TestCase): self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world) - def test_gather_boar_initial_lure(self): - walking = 30 - - game = Gameplay() - game.queue_villager(0, Tasks.LURE) - game.play_until(25 + walking + 60) - - boar_rate_times_60 = 24.6 - gathered = boar_rate_times_60 - - self.assertResourcesMatch([150 + gathered, 200, 100, 200], game.world) - - - def test_gather_boar_initial_lure_custom_time(self): - walking = 80 - - game = Gameplay() - game.queue_villager(0, Tasks.LURE, walking_time=walking) - game.play_until(25 + walking + 60) - - boar_rate_times_60 = 24.6 - gathered = boar_rate_times_60 - - self.assertResourcesMatch([150 + gathered, 200, 100, 200], game.world) - - def test_gather_boar_limited(self): walking = 20 @@ -789,29 +763,3 @@ class TestWorld(unittest.TestCase): self.assertEqual(4, len(game.world.buildings)) self.assertResourcesMatch([200 + gathered, 50, 100, 200], game.world) - - - def test_initial_build(self): - game = Gameplay() - - game.queue_villager(0, - Tasks.BUILD, - building=Buildings.HOUSE, - villagers_to=Tasks.SHEEP) - - game.play_until(10) - self.assertEqual(1, len(game.world.buildings)) - self.assertEqual(4, game.world.population) - - game.play_until(30) - self.assertEqual(1, len(game.world.buildings)) - self.assertEqual(5, game.world.population) - - game.play_until(25 + 25 + 60) - self.assertEqual(2, len(game.world.buildings)) - self.assertEqual(5, game.world.population) - - sheep_rate_per_60 = 19.8 - gathered = sheep_rate_per_60 - - self.assertResourcesMatch([150 + gathered, 175, 100, 200], game.world)