Compare commits
1 Commits
master
...
44f60c891b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44f60c891b |
31
LICENSE.txt
31
LICENSE.txt
@@ -1,31 +0,0 @@
|
||||
MIT NON-AI License
|
||||
|
||||
Copyright (c) 2026, Nathaniel Bowman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
In addition, the following restrictions apply:
|
||||
|
||||
1. The Software and any modifications made to it may not be used for the purpose of training or improving machine learning algorithms,
|
||||
including but not limited to artificial intelligence, natural language processing, or data mining. This condition applies to any derivatives,
|
||||
modifications, or updates based on the Software code. Any usage of the Software in an AI-training dataset is considered a breach of this License.
|
||||
|
||||
2. The Software may not be included in any dataset used for training or improving machine learning algorithms,
|
||||
including but not limited to artificial intelligence, natural language processing, or data mining.
|
||||
|
||||
3. Any person or organization found to be in violation of these restrictions will be subject to legal action and may be held liable
|
||||
for any damages resulting from such use.
|
||||
|
||||
4. This software repository contains open-source software licenses that can be modified and used to derive other software licenses.
|
||||
However, no derivative, modification or update is allowed to remove the licensing conditions that forbid the use of that derivative
|
||||
for the purpose of training, or improving machine learning algorithms, including but not limited to artificial intelligence,
|
||||
natural language processing, or data mining.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,5 +1,4 @@
|
||||
This is a simulator that produces a timeline of villager production and
|
||||
resource gathering for Age of Empires 2.
|
||||
Timeline of villager production and gathering for Age of Empires 2.
|
||||
|
||||
You can see the `tests/test.py` file for examples of how to use it.
|
||||
|
||||
|
||||
@@ -55,16 +55,6 @@ 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)
|
||||
@@ -73,17 +63,8 @@ class Gameplay():
|
||||
self.queue_villager(from_time + i*train_time, initial_task)
|
||||
|
||||
|
||||
def queue_villager(self, action_time, initial_task, **kwargs):
|
||||
'''
|
||||
initial_task can be instance of one of the following:
|
||||
Tasks -- assign this task along with any keyword arguments
|
||||
(Tasks, dict) -- assume the dict contains the keyword arguments
|
||||
List of (Tasks, dict) -- several tasks to complete in order, each with
|
||||
its own keyword arguments
|
||||
'''
|
||||
def queue_villager(self, action_time, initial_task):
|
||||
self._check_time(action_time)
|
||||
if isinstance(initial_task, Tasks):
|
||||
initial_task = (initial_task, kwargs)
|
||||
self.actions[action_time].append((self.world.queue_villager,
|
||||
(initial_task,)))
|
||||
|
||||
@@ -115,25 +96,12 @@ class Gameplay():
|
||||
(old_task, new_task, count,)))
|
||||
|
||||
|
||||
def add_task_to_work_queue(self, action_time, task, **kwargs):
|
||||
self._check_time(action_time)
|
||||
task = (task, kwargs)
|
||||
self.actions[action_time].append((self.world.add_task_to_work_queue,
|
||||
(task,)))
|
||||
|
||||
|
||||
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,)))
|
||||
|
||||
|
||||
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,)))
|
||||
|
||||
|
||||
def lure_huntable_with_villager(self,
|
||||
action_time,
|
||||
previous_task,
|
||||
@@ -153,15 +121,6 @@ class Gameplay():
|
||||
raise CannotChangeThePastException
|
||||
|
||||
|
||||
def _get_last_action_time(self):
|
||||
try:
|
||||
last_action_time = max(self.actions.keys())
|
||||
except ValueError:
|
||||
last_action_time = self.world.current_time
|
||||
|
||||
return last_action_time
|
||||
|
||||
|
||||
def _get_next_action_time(self):
|
||||
try:
|
||||
next_action_time = min(self.actions.keys())
|
||||
@@ -177,12 +136,7 @@ class Gameplay():
|
||||
|
||||
def _handle_actions(self):
|
||||
for func, args in self.actions[self.world.current_time]:
|
||||
try:
|
||||
func(*args)
|
||||
except Exception as e:
|
||||
raise type(e)(
|
||||
f'Error in {func.__name__}{args}'
|
||||
f' at time {self.world.current_time}.') from e
|
||||
func(*args)
|
||||
del self.actions[self.world.current_time]
|
||||
|
||||
|
||||
@@ -194,11 +148,6 @@ class Gameplay():
|
||||
self._handle_actions()
|
||||
|
||||
|
||||
def play_until_last_action(self, extra_time=0):
|
||||
last_action_time = self._get_last_action_time()
|
||||
self.play_until(last_action_time + extra_time)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.world = World()
|
||||
self.actions = defaultdict(list)
|
||||
|
||||
@@ -233,8 +233,7 @@ class Gather():
|
||||
else:
|
||||
available = self.gatherable_amounts[task]
|
||||
|
||||
SMALL_FLOAT = 1e-8
|
||||
if rate < SMALL_FLOAT or (villagers == 0 and decay == 0):
|
||||
if rate == 0 or (villagers == 0 and decay == 0):
|
||||
next_decrease = None
|
||||
else:
|
||||
next_decrease = available/(villagers*rate + decay)
|
||||
|
||||
@@ -16,15 +16,6 @@ class Housing():
|
||||
if world.get_effective_population() + required > pop_space:
|
||||
raise YallGotHousedException
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def check_housing_safe(self, world, thing):
|
||||
try:
|
||||
return self.check_housing(world, thing)
|
||||
except YallGotHousedException:
|
||||
return False
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.space = defaultdict(int, {
|
||||
|
||||
@@ -14,15 +14,6 @@ class Production():
|
||||
raise ProductionBuildingNotAvailableException
|
||||
|
||||
|
||||
def check_production_safe(self, world, thing):
|
||||
try:
|
||||
self.check_production(world, thing)
|
||||
except ProductionBuildingNotAvailableException:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
# assumes for now each unit can be built in only one type of building
|
||||
def __init__(self):
|
||||
self.building = defaultdict(None, {
|
||||
|
||||
114
aoe/world.py
114
aoe/world.py
@@ -180,35 +180,6 @@ class World():
|
||||
self.assign_villager(Tasks.LURE, Tasks.BOAR)
|
||||
|
||||
|
||||
def add_task_to_work_queue(self, task, **kwargs):
|
||||
if isinstance(task, Tasks):
|
||||
task = (task, kwargs)
|
||||
self.villager_work_queue.append(task)
|
||||
self._assign_to_villagers_from_work_queue()
|
||||
|
||||
|
||||
def _assign_idle_villager_possibly_compound_task(self, task, **kwargs):
|
||||
if task == Tasks.LURE:
|
||||
self.lure_huntable_with_villager(Tasks.IDLE, **kwargs)
|
||||
elif 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, task)
|
||||
|
||||
|
||||
def _assign_to_villagers_from_work_queue(self):
|
||||
while (self.villager_tasks[Tasks.IDLE] > 0 and
|
||||
len(self.villager_work_queue) > 0):
|
||||
original_task = self.villager_work_queue.pop(0)
|
||||
task, kwargs = self._parse_task(original_task)
|
||||
self._assign_idle_villager_possibly_compound_task(task, **kwargs)
|
||||
|
||||
|
||||
def assign_villager(self, previous_task, new_task, count=1):
|
||||
# new_task of None means kill the villager
|
||||
|
||||
@@ -237,8 +208,6 @@ class World():
|
||||
if new_task:
|
||||
self._schedule_next_gather_rate_decrease(new_task)
|
||||
|
||||
self._assign_to_villagers_from_work_queue()
|
||||
|
||||
|
||||
def _check_valid_builders(self, villagers_from, building):
|
||||
# If building a fishtrap, at least one builder needs to be a fishing
|
||||
@@ -279,14 +248,6 @@ class World():
|
||||
self.assign_villager(task, build_task, count)
|
||||
|
||||
|
||||
def _get_house_check_function(self):
|
||||
if self.housed_is_error:
|
||||
house_check = self.housing.check_housing
|
||||
else:
|
||||
house_check = self.housing.check_housing_safe
|
||||
return house_check
|
||||
|
||||
|
||||
def _get_build_task_from_task(self, task):
|
||||
if task in Gather.FISHING_TASKS:
|
||||
return Tasks.FISH_SHIP_BUILD
|
||||
@@ -421,10 +382,6 @@ class World():
|
||||
self._handle_events()
|
||||
|
||||
|
||||
def set_housed_is_error(self, is_error=True):
|
||||
self.housed_is_error = is_error
|
||||
|
||||
|
||||
def get_population_space(self):
|
||||
space = sum([self.housing.space[building] for building in self.buildings])
|
||||
return min(space, World.POPULATION_CAP)
|
||||
@@ -437,15 +394,13 @@ class World():
|
||||
def _free_housing(self):
|
||||
pop_space = self.get_population_space()
|
||||
|
||||
house_check = self._get_house_check_function()
|
||||
|
||||
i = 0
|
||||
while (self.get_effective_population() < pop_space and
|
||||
i < len(self.production_queue)):
|
||||
|
||||
thing, task = self.production_queue[i]
|
||||
if house_check(self, thing) and \
|
||||
self.production.check_production_safe(self, thing):
|
||||
if self.housing.check_housing(self, thing) and \
|
||||
self.production.check_production(self, thing):
|
||||
self._start_producing(thing, task)
|
||||
del self.production_queue[i]
|
||||
else:
|
||||
@@ -466,13 +421,11 @@ class World():
|
||||
# production queue as a shared pool, and I don't really care.
|
||||
self.production_available[building] += 1
|
||||
|
||||
house_check = self._get_house_check_function()
|
||||
|
||||
i = 0
|
||||
while i < len(self.production_queue):
|
||||
thing, task = self.production_queue[i]
|
||||
if self.production.building[thing] == building and \
|
||||
house_check(self, thing):
|
||||
self.housing.check_housing(self, thing):
|
||||
self._start_producing(thing, task)
|
||||
del self.production_queue[i]
|
||||
break
|
||||
@@ -503,11 +456,6 @@ class World():
|
||||
|
||||
|
||||
def _add_thing(self, thing, initial_task):
|
||||
if (initial_task and
|
||||
thing != Units.VILLAGER and
|
||||
not isinstance(initial_task, Tasks)):
|
||||
raise ValueError('Only villagers can accept compound tasks')
|
||||
|
||||
self.units_being_built -= self.housing.required[thing]
|
||||
self.population += self.housing.required[thing]
|
||||
|
||||
@@ -520,8 +468,9 @@ class World():
|
||||
if thing == Units.VILLAGER:
|
||||
self.villagers += 1
|
||||
self.villager_tasks[Tasks.IDLE] += 1
|
||||
task, kwargs = self._parse_task(initial_task)
|
||||
self._assign_idle_villager_possibly_compound_task(task, **kwargs)
|
||||
if not initial_task:
|
||||
initial_task = Tasks.IDLE
|
||||
self.assign_villager(Tasks.IDLE, initial_task)
|
||||
elif thing == Units.MONK:
|
||||
self.villager_tasks[Tasks.MONK_IDLE] += 1
|
||||
self._get_next_waiting_relic()
|
||||
@@ -538,14 +487,8 @@ class World():
|
||||
def _start_producing(self, thing, initial_task):
|
||||
try:
|
||||
self._use_housing_and_production(thing)
|
||||
except Exception as e:
|
||||
is_prod = isinstance(e, ProductionBuildingNotAvailableException)
|
||||
is_housing = isinstance(e, YallGotHousedException)
|
||||
|
||||
if is_prod or (is_housing and not self.housed_is_error):
|
||||
self.production_queue.append((thing, initial_task))
|
||||
else:
|
||||
raise(e)
|
||||
except ProductionBuildingNotAvailableException:
|
||||
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,)))
|
||||
@@ -583,45 +526,9 @@ class World():
|
||||
self._queue_thing(Units.TRADECART)
|
||||
|
||||
|
||||
def _parse_task(self, initial_task):
|
||||
'''
|
||||
A single task is either a Task or a tuple of (Tasks, dict) where the
|
||||
dictionary contains keyword arguments.
|
||||
|
||||
If a list is passed, all tasks beyond the first are appended to the
|
||||
villager work queue.
|
||||
'''
|
||||
if isinstance(initial_task, list):
|
||||
remaining_tasks = initial_task[1:]
|
||||
self.villager_work_queue.extend(remaining_tasks)
|
||||
initial_task = initial_task[0]
|
||||
|
||||
kwargs = {}
|
||||
|
||||
if isinstance(initial_task, tuple):
|
||||
kwargs = initial_task[1]
|
||||
initial_task = initial_task[0]
|
||||
|
||||
if not initial_task:
|
||||
initial_task = Tasks.IDLE
|
||||
|
||||
return initial_task, kwargs
|
||||
|
||||
|
||||
def _handle_events(self):
|
||||
for func, args in self.events[self.current_time]:
|
||||
try:
|
||||
func(*args)
|
||||
except Exception as e:
|
||||
raise type(e)(
|
||||
f'Error in {func.__name__}{args}'
|
||||
f' at time {self.current_time}.'
|
||||
f' Note that the actual gameplay command that caused'
|
||||
f' the error may not have been issued at'
|
||||
f' {self.current_time} -- the action may have been'
|
||||
f' delayed until that time while'
|
||||
f' waiting in a queue') from e
|
||||
|
||||
func(*args)
|
||||
del self.events[self.current_time]
|
||||
|
||||
|
||||
@@ -657,7 +564,6 @@ class World():
|
||||
|
||||
self.villager_tasks = {t: 0 for t in Tasks}
|
||||
self.villager_tasks[Tasks.IDLE] = self.villagers
|
||||
self.villager_work_queue = []
|
||||
|
||||
self.rate_decrease_event_times = {t: None for t in Tasks}
|
||||
|
||||
@@ -677,6 +583,4 @@ class World():
|
||||
self.production = Production()
|
||||
self.gather = Gather()
|
||||
|
||||
self.housed_is_error = True
|
||||
|
||||
self._deal_with_civ()
|
||||
|
||||
413
tests/test.py
413
tests/test.py
@@ -92,39 +92,6 @@ class TestWorld(unittest.TestCase):
|
||||
self.assertResourcesMatch([150, new_wood, 100, 200], game.world)
|
||||
|
||||
|
||||
def test_wood_stale_camp(self):
|
||||
game = Gameplay()
|
||||
|
||||
wood_amount_per_camp = 1000
|
||||
|
||||
wood_rate_times_60 = 23.4
|
||||
wood_rate_decrease = 0.85
|
||||
slow_wood_rate_times_60 = wood_rate_times_60*wood_rate_decrease
|
||||
|
||||
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||
game.assign_villager(1, Tasks.IDLE, Tasks.WOOD)
|
||||
|
||||
game.play_until(60)
|
||||
new_wood = 200 + wood_rate_times_60
|
||||
self.assertResourcesMatch([200, new_wood, 100, 200], game.world)
|
||||
|
||||
camp_expires = 60*wood_amount_per_camp/wood_rate_times_60
|
||||
|
||||
game.play_until(camp_expires)
|
||||
new_wood = 200 + wood_rate_times_60*(camp_expires/60)
|
||||
self.assertResourcesMatch([200, new_wood, 100, 200], game.world)
|
||||
self.assertResourcesMatch([200,
|
||||
200 + wood_amount_per_camp,
|
||||
100,
|
||||
200],
|
||||
game.world)
|
||||
|
||||
game.play_until(camp_expires + 60)
|
||||
new_wood += slow_wood_rate_times_60
|
||||
|
||||
self.assertResourcesMatch([200, new_wood, 100, 200], game.world)
|
||||
|
||||
|
||||
def test_good_villager_task_assign(self):
|
||||
game = Gameplay()
|
||||
game.assign_villager(5, Tasks.IDLE, Tasks.SHEEP)
|
||||
@@ -169,18 +136,6 @@ class TestWorld(unittest.TestCase):
|
||||
self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings)
|
||||
|
||||
|
||||
def test_build_lumber_camp_three_villagers(self):
|
||||
lc_build_time = 35
|
||||
lc_build_time_three_vils = 3*lc_build_time/(3 + 2)
|
||||
|
||||
game = Gameplay()
|
||||
game.build(0, Buildings.LUMBERCAMP, [Tasks.IDLE]*3, [Tasks.IDLE]*3)
|
||||
game.play_until(lc_build_time_three_vils - 1)
|
||||
self.assertTrue(Buildings.LUMBERCAMP not in game.world.buildings)
|
||||
game.play_until(lc_build_time_three_vils)
|
||||
self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings)
|
||||
|
||||
|
||||
def test_building_adds_gatherable(self):
|
||||
lc_build_time = 35
|
||||
|
||||
@@ -247,34 +202,6 @@ class TestWorld(unittest.TestCase):
|
||||
game.play_until(25)
|
||||
|
||||
|
||||
def test_get_housed_no_error(self):
|
||||
game = Gameplay()
|
||||
game.queue_villager(0, Tasks.IDLE)
|
||||
game.queue_villager(0, Tasks.IDLE)
|
||||
game.queue_villager(0, Tasks.IDLE)
|
||||
|
||||
game.set_housed_is_error(24, False)
|
||||
game.play_until(100)
|
||||
self.assertEqual(5, game.world.population)
|
||||
|
||||
|
||||
def test_get_housed_toggle_error(self):
|
||||
game = Gameplay()
|
||||
game.world.gather.resources = [1000, 1000, 1000, 1000]
|
||||
|
||||
game.queue_villager(0, Tasks.IDLE)
|
||||
game.queue_villager(0, Tasks.IDLE)
|
||||
|
||||
game.set_housed_is_error(24, False)
|
||||
game.play_until(80)
|
||||
|
||||
game.set_housed_is_error(81, True)
|
||||
game.queue_villager(82, Tasks.IDLE)
|
||||
|
||||
with self.assertRaises(YallGotHousedException):
|
||||
game.play_until(85)
|
||||
|
||||
|
||||
def test_gather_boar_without_lure(self):
|
||||
game = Gameplay()
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.BOAR, 1)
|
||||
@@ -296,32 +223,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
|
||||
|
||||
@@ -366,7 +267,7 @@ class TestWorld(unittest.TestCase):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.CASTLE
|
||||
game.world.gather.resources = [1000, 1000, 1000, 1000]
|
||||
game.world.resources = [1000, 1000, 1000, 1000]
|
||||
game.world._add_building(Buildings.MONASTERY, {}, {})
|
||||
|
||||
game.queue_unit(0, Units.MONK)
|
||||
@@ -811,315 +712,3 @@ class TestWorld(unittest.TestCase):
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_play_until_last_action(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.build(0, Buildings.HOUSE, [Tasks.IDLE]*2, [Tasks.IDLE]*2)
|
||||
game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.IDLE)
|
||||
game.build(100, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.IDLE)
|
||||
|
||||
game.play_until_last_action()
|
||||
|
||||
self.assertEqual(3, len(game.world.buildings))
|
||||
|
||||
game.assign_villager(200, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.assign_villager(200, Tasks.IDLE, Tasks.SHEEP)
|
||||
|
||||
game.play_until_last_action(extra_time=60)
|
||||
|
||||
sheep_rate_per_60 = 19.8
|
||||
gathered = sheep_rate_per_60*2
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def test_work_queue_adding_villager(self):
|
||||
game = Gameplay()
|
||||
|
||||
build_house = (Tasks.BUILD,
|
||||
{'building': Buildings.HOUSE,
|
||||
'villagers_to': Tasks.IDLE})
|
||||
build_lumber = (Tasks.BUILD,
|
||||
{'building': Buildings.LUMBERCAMP,
|
||||
'villagers_to': Tasks.IDLE})
|
||||
build_house_to_wood = (Tasks.BUILD,
|
||||
{'building': Buildings.HOUSE,
|
||||
'villagers_to': Tasks.WOOD})
|
||||
|
||||
task_list = [
|
||||
build_house,
|
||||
build_house,
|
||||
build_lumber,
|
||||
build_house_to_wood,
|
||||
]
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.queue_villager(0, task_list)
|
||||
|
||||
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)
|
||||
|
||||
train_and_build_time = 25 + 25*2 + 35 + 25
|
||||
duration = train_and_build_time + 60
|
||||
game.play_until(duration)
|
||||
self.assertEqual(5, len(game.world.buildings))
|
||||
self.assertEqual(5, game.world.population)
|
||||
|
||||
sheep_rate_per_60 = 19.8
|
||||
gathered_food = sheep_rate_per_60*(duration/60)*3
|
||||
|
||||
wood_rate_per_60 = 23.4
|
||||
gathered_wood = wood_rate_per_60
|
||||
|
||||
self.assertResourcesMatch([150 + gathered_food,
|
||||
25 + gathered_wood,
|
||||
100,
|
||||
200],
|
||||
game.world)
|
||||
|
||||
|
||||
def test_add_tasks_to_work_queue(self):
|
||||
game = Gameplay()
|
||||
|
||||
task_list = [
|
||||
Tasks.WOOD,
|
||||
Tasks.WOOD,
|
||||
Tasks.SHEEP,
|
||||
]
|
||||
|
||||
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||
|
||||
game.queue_villager(0, Tasks.WOOD)
|
||||
for t in task_list:
|
||||
game.add_task_to_work_queue(0, t)
|
||||
|
||||
duration = 25 + 60
|
||||
game.play_until(duration)
|
||||
|
||||
sheep_rate_per_60 = 19.8
|
||||
gathered_food = sheep_rate_per_60*(duration/60)
|
||||
|
||||
wood_rate_per_60 = 23.4
|
||||
gathered_wood = wood_rate_per_60*(duration/60)*2
|
||||
gathered_wood += wood_rate_per_60
|
||||
|
||||
self.assertResourcesMatch([150 + gathered_food,
|
||||
200 + gathered_wood,
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def test_production_queue_new_building(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(10)
|
||||
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||
|
||||
game.play_until(training)
|
||||
self.assertEqual(5, game.world.population)
|
||||
|
||||
game.play_until(training + 10)
|
||||
self.assertEqual(6, game.world.population)
|
||||
|
||||
|
||||
def test_production_queue_new_housing(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world._add_building(Buildings.BARRACKS, {}, {})
|
||||
game.set_housed_is_error(0, False)
|
||||
|
||||
training = 21
|
||||
|
||||
game.queue_unit(0, Units.MILITIA)
|
||||
game.queue_unit(0, Units.MILITIA)
|
||||
|
||||
game.play_until(3*training)
|
||||
self.assertEqual(5, game.world.population)
|
||||
|
||||
game.world._add_building(Buildings.HOUSE, {}, {})
|
||||
game.play_until(4*training)
|
||||
self.assertEqual(6, game.world.population)
|
||||
|
||||
|
||||
def test_research_bit_axe(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
|
||||
wood_amount_per_camp = 1000
|
||||
|
||||
wood_rate_times_60 = 23.4
|
||||
bit_axe_mult = 1.2
|
||||
wood_rate_times_60 *= bit_axe_mult
|
||||
|
||||
bit_axe_time = 25
|
||||
|
||||
wood_rate_decrease = 0.85
|
||||
slow_wood_rate_times_60 = wood_rate_times_60*wood_rate_decrease
|
||||
|
||||
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||
game.queue_research(0, Research.DOUBLEBITAXE)
|
||||
|
||||
game.assign_villager(bit_axe_time, Tasks.IDLE, Tasks.WOOD)
|
||||
|
||||
game.play_until(bit_axe_time + 60)
|
||||
new_wood = 150 + wood_rate_times_60
|
||||
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||
|
||||
camp_duration = 60*wood_amount_per_camp/wood_rate_times_60
|
||||
|
||||
game.play_until(bit_axe_time + camp_duration)
|
||||
new_wood = 150 + wood_rate_times_60*(camp_duration/60)
|
||||
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||
self.assertResourcesMatch([100,
|
||||
150 + wood_amount_per_camp,
|
||||
100,
|
||||
200],
|
||||
game.world)
|
||||
|
||||
game.play_until(bit_axe_time + camp_duration + 60)
|
||||
new_wood += slow_wood_rate_times_60
|
||||
|
||||
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||
|
||||
|
||||
def test_research_bit_axe_partial_start(self):
|
||||
game = Gameplay()
|
||||
|
||||
wood_rate_times_60 = 23.4
|
||||
bit_axe_mult = 1.2
|
||||
|
||||
bit_axe_time = 25
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.WOOD)
|
||||
game.queue_research(35, Research.DOUBLEBITAXE)
|
||||
|
||||
game.play_until(60)
|
||||
new_wood = 150 + wood_rate_times_60
|
||||
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||
|
||||
game.play_until(120)
|
||||
new_wood = 150 + wood_rate_times_60*(1 + bit_axe_mult)
|
||||
self.assertResourcesMatch([100, new_wood, 100, 200], game.world)
|
||||
|
||||
Reference in New Issue
Block a user