Esempio n. 1
0
    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)
Esempio n. 2
0
    def test_buy_unit(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)
        city = civ.cities[1]
        unit = civ.buy_unit(city, Archer, 1, 1)

        self.assertEqual(civ.units[1], unit)
        self.assertEqual(civ.gold, 65)
Esempio n. 3
0
    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)
Esempio n. 4
0
    def test_build_city_on_tile(self):
        """Test the build_city_on_tile function."""
        hextile = Hex(0, 0, 0)
        civ = Civilisation("myCiv", grid, logger)
        worker = Worker("worker", 1, hextile, 1)
        worker.actions = 2

        grid.create_grid()

        gold = civ.gold
        actions = worker.actions

        civ.build_city_on_tile(worker, 1)

        city = civ.cities[1]

        self.assertEqual(civ.gold, gold - 25)
        self.assertEqual(worker.actions, actions - 1)
        self.assertEqual(civ.cities[1], city)
        self.assertEqual(civ.tiles[worker.position], civ._id)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)