Beispiel #1
0
def calculateResearchPriority():
    """calculates the AI empire's demand for research"""
    universe = fo.getUniverse()
    empire = fo.getEmpire()
    empireID = empire.empireID
    current_turn = fo.currentTurn()
    enemies_sighted = foAI.foAIstate.misc.get('enemies_sighted', {})
    recent_enemies = [x for x in enemies_sighted if x > current_turn - 8]

    industryPriority = foAI.foAIstate.get_priority(
        EnumsAI.AIPriorityType.PRIORITY_RESOURCE_PRODUCTION)

    gotAlgo = tech_is_complete(AIDependencies.LRN_ALGO_ELEGANCE)
    got_quant = tech_is_complete(AIDependencies.LRN_QUANT_NET)
    researchQueueList = ResearchAI.get_research_queue_techs()
    orb_gen_tech = AIDependencies.PRO_ORBITAL_GEN
    got_orb_gen = tech_is_complete(orb_gen_tech)
    mgrav_prod_tech = AIDependencies.PRO_MICROGRAV_MAN
    got_mgrav_prod = tech_is_complete(mgrav_prod_tech)
    got_solar_gen = tech_is_complete(AIDependencies.PRO_SOL_ORB_GEN)

    milestone_techs = [
        "PRO_SENTIENT_AUTOMATION", "LRN_DISTRIB_THOUGHT", "LRN_QUANT_NET",
        "SHP_WEAPON_2_4", "SHP_WEAPON_3_2", "SHP_WEAPON_4_2"
    ]
    milestones_done = [
        mstone for mstone in milestone_techs if tech_is_complete(mstone)
    ]
    print "Research Milestones accomplished at turn %d: %s" % (current_turn,
                                                               milestones_done)

    totalPP = empire.productionPoints
    totalRP = empire.resourceProduction(fo.resourceType.research)
    industrySurge = (
        (foAI.foAIstate.aggression > fo.aggression.cautious)
        and ((totalPP + 1.6 * totalRP) < (50 * foAI.foAIstate.aggression))
        and (((orb_gen_tech in researchQueueList[:2] or got_orb_gen)
              and ColonisationAI.have_gas_giant()) or
             ((mgrav_prod_tech in researchQueueList[:2] or got_mgrav_prod)
              and ColonisationAI.have_asteroids()))
        and (not (len(AIstate.popCtrIDs) >= 12)))
    # get current industry production & Target
    ownedPlanetIDs = PlanetUtilsAI.get_owned_planets_by_empire(
        universe.planetIDs)
    planets = map(universe.getPlanet, ownedPlanetIDs)
    targetRP = sum(
        map(lambda x: x.currentMeterValue(fo.meterType.targetResearch),
            planets))
    galaxy_is_sparse = ColonisationAI.galaxy_is_sparse()
    enemies_sighted = foAI.foAIstate.misc.get('enemies_sighted', {})

    styleIndex = empireID % 2
    if foAI.foAIstate.aggression >= fo.aggression.maniacal:
        styleIndex += 1

    cutoffSets = [[25, 45, 70, 110], [30, 45, 70, 150], [25, 40, 80, 160]]
    cutoffs = cutoffSets[styleIndex]
    settings = [[1.3, .7, .5, .4, .35], [1.4, 0.8, 0.6, 0.5, 0.35],
                [1.4, 0.8, 0.6, 0.5, 0.4]][styleIndex]

    if (current_turn < cutoffs[0]) or (not gotAlgo) or (
        (styleIndex == 0) and not got_orb_gen and (current_turn < cutoffs[1])):
        researchPriority = settings[
            0] * industryPriority  # high research at beginning of game to get easy gro tech and to get research booster Algotrithmic Elegance
    elif (not got_orb_gen) or (current_turn < cutoffs[1]):
        researchPriority = settings[1] * industryPriority  # med-high research
    elif current_turn < cutoffs[2]:
        researchPriority = settings[2] * industryPriority  # med-high industry
    elif current_turn < cutoffs[3]:
        researchPriority = settings[3] * industryPriority  # med-high industry
    else:
        researchQueue = list(empire.researchQueue)
        researchPriority = settings[
            4] * industryPriority  # high industry , low research
        if len(researchQueue) == 0:
            researchPriority = 0  # done with research
        elif len(researchQueue) < 5 and researchQueue[-1].allocation > 0:
            researchPriority = len(
                researchQueue
            ) * 0.01 * industryPriority  # barely not done with research
        elif len(researchQueue) < 10 and researchQueue[-1].allocation > 0:
            researchPriority = (
                4 + 2 * len(researchQueue)
            ) * 0.01 * industryPriority  # almost done with research
        elif len(researchQueue) < 20 and researchQueue[int(
                len(researchQueue) / 2)].allocation > 0:
            researchPriority *= 0.7  # closing in on end of research
    if industrySurge:
        if galaxy_is_sparse and not any(enemies_sighted):
            researchPriority *= 0.5
        else:
            researchPriority *= 0.8

    if ((tech_is_complete("SHP_WEAPON_2_4")
         or tech_is_complete("SHP_WEAPON_4_1"))
            and tech_is_complete(AIDependencies.PROD_AUTO_NAME)):
        #industry_factor = [ [0.25, 0.2], [0.3, 0.25], [0.3, 0.25] ][styleIndex ]
        #researchPriority = min(researchPriority, industry_factor[got_solar_gen]*industryPriority)
        researchPriority *= 0.9
    if got_quant:
        researchPriority = min(researchPriority + 0.1 * industryPriority,
                               researchPriority * 1.3)
    researchPriority = int(researchPriority)
    print ""
    print "Research Production (current/target) : ( %.1f / %.1f )" % (totalRP,
                                                                      targetRP)
    print "Priority for Research: %d (new target ~ %d RP)" % (
        researchPriority, totalPP * researchPriority / industryPriority)

    if len(enemies_sighted) < (
            2 + current_turn / 20.0):  #TODO: adjust for colonisation priority
        researchPriority *= 1.2
    if (current_turn > 20) and (len(recent_enemies) > 3):
        researchPriority *= 0.8
    return researchPriority
Beispiel #2
0
def _calculate_research_priority():
    """Calculates the AI empire's demand for research."""
    universe = fo.getUniverse()
    empire = fo.getEmpire()
    empire_id = empire.empireID
    current_turn = fo.currentTurn()
    enemies_sighted = foAI.foAIstate.misc.get('enemies_sighted', {})
    recent_enemies = [x for x in enemies_sighted if x > current_turn - 8]

    industry_priority = foAI.foAIstate.get_priority(PriorityType.RESOURCE_PRODUCTION)

    got_algo = tech_is_complete(AIDependencies.LRN_ALGO_ELEGANCE)
    got_quant = tech_is_complete(AIDependencies.LRN_QUANT_NET)
    research_queue_list = ResearchAI.get_research_queue_techs()
    orb_gen_tech = AIDependencies.PRO_ORBITAL_GEN
    got_orb_gen = tech_is_complete(orb_gen_tech)
    mgrav_prod_tech = AIDependencies.PRO_MICROGRAV_MAN
    got_mgrav_prod = tech_is_complete(mgrav_prod_tech)
    # got_solar_gen = tech_is_complete(AIDependencies.PRO_SOL_ORB_GEN)
    
    milestone_techs = ["PRO_SENTIENT_AUTOMATION", "LRN_DISTRIB_THOUGHT", "LRN_QUANT_NET", "SHP_WEAPON_2_4", "SHP_WEAPON_3_2", "SHP_WEAPON_4_2"]
    milestones_done = [mstone for mstone in milestone_techs if tech_is_complete(mstone)]
    print "Research Milestones accomplished at turn %d: %s" % (current_turn, milestones_done)

    total_pp = empire.productionPoints
    total_rp = empire.resourceProduction(fo.resourceType.research)
    industry_surge = ((foAI.foAIstate.aggression > fo.aggression.cautious) and
                     ((total_pp + 1.6 * total_rp) < (50 * foAI.foAIstate.aggression)) and
                     (((orb_gen_tech in research_queue_list[:2] or got_orb_gen) and ColonisationAI.have_gas_giant()) or
                      ((mgrav_prod_tech in research_queue_list[:2] or got_mgrav_prod) and ColonisationAI.have_asteroids())) and
                     (not (len(AIstate.popCtrIDs) >= 12)))
    # get current industry production & Target
    owned_planet_ids = PlanetUtilsAI.get_owned_planets_by_empire(universe.planetIDs)
    planets = map(universe.getPlanet, owned_planet_ids)
    target_rp = sum(map(lambda x: x.currentMeterValue(fo.meterType.targetResearch), planets))
    galaxy_is_sparse = ColonisationAI.galaxy_is_sparse()
    enemies_sighted = foAI.foAIstate.misc.get('enemies_sighted', {})

    style_index = empire_id % 2
    if foAI.foAIstate.aggression >= fo.aggression.maniacal:
        style_index += 1

    cutoff_sets = [[25, 45, 70, 110], [30, 45, 70, 150], [25, 40, 80, 160]]
    cutoffs = cutoff_sets[style_index]
    settings = [[1.3, .7, .5, .4, .35], [1.4, 0.8, 0.6, 0.5, 0.35], [1.4, 0.8, 0.6, 0.5, 0.4]][style_index]

    if (current_turn < cutoffs[0]) or (not got_algo) or ((style_index == 0) and not got_orb_gen and (current_turn < cutoffs[1])):
        research_priority = settings[0] * industry_priority  # high research at beginning of game to get easy gro tech and to get research booster Algotrithmic Elegance
    elif (not got_orb_gen) or (current_turn < cutoffs[1]):
        research_priority = settings[1] * industry_priority  # med-high research
    elif current_turn < cutoffs[2]:
        research_priority = settings[2] * industry_priority  # med-high industry
    elif current_turn < cutoffs[3]:
        research_priority = settings[3] * industry_priority  # med-high industry
    else:
        research_queue = list(empire.researchQueue)
        research_priority = settings[4] * industry_priority  # high industry , low research
        if len(research_queue) == 0:
            research_priority = 0  # done with research
        elif len(research_queue) < 5 and research_queue[-1].allocation > 0:
            research_priority = len(research_queue) * 0.01 * industry_priority  # barely not done with research
        elif len(research_queue) < 10 and research_queue[-1].allocation > 0:
            research_priority = (4 + 2 * len(research_queue)) * 0.01 * industry_priority  # almost done with research
        elif len(research_queue) < 20 and research_queue[int(len(research_queue) / 2)].allocation > 0:
            research_priority *= 0.7  # closing in on end of research
    if industry_surge:
        if galaxy_is_sparse and not any(enemies_sighted):
            research_priority *= 0.5
        else:
            research_priority *= 0.8
                
    if ((tech_is_complete("SHP_WEAPON_2_4") or
         tech_is_complete("SHP_WEAPON_4_1")) and
            tech_is_complete(AIDependencies.PROD_AUTO_NAME)):
        # industry_factor = [ [0.25, 0.2], [0.3, 0.25], [0.3, 0.25] ][styleIndex ]
        # researchPriority = min(researchPriority, industry_factor[got_solar_gen]*industryPriority)
        research_priority *= 0.9
    if got_quant:
        research_priority = min(research_priority + 0.1 * industry_priority, research_priority * 1.3)
    research_priority = int(research_priority)
    print ""
    print "Research Production (current/target) : ( %.1f / %.1f )" % (total_rp, target_rp)
    print "Priority for Research: %d (new target ~ %d RP)" % (research_priority, total_pp * research_priority / industry_priority)

    if len(enemies_sighted) < (2 + current_turn/20.0):  # TODO: adjust for colonisation priority
        research_priority *= 1.2
    if (current_turn > 20) and (len(recent_enemies) > 3):
        research_priority *= 0.8
    return research_priority