Previously, the simulation would automatically end whenever it determined you were housed. That is still the default, but the user can now choose to have the simulation continue instead. Also, this likely fixes a bug whereby an error could have been thrown for an unavailable production building when searching the production queue.
743 lines
22 KiB
Python
743 lines
22 KiB
Python
# Run from root of repo with `python -m unittest tests/test.py`
|
|
import unittest
|
|
|
|
from aoe.exceptions import *
|
|
from aoe.types import *
|
|
from aoe.gameplay import *
|
|
|
|
|
|
|
|
class TestWorld(unittest.TestCase):
|
|
|
|
|
|
@staticmethod
|
|
def equal_to_tolerance(v1, v2, atol):
|
|
return (abs(v1 - v2) <= atol)
|
|
|
|
|
|
def assertResourcesMatch(self, expected, world):
|
|
CLOSE_ENOUGH = 1
|
|
|
|
for i in range(len(expected)):
|
|
small_diff = TestWorld.equal_to_tolerance(expected[i],
|
|
world.gather.resources[i],
|
|
CLOSE_ENOUGH)
|
|
self.assertTrue(small_diff,
|
|
f'Resource {i}: expected {expected[i]} but had '
|
|
f'{world.gather.resources[i]}')
|
|
|
|
|
|
def test_initial_world(self):
|
|
game = Gameplay()
|
|
|
|
self.assertResourcesMatch([200, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_idle_start(self):
|
|
game = Gameplay()
|
|
game.play_until(60)
|
|
|
|
self.assertResourcesMatch([200, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_build_villager_not_complete(self):
|
|
game = Gameplay()
|
|
game.queue_villager(5, Tasks.IDLE)
|
|
game.play_until(5 + 20)
|
|
|
|
self.assertEqual(4, game.world.population)
|
|
self.assertResourcesMatch([150, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_build_villager(self):
|
|
game = Gameplay()
|
|
game.queue_villager(5, Tasks.IDLE)
|
|
game.play_until(5 + 25)
|
|
|
|
self.assertEqual(5, game.world.population)
|
|
self.assertResourcesMatch([150, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_build_villagers_regularly(self):
|
|
game = Gameplay()
|
|
game.world._add_building(Buildings.HOUSE, {}, {})
|
|
|
|
game.queue_villagers_over_time(0, 75, Tasks.IDLE)
|
|
game.play_until(100)
|
|
|
|
self.assertEqual(8, game.world.population)
|
|
self.assertResourcesMatch([0, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_build_villager_leave_idle(self):
|
|
game = Gameplay()
|
|
game.queue_villager(5, Tasks.IDLE)
|
|
game.play_until(5 + 25 + 30)
|
|
|
|
self.assertEqual(5, game.world.population)
|
|
self.assertResourcesMatch([150, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_wood_no_camp(self):
|
|
game = Gameplay()
|
|
game.queue_villager(5, Tasks.WOOD)
|
|
game.play_until(5 + 25 + 60)
|
|
|
|
wood_rate = 23.4/60
|
|
wood_rate_decrease = 0.85
|
|
slow_wood_rate_times_60 = 23.4*wood_rate_decrease
|
|
|
|
new_wood = 200 + slow_wood_rate_times_60
|
|
|
|
self.assertResourcesMatch([150, new_wood, 100, 200], game.world)
|
|
|
|
|
|
def test_good_villager_task_assign(self):
|
|
game = Gameplay()
|
|
game.assign_villager(5, Tasks.IDLE, Tasks.SHEEP)
|
|
game.play_until(5)
|
|
|
|
|
|
def test_bad_villager_task_assign(self):
|
|
game = Gameplay()
|
|
game.assign_villager(5, Tasks.SHEEP, Tasks.WOOD)
|
|
with self.assertRaises(IllegalVillagerMoveException):
|
|
game.play_until(5)
|
|
|
|
|
|
def test_assign_several_villagers(self):
|
|
num_villagers = 3
|
|
|
|
game = Gameplay()
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP, num_villagers)
|
|
game.play_until(60)
|
|
|
|
sheep_rate_per_60 = 19.8
|
|
gathered = sheep_rate_per_60*num_villagers
|
|
|
|
self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_change_past(self):
|
|
game = Gameplay()
|
|
game.play_until(60)
|
|
with self.assertRaises(CannotChangeThePastException):
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
|
|
|
|
|
def test_build_lumber_camp_one_villager(self):
|
|
lc_build_time = 35
|
|
|
|
game = Gameplay()
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.IDLE)
|
|
game.play_until(20)
|
|
self.assertTrue(Buildings.LUMBERCAMP not in game.world.buildings)
|
|
game.play_until(lc_build_time)
|
|
self.assertTrue(Buildings.LUMBERCAMP in game.world.buildings)
|
|
|
|
|
|
def test_building_adds_gatherable(self):
|
|
lc_build_time = 35
|
|
|
|
game = Gameplay()
|
|
|
|
gatherable = game.world.gather.gatherable_amounts[Tasks.WOOD]
|
|
self.assertEqual(0, gatherable)
|
|
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.IDLE)
|
|
|
|
gatherable = game.world.gather.gatherable_amounts[Tasks.WOOD]
|
|
self.assertEqual(0, gatherable)
|
|
|
|
game.play_until(lc_build_time)
|
|
|
|
gatherable = game.world.gather.gatherable_amounts[Tasks.WOOD]
|
|
self.assertTrue(gatherable > 0)
|
|
|
|
|
|
def test_bad_build_villager_move(self):
|
|
game = Gameplay()
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.WOOD, Tasks.IDLE)
|
|
with self.assertRaises(IllegalVillagerMoveException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_bad_build_conservation_villagers(self):
|
|
game = Gameplay()
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.WOOD, [Tasks.IDLE]*2)
|
|
with self.assertRaises(ConservationOfVillagersException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_bad_build_resources(self):
|
|
game = Gameplay()
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.IDLE)
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.IDLE)
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.IDLE)
|
|
with self.assertRaises(NotEnoughResourcesException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_bad_build_age(self):
|
|
game = Gameplay()
|
|
game.build(0, Buildings.BLACKSMITH, Tasks.IDLE, Tasks.IDLE)
|
|
with self.assertRaises(MissingDependencyException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_bad_build_dependencies(self):
|
|
game = Gameplay()
|
|
game.build(0, Buildings.FARM, Tasks.IDLE, Tasks.IDLE)
|
|
with self.assertRaises(MissingDependencyException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_get_housed(self):
|
|
game = Gameplay()
|
|
game.queue_villager(0, Tasks.IDLE)
|
|
game.queue_villager(0, Tasks.IDLE)
|
|
game.play_until(20)
|
|
|
|
with self.assertRaises(YallGotHousedException):
|
|
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)
|
|
game.play_until(20)
|
|
self.assertResourcesMatch([200, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_gather_boar(self):
|
|
walking = 20
|
|
|
|
game = Gameplay()
|
|
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
|
|
game.assign_villager(walking, Tasks.IDLE, Tasks.BOAR, 2)
|
|
game.play_until(walking + 60)
|
|
|
|
boar_rate_times_60 = 24.6
|
|
gathered = boar_rate_times_60*3
|
|
|
|
self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_gather_boar_limited(self):
|
|
walking = 20
|
|
|
|
game = Gameplay()
|
|
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
|
|
game.assign_villager(walking, Tasks.IDLE, Tasks.BOAR, 2)
|
|
game.play_until(1000)
|
|
|
|
boar_total = 340
|
|
boar_per_60 = 24.6
|
|
boar_decay_per_60 = 0.4*60
|
|
boar_gone_time = boar_total/(boar_decay_per_60 + boar_per_60*3)
|
|
|
|
boar_eaten = boar_gone_time*boar_per_60*3
|
|
|
|
self.assertResourcesMatch([200 + boar_eaten, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_age_increase(self):
|
|
walking = 35 # to match mill and camp
|
|
|
|
game = Gameplay()
|
|
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
|
|
game.build(0, Buildings.MILL, Tasks.IDLE, Tasks.BOAR)
|
|
game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.BOAR)
|
|
game.lure_huntable_with_villager(walking, Tasks.BOAR, walking)
|
|
game.increase_age(300)
|
|
game.play_until(400)
|
|
self.assertEqual(Ages.DARK, game.world.age)
|
|
game.play_until(430)
|
|
self.assertEqual(Ages.FEUDAL, game.world.age)
|
|
|
|
|
|
def test_get_relic_no_monk(self):
|
|
game = Gameplay()
|
|
game.get_relic(0, walking_time=10)
|
|
game.play_until(10 + 500)
|
|
self.assertResourcesMatch([200, 200, 100, 200], game.world)
|
|
|
|
|
|
def test_monk_get_relic(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.CASTLE
|
|
game.world.resources = [1000, 1000, 1000, 1000]
|
|
game.world._add_building(Buildings.MONASTERY, {}, {})
|
|
|
|
game.queue_unit(0, Units.MONK)
|
|
|
|
current_time = 51
|
|
game.play_until(current_time)
|
|
initial_gold = game.world.gather.resources[2]
|
|
|
|
game.get_relic(current_time, walking_time=20)
|
|
|
|
current_time += 20
|
|
game.play_until(current_time + 60)
|
|
|
|
relic_gold_per_60 = 30
|
|
|
|
self.assertEqual(initial_gold + relic_gold_per_60,
|
|
game.world.gather.resources[2])
|
|
|
|
|
|
def test_ship_no_fishing(self):
|
|
game = Gameplay()
|
|
|
|
# just cheat
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
|
|
game.queue_fishing_ship(0, Tasks.FISH_SHIP_IDLE)
|
|
|
|
training = 40
|
|
|
|
game.play_until(training + 60)
|
|
self.assertResourcesMatch([500, 425, 500, 500], game.world)
|
|
|
|
|
|
def test_ship_deep_fishing(self):
|
|
game = Gameplay()
|
|
|
|
# just cheat
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
|
|
game.queue_fishing_ship(0)
|
|
|
|
training = 40
|
|
gathered = 29.4
|
|
|
|
game.play_until(training + 60)
|
|
self.assertResourcesMatch([500 + gathered, 425, 500, 500], game.world)
|
|
|
|
|
|
def test_trade_cog(self):
|
|
game = Gameplay()
|
|
|
|
# just cheat
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
|
|
game.queue_trade_cog(0)
|
|
|
|
training = 36
|
|
gathered = 25.9
|
|
|
|
game.play_until(training + 60)
|
|
self.assertResourcesMatch([500, 400, 450 + gathered, 500], game.world)
|
|
|
|
|
|
def test_trade_cart(self):
|
|
game = Gameplay()
|
|
|
|
# just cheat
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.MARKET, {}, {})
|
|
|
|
game.queue_trade_cart(0)
|
|
|
|
training = 51
|
|
gathered = 25.9
|
|
|
|
game.play_until(training + 60)
|
|
self.assertResourcesMatch([500, 400, 450 + gathered, 500], game.world)
|
|
|
|
|
|
def test_market_buy_without_market(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 1000, 500]
|
|
|
|
game.market_buy(0, Resources.FOOD, 100)
|
|
|
|
with self.assertRaises(MissingDependencyException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_market_buy(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 1000, 500]
|
|
game.world._add_building(Buildings.MARKET, {}, {})
|
|
|
|
food_rate = 115
|
|
wood_rate = 100
|
|
new_gold = game.world.gather.resources[2]
|
|
fee = 0.3
|
|
inc = 2
|
|
|
|
game.market_buy(0, Resources.FOOD, 100)
|
|
new_gold -= food_rate*(1 + fee)
|
|
food_rate += 2
|
|
game.play_until(1)
|
|
self.assertResourcesMatch([600, 500, new_gold, 500], game.world)
|
|
|
|
game.market_buy(5, Resources.FOOD, 100)
|
|
new_gold -= food_rate*(1 + fee)
|
|
food_rate += 2
|
|
game.play_until(6)
|
|
self.assertResourcesMatch([700, 500, new_gold, 500], game.world)
|
|
|
|
game.market_buy(7, Resources.FOOD, 300)
|
|
for i in range(3):
|
|
new_gold -= food_rate*(1 + fee)
|
|
food_rate += 2
|
|
game.play_until(8)
|
|
self.assertResourcesMatch([1000, 500, new_gold, 500], game.world)
|
|
|
|
game.market_buy(9, Resources.WOOD, 100)
|
|
new_gold -= wood_rate*(1 + fee)
|
|
wood_rate += 2
|
|
game.play_until(10)
|
|
self.assertResourcesMatch([1000, 600, new_gold, 500], game.world)
|
|
|
|
|
|
def test_market_sell(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 1000, 500]
|
|
game.world._add_building(Buildings.MARKET, {}, {})
|
|
|
|
food_rate = 115
|
|
wood_rate = 100
|
|
new_gold = game.world.gather.resources[2]
|
|
fee = 0.3
|
|
inc = 2
|
|
|
|
game.market_sell(0, Resources.FOOD, 100)
|
|
new_gold += food_rate*(1 - fee)
|
|
food_rate -= 2
|
|
game.play_until(1)
|
|
self.assertResourcesMatch([400, 500, new_gold, 500], game.world)
|
|
|
|
game.market_sell(5, Resources.FOOD, 100)
|
|
new_gold += food_rate*(1 - fee)
|
|
food_rate -= 2
|
|
game.play_until(6)
|
|
self.assertResourcesMatch([300, 500, new_gold, 500], game.world)
|
|
|
|
game.market_sell(7, Resources.FOOD, 300)
|
|
for i in range(3):
|
|
new_gold += food_rate*(1 - fee)
|
|
food_rate -= 2
|
|
game.play_until(8)
|
|
self.assertResourcesMatch([0, 500, new_gold, 500], game.world)
|
|
|
|
game.market_sell(9, Resources.WOOD, 100)
|
|
new_gold += wood_rate*(1 - fee)
|
|
wood_rate -= 2
|
|
game.play_until(10)
|
|
self.assertResourcesMatch([0, 400, new_gold, 500], game.world)
|
|
|
|
|
|
def test_market_buy_too_much(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 1000, 500]
|
|
game.world._add_building(Buildings.MARKET, {}, {})
|
|
|
|
with self.assertRaises(NotEnoughResourcesException):
|
|
game.market_buy(0, Resources.FOOD, 1000)
|
|
game.play_until(1)
|
|
|
|
|
|
def test_market_sell_too_much(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 1000, 500]
|
|
game.world._add_building(Buildings.MARKET, {}, {})
|
|
|
|
with self.assertRaises(NotEnoughResourcesException):
|
|
game.market_sell(0, Resources.FOOD, 1000)
|
|
game.play_until(1)
|
|
|
|
|
|
def test_market_sell_bad_amount(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 1000, 500]
|
|
game.world._add_building(Buildings.MARKET, {}, {})
|
|
|
|
with self.assertRaises(InvalidMarketAmountException):
|
|
game.market_sell(0, Resources.FOOD, 50)
|
|
game.play_until(1)
|
|
|
|
|
|
def test_farm_simple(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.DARK
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.MILL, {}, {})
|
|
game.world._add_building(Buildings.FARM, {}, {})
|
|
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
|
|
|
rate_per_60 = 20
|
|
|
|
game.play_until(60)
|
|
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
|
|
|
|
|
def test_farm_build(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.DARK
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.MILL, {}, {})
|
|
|
|
game.build(0, Buildings.FARM, Tasks.IDLE, Tasks.IDLE)
|
|
game.assign_villager(30, Tasks.IDLE, Tasks.FARM)
|
|
|
|
rate_per_60 = 20
|
|
|
|
game.play_until(90)
|
|
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 440, 500, 500], game.world)
|
|
|
|
|
|
def test_farm_depleted(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.DARK
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.MILL, {}, {})
|
|
game.world._add_building(Buildings.FARM, {}, {})
|
|
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
|
|
|
amount_per_farm = 175
|
|
|
|
game.play_until(1000)
|
|
|
|
new_food = 500 + amount_per_farm
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
|
|
|
farms = game.world.gather.consumable_buildings[Tasks.FARM]
|
|
self.assertEqual(0, len(farms['used']))
|
|
self.assertEqual(0, len(farms['unused']))
|
|
|
|
|
|
def test_farm_too_many_farmers(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.DARK
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.MILL, {}, {})
|
|
game.world._add_building(Buildings.FARM, {}, {})
|
|
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
|
|
|
with self.assertRaises(GatherBuildingNotAvailableException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_farm_off_and_on(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.DARK
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.MILL, {}, {})
|
|
game.world._add_building(Buildings.FARM, {}, {})
|
|
|
|
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
|
game.assign_villager(30, Tasks.FARM, Tasks.IDLE)
|
|
game.assign_villager(60, Tasks.IDLE, Tasks.FARM)
|
|
|
|
rate_per_60 = 20
|
|
|
|
game.play_until(90)
|
|
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
|
|
|
|
|
def test_fishing_ship(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.DARK
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
|
|
game.queue_fishing_ship(0)
|
|
|
|
rate_per_60 = 29.4
|
|
ship_training = 40
|
|
|
|
game.play_until(ship_training - 1)
|
|
self.assertResourcesMatch([500, 425, 500, 500], game.world)
|
|
|
|
game.play_until(ship_training + 60)
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 425, 500, 500], game.world)
|
|
|
|
|
|
def test_fishtrap_simple(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
|
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_TRAP)
|
|
|
|
rate_per_60 = 21
|
|
|
|
game.play_until(60)
|
|
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
|
|
|
|
|
def test_fishtrap_build(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
|
|
|
game.build(0,
|
|
Buildings.FISHTRAP,
|
|
Tasks.FISH_SHIP_IDLE,
|
|
Tasks.FISH_SHIP_IDLE)
|
|
|
|
game.play_until(10)
|
|
|
|
game.assign_villager(50, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
|
|
|
rate_per_60 = 21
|
|
|
|
game.play_until(110)
|
|
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 400, 500, 500], game.world)
|
|
|
|
|
|
def test_fishtrap_depleted(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
|
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
|
|
|
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
|
|
|
amount_per_fishtrap = 715
|
|
rate_per_60 = 21
|
|
duration = (amount_per_fishtrap/rate_per_60)*60 + 1
|
|
|
|
game.play_until(duration)
|
|
|
|
new_food = 500 + amount_per_fishtrap
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
|
|
|
traps = game.world.gather.consumable_buildings[Tasks.FISH_SHIP_TRAP]
|
|
self.assertEqual(0, len(traps['used']))
|
|
self.assertEqual(0, len(traps['unused']))
|
|
|
|
# fishing ships go back to fishing after trap is depleted
|
|
deep_rate_per_60 = 29.4
|
|
game.play_until(duration + 60)
|
|
new_food += deep_rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
|
|
|
|
|
def test_fishtrap_too_many_fish_ships(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
|
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
|
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
|
|
|
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
|
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
|
|
|
with self.assertRaises(GatherBuildingNotAvailableException):
|
|
game.play_until(1)
|
|
|
|
|
|
def test_fishtrap_off_and_on(self):
|
|
game = Gameplay()
|
|
|
|
game.world.age = Ages.FEUDAL
|
|
game.world.gather.resources = [500, 500, 500, 500]
|
|
game.world._add_building(Buildings.DOCK, {}, {})
|
|
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
|
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
|
|
|
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
|
game.assign_villager(30, Tasks.FISH_SHIP_TRAP, Tasks.FISH_SHIP_IDLE)
|
|
game.assign_villager(60, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
|
|
|
rate_per_60 = 21
|
|
|
|
game.play_until(90)
|
|
|
|
new_food = 500 + rate_per_60
|
|
|
|
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|