Пример #1
0
def find_adjust_energy(game):
    plans = []
    ENERGY_CHANGE_COST = 150
    THRESHOLD = 0.001

    def urgency(residence):
        if ENERGY.urgent(residence.temperature):
            return Urgency.MAJOR_ADJUST_ENERGY
        return Urgency.MINOR_ADJUST_ENERGY

    def change(residence, energy):
        return abs(energy - residence.requested_energy_in)

    def score(residence, energy):
        return change(residence, energy) * residence.current_pop

    for residence, energy in recommend_energy_adjustments(game):
        if change(residence, energy) > THRESHOLD:
            plan = Plan(urgency(residence), score(residence, energy))
            if game.game_state.funds < ENERGY_CHANGE_COST:
                plan.wait()
            else:
                plan.adjust_energy((residence.X, residence.Y), energy)
            plans.append(plan)
    return plans
Пример #2
0
def find_construction(game):
    state = game.game_state
    plans = []
    # new construction?
    available = available_buildings(state)
    vacancies = sum([
        game.get_blueprint(residence.building_name).max_pop -
        residence.current_pop for residence in state.residences
    ])
    bad_time = state.housing_queue < SETTINGS.BUILDING.REQ_MIN_HOUSING_QUEUE or vacancies > SETTINGS.BUILDING.REQ_MAX_VACANCIES
    priority = 1
    for entry in memory['planned_buildings']:
        position, building_name = entry
        if building_name not in available:
            continue
        bp = game.get_blueprint(building_name)
        score = SETTINGS.BUILDING.PRIORITY_VALUE - 0.01 * priority
        priority += 1
        plan = Plan(Urgency.CONSTRUCTION, score)
        if bad_time:
            pass
        elif state.funds < bp.cost:
            plans.append(plan.wait())
        else:
            plans.append(
                plan.construction(position, building_name).forget_entry(
                    memory, 'planned_buildings', entry))
    return plans
Пример #3
0
def find_upgrades(game):
    state = game.game_state
    plans = []
    COST = {  # todo get
        'Caretaker': 3500,
        'SolarPanel': 6800,
        'Insulation': 7200,
        'Playground': 5200,
        'Charger': 3400,
        'Regulator': 1250
    }
    for residence in state.residences:
        if residence.building_name in SETTINGS.UPGRADE.PRIORITY:
            for priority, upgrade_name in enumerate(
                    SETTINGS.UPGRADE.PRIORITY[residence.building_name]):
                if upgrade_name not in residence.effects:
                    if upgrade_name == 'Charger' and SETTINGS.UPGRADE.CHARGER_ONLY_ON_MALL and 'Mall.2' not in residence.effects:
                        continue
                    score = 10.0 - priority
                    plan = Plan(Urgency.UPGRADE, score)
                    if state.funds >= SETTINGS.UPGRADE.FUNDS_THRESHOLD and state.funds >= COST[
                            upgrade_name]:  # never will happen with high threshold
                        plans.append(
                            plan.upgrade((residence.X, residence.Y),
                                         upgrade_name).remember_count(
                                             memory, 'upgrade', upgrade_name))
                    elif SETTINGS.UPGRADE.WAIT_FOR_UPGRADE:
                        plans.append(plan.wait())
    return plans
Пример #4
0
 def find(priorities, urgency):
     if residence.building_name in priorities:
         for priority, upgrade_name in enumerate(
                 priorities[residence.building_name]):
             if upgrade_name not in residence.effects:
                 if upgrade_name in SETTINGS.UPGRADE.DELAY and state.turn < SETTINGS.UPGRADE.DELAY[
                         upgrade_name]:
                     continue
                 score = SCORE_BASE - priority
                 plan = Plan(urgency, score)
                 if upgrade_name == 'Regulator' and residence.temperature > SETTINGS.UPGRADE.REGULATOR_TEMP:
                     plan.urgency = Urgency.MAJOR_ADJUST_ENERGY
                     plan.score = SCORE_BASE + residence.temperature
                 elif upgrade_name == 'Charger' and SETTINGS.UPGRADE.CHARGER_PRIO_ON_MALL and 'Mall.2' in residence.effects:
                     plan.urgency = Urgency.MAJOR_UPGRADE
                     plan.score = SCORE_BASE + residence.current_pop
                 if state.funds >= COST[upgrade_name] and (
                         state.funds >= SETTINGS.UPGRADE.FUNDS_THRESHOLD
                         or len(memory['planned_buildings']) == 0):
                     plans.append(
                         plan.upgrade((residence.X, residence.Y),
                                      upgrade_name).remember_count(
                                          memory, 'upgrade', upgrade_name))
                 elif SETTINGS.UPGRADE.SAVE_FOR_UPGRADE:
                     plans.append(plan.wait())