def test_per_turn(self): # tbc civ = Civilisation("myCiv", grid, logger) hextile = Hex(0, 0, 0) worker = Worker("worker", 1, hextile, "myCiv") civ.units[worker.id] = worker archer = Archer(1, 1, hextile, "myCiv") civ.units[archer.id] = archer civ.reset_unit_actions_and_movement() grid.create_grid() civ.build_city_on_tile(worker, 1) hextile2 = grid.get_neighbour_in_direction(hextile, 2) worker.position = hextile2 civ.build_structure(worker, BuildingType.UNIVERSITY, 1) civ.reset_unit_actions_and_movement() hextile3 = grid.get_neighbour_in_direction(hextile, 4) worker.position = hextile3 civ.build_structure(worker, BuildingType.FARM, 2) civ.reset_unit_actions_and_movement() civ.currency_per_turn() self.assertEqual(archer.actions, 2) self.assertEqual(worker.actions, 2) self.assertEqual(archer.movement, 5) self.assertEqual(worker.movement, 4) self.assertEqual(civ.food, 99) self.assertEqual(civ.gold, 51) self.assertEqual(civ.science, 5)
def test_calculate_vision(self): civ = Civilisation("myCiv", grid, logger) hextile = Hex(0, 0, 0) worker = Worker("worker", 1, hextile, "myCiv") worker.actions = 2 civ.units[worker.id] = worker grid.create_grid() civ.build_city_on_tile(worker, 1) hextile2 = grid.get_neighbour_in_direction(hextile, 2) worker.position = hextile2 civ.build_structure(worker, BuildingType.UNIVERSITY, 1) civ.calculate_vision() self.assertEqual(len(civ._vision), 44)
def test_currency_of_buildings(self): civ = Civilisation("myCiv", grid, logger) hextile = Hex(0, 0, 0) worker = Worker("worker", 1, hextile, "myCiv") worker.actions = 5 civ.units[worker.id] = worker grid.create_grid() civ.build_city_on_tile(worker, 1) hextile2 = grid.get_neighbour_in_direction(hextile, 2) worker.position = hextile2 civ.build_structure(worker, BuildingType.UNIVERSITY, 1) hextile3 = grid.get_neighbour_in_direction(hextile, 4) worker.position = hextile3 civ.build_structure(worker, BuildingType.FARM, 2) curr = civ.currency_of_buildings() self.assertEqual(curr["food"], 2) self.assertEqual(curr["gold"], -4) self.assertEqual(curr["science"], 5)
def test_build_structure(self): """Test the build_structure function.""" grid.create_grid() hextile = Hex(0, 0, 0) civ = Civilisation("myCiv", grid, logger) worker = Worker("worker", 1, hextile, "myCiv") worker.actions = 2 grid.create_grid() gold = civ.gold actions = worker.actions civ.build_city_on_tile(worker, 1) hextile2 = grid.get_neighbour_in_direction(hextile, 2) worker.position = hextile2 civ.build_structure(worker, BuildingType.UNIVERSITY, 1) building = civ.cities[hextile.city_id].buildings[1] # a city had to be built before the university so both costs # must be deducted from the total gold and actions self.assertEqual(civ.gold, gold - 35) self.assertEqual(worker.actions, actions - 2) self.assertEqual(worker.position.building, building)