Upgrading a list of units requires far more cores than it should

I’m using python. If I call game_state.attempt_upgrade() on a list of units, it won’t upgrade all of them even if I have the cores to do so. I suspect it’s counting the cost of upgrading my already upgraded units, and not upgrading further units even though I am not charged for the already upgraded units.

You are correct,
It does not seem to have check if the unit is already upgraded, and just creates an upgrade command, and reduce the cores.
This will trigger notice when you run the match locally “location already upgraded” or something.

Can some one suggest a patch ? :slight_smile:

This is the code in question:
https://github.com/correlation-one/C1GamesStarterKit/blob/master/python-algo/gamelib/game_state.py#L413

attempt_upgrade
def attempt_upgrade(self, locations):
    if type(locations[0]) == int:
        locations = [locations]
    spawned_units = 0
    for location in locations:
        if location[1] < self.HALF_ARENA and self.contains_stationary_unit(location):
            x, y = map(int, location)
            existing_unit = None
            for unit in self.game_map[x,y]:
                if unit.stationary:
                    existing_unit = unit

            if not existing_unit.upgraded and self.config["unitInformation"][UNIT_TYPE_TO_INDEX[existing_unit.unit_type]].get("upgrade", None) is not None:
                costs = self.type_cost(existing_unit.unit_type, True)
                resources = self.get_resources()
                if resources[CORES] >= costs[CORES] and resources[BITS] >= costs[BITS]:
                    self.__set_resource(CORES, 0 - costs[CORES])
                    self.__set_resource(BITS, 0 - costs[BITS])
                    existing_unit.upgrade()
                    self._build_stack.append((UPGRADE, x, y))
                    spawned_units += 1
        else:
            self.warn("Could not upgrade a unit from {}. Location has no firewall or is enemy territory.".format(location))
    return spawned_units

EDIT:
actually, now looking at the code in GIT, there IS a check if the unit is upgraded

https://github.com/correlation-one/C1GamesStarterKit/blob/master/python-algo/gamelib/game_state.py#L435

if not existing_unit.upgraded and ...

but this seems to be recent update … as I don’t have in my local version

2 Likes