コード例 #1
0
        private Tech AIBaseSelectNextTech(
            StrategicAI ai,
            List <PlayerTechInfo> desiredTech      = null,
            Dictionary <string, int> familyWeights = null)
        {
            Tech tech            = (((Tech)null ?? this.AISelectPartialTech(ai)) ?? AIResearchFramework.AISelectBinaryResponseTech(ai)) ?? this.AISelectDefaultTech(ai, desiredTech, familyWeights);
            Tech researchingTech = AIResearchFramework.AIGetResearchingTech(ai);

            if (tech != null && tech != researchingTech)
            {
                if (this._log != null)
                {
                    if (researchingTech != null)
                    {
                        this._log.Print(string.Format("\n          >>> {0} (replacing {1})\n", (object)tech.Id, (object)researchingTech.Id));
                    }
                    else
                    {
                        this._log.Print(string.Format("\n          >>> {0}\n", (object)tech.Id));
                    }
                }
                return(tech);
            }
            if (this._log != null)
            {
                this._log.ClearRecord();
            }
            return((Tech)null);
        }
コード例 #2
0
        private bool AIHaveReplacementForTech(StrategicAI ai, Tech tech)
        {
            bool flag = false;

            foreach (AIResearchFramework.AITechReplacementRow replacement in this._replacements)
            {
                if (tech == replacement.Old)
                {
                    PlayerTechInfo playerTechInfo = AIResearchFramework.AIGetPlayerTechInfo(ai, replacement.New);
                    if (playerTechInfo != null)
                    {
                        switch (replacement.Contexts)
                        {
                        case AIResearchFramework.AITechReplacementContexts.Available:
                            flag = AIResearchFramework.AIIsTechAvailable(playerTechInfo.State) || AIResearchFramework.AIHaveTech(playerTechInfo.State);
                            break;

                        case AIResearchFramework.AITechReplacementContexts.Researched:
                            flag = AIResearchFramework.AIHaveTech(playerTechInfo.State);
                            break;
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                }
            }
            return(flag);
        }
コード例 #3
0
 private IEnumerable <AIResearchFramework.TechBeat> AIGetTechBeats(
     IEnumerable <Tech> techs,
     List <AIResearchModes> rhythm,
     List <PlayerTechInfo> desiredTech = null)
 {
     foreach (Tech tech1 in techs)
     {
         Tech tech = tech1;
         for (int beat = 0; beat < rhythm.Count; ++beat)
         {
             if (AIResearchFramework.AIContainsTech(new AIResearchModes?(rhythm[beat]), new TechFamilies?(), tech))
             {
                 if (desiredTech != null)
                 {
                     desiredTech.Any <PlayerTechInfo>((Func <PlayerTechInfo, bool>)(x => x.TechFileID == tech.Id));
                 }
                 yield return(new AIResearchFramework.TechBeat()
                 {
                     Tech = tech,
                     Beat = beat
                 });
             }
         }
     }
 }
コード例 #4
0
        private Tech AISelectPartialTech(StrategicAI ai)
        {
            Tech tech1 = (Tech)null;

            if (AIResearchFramework.AIGetResearchingTech(ai) == null)
            {
                List <Tech> techList = AIResearchFramework.AISelectAvailableTechs(ai, new AIResearchModes?(), new TechFamilies?());
                if (techList.Count > 0)
                {
                    int num = 0;
                    foreach (Tech tech2 in techList)
                    {
                        int techProgress = AIResearchFramework.AIGetTechProgress(ai, tech2);
                        if (techProgress > num)
                        {
                            num   = techProgress;
                            tech1 = tech2;
                        }
                    }
                }
            }
            if (this._log != null && tech1 != null)
            {
                this._log.Print(string.Format("Resuming {0}", (object)tech1.Id));
            }
            return(tech1);
        }
コード例 #5
0
        private List <AIResearchFramework.TechBeat> AIGetCulledProspects(
            StrategicAI ai,
            IEnumerable <AIResearchFramework.TechBeat> sorted)
        {
            int    num1 = 0;
            double num2 = 0.0;
            List <AIResearchFramework.TechBeat> techBeatList = new List <AIResearchFramework.TechBeat>();

            foreach (AIResearchFramework.TechBeat techBeat in sorted)
            {
                techBeatList.Add(techBeat);
                if (num1 == 0)
                {
                    techBeatList.Add(techBeat);
                    techBeatList.Add(techBeat);
                    num2 = (double)AIResearchFramework.AICalcTechCost(ai, techBeat.Tech);
                }
                if ((double)AIResearchFramework.AICalcTechCost(ai, techBeat.Tech) == num2)
                {
                    ++num1;
                }
                else
                {
                    break;
                }
            }
            return(techBeatList);
        }
コード例 #6
0
        private static Tech AISelectFavoriteTech(StrategicAI ai, IList <Tech> techs)
        {
            if (techs.Count == 0)
            {
                return((Tech)null);
            }
            List <Tech> techList = new List <Tech>();
            int         num      = AIResearchFramework.AICalcTechCost(ai, techs[0]);

            foreach (Tech tech in (IEnumerable <Tech>)techs)
            {
                if (num == AIResearchFramework.AICalcTechCost(ai, tech))
                {
                    techList.Add(tech);
                }
                else
                {
                    if (AIResearchFramework.AIGetTurnsToComplete(ai, tech) <= 15)
                    {
                        techList.Add(tech);
                        break;
                    }
                    break;
                }
            }
            return(techList[ai.Random.Next(techList.Count)]);
        }
コード例 #7
0
        private static Tech AISelectBinaryResponseTech(StrategicAI ai)
        {
            Tech tech = (Tech)null;

            AIResearchFramework.AICanSelectBinaryResponseTech(ai);
            return(tech);
        }
コード例 #8
0
 private static double AICalcTechStyleCost(StrategicAI ai, AITechStyleInfo style, Tech tech)
 {
     if (AIResearchFramework.AITechStyleContains(ai, style, tech))
     {
         return((double)style.CostFactor);
     }
     return(1.0);
 }
コード例 #9
0
        private static bool AICanSelectBinaryResponseTech(StrategicAI ai)
        {
            Tech researchingTech = AIResearchFramework.AIGetResearchingTech(ai);

            if (researchingTech != null)
            {
                return(AIResearchFramework.AIGetTurnsToComplete(ai, researchingTech) > 5);
            }
            return(true);
        }
コード例 #10
0
        private static int AIGetTechProgress(StrategicAI ai, Tech tech)
        {
            PlayerTechInfo playerTechInfo = AIResearchFramework.AIGetPlayerTechInfo(ai, tech);

            if (playerTechInfo == null)
            {
                return(0);
            }
            return(playerTechInfo.Progress);
        }
コード例 #11
0
        private static double AICalcCombinedTechStyleCost(StrategicAI ai, Tech tech)
        {
            double num = 1.0;

            foreach (AITechStyleInfo techStyleInfo in ai.TechStyles.TechStyleInfos)
            {
                num *= AIResearchFramework.AICalcTechStyleCost(ai, techStyleInfo, tech);
            }
            return(num);
        }
コード例 #12
0
 private void LogProspects(
     StrategicAI ai,
     IList <AIResearchModes> phasedRhythm,
     IEnumerable <AIResearchFramework.TechBeat> prospects)
 {
     if (this._log == null)
     {
         return;
     }
     foreach (AIResearchFramework.TechBeat prospect in prospects)
     {
         this._log.Print(string.Format("{0}/{1} ({2}{3}); ", (object)AIResearchFramework.AIGetResearchModeSymbol(phasedRhythm[prospect.Beat]), (object)prospect.Tech.Id, (object)AIResearchFramework.AICalcTechCost(ai, prospect.Tech), this.AIIsShortTermTech(ai, prospect.Tech) ? (object)"" : (object)"*"));
     }
 }
コード例 #13
0
        private Tech AISelectDefaultTechPass(
            StrategicAI ai,
            AIResearchModes?mode,
            TechFamilies?family)
        {
            List <Tech> list = AIResearchFramework.AISelectAvailableTechs(ai, mode, family).OrderBy <Tech, int>((Func <Tech, int>)(x => AIResearchFramework.AICalcTechCost(ai, x))).ToList <Tech>();

            if (list.Count > 0)
            {
                list.Insert(0, list[0]);
            }
            if (this._log != null)
            {
                this._log.Print(string.Format(" {0} prospects: ", mode.HasValue ? (object)string.Format("{0}/{1}", (object)AIResearchFramework.AIGetResearchModeSymbol(mode.Value), (object)ai.Game.GameDatabase.GetAIInfo(ai.Player.ID).Stance.ToString()) : (object)"ALL"));
                foreach (Tech tech in list)
                {
                    int num = AIResearchFramework.AICalcTechCost(ai, tech);
                    this._log.Print(string.Format("{0} ({1}); ", (object)tech.Id, (object)num));
                }
            }
            return(AIResearchFramework.AISelectFavoriteTech(ai, (IList <Tech>)list));
        }
コード例 #14
0
        private Tech AISelectDefaultTech(
            StrategicAI ai,
            List <PlayerTechInfo> desiredTech      = null,
            Dictionary <string, int> familyWeights = null)
        {
            if (this._log != null)
            {
                this._log.Print("{");
                bool flag = true;
                foreach (AITechStyleInfo techStyleInfo in ai.TechStyles.TechStyleInfos)
                {
                    if (!flag)
                    {
                        this._log.Print(",");
                    }
                    else
                    {
                        flag = false;
                    }
                    this._log.Print(techStyleInfo.TechFamily.ToString());
                }
                this._log.Print("}");
            }
            Tech tech1 = (Tech)null;

            if (AIResearchFramework.AIGetResearchingTech(ai) == null && tech1 == null)
            {
                AIStance stance = this.AIGetStance(ai);
                int      phase  = this.AIGetPhase(ai);
                List <AIResearchModes> phasedRhythm = this.AIGetPhasedRhythm(this.AIGetRhythm(stance), phase);
                IEnumerable <AIResearchFramework.TechBeat> prospects       = this.AIGetProspects(ai, this.AIGetTechBeats(this.AIGetAvailableTechs(ai), phasedRhythm, (List <PlayerTechInfo>)null));
                List <AIResearchFramework.TechBeat>        culledProspects = this.AIGetCulledProspects(ai, prospects);
                if (this._log != null)
                {
                    this._log.Print(string.Format(" (phase {0}) {1}/{2} prospects: ", (object)phase, (object)AIResearchFramework.AIGetResearchModeSymbol(phasedRhythm[0]), (object)stance));
                    this.LogProspects(ai, (IList <AIResearchModes>)phasedRhythm, (IEnumerable <AIResearchFramework.TechBeat>)culledProspects);
                    if (App.Log.Level >= Kerberos.Sots.Engine.LogLevel.Verbose)
                    {
                        this._log.Print(string.Format(" ... (phase {0}) {1}/{2} ALL prospects: ", (object)phase, (object)AIResearchFramework.AIGetResearchModeSymbol(phasedRhythm[0]), (object)stance));
                        this.LogProspects(ai, (IList <AIResearchModes>)phasedRhythm, prospects);
                    }
                }
                if (culledProspects.Any <AIResearchFramework.TechBeat>())
                {
                    if (desiredTech != null && culledProspects.Any <AIResearchFramework.TechBeat>((Func <AIResearchFramework.TechBeat, bool>)(x => desiredTech.Any <PlayerTechInfo>((Func <PlayerTechInfo, bool>)(y => y.TechFileID == x.Tech.Id)))))
                    {
                        culledProspects.RemoveAll((Predicate <AIResearchFramework.TechBeat>)(x => !desiredTech.Any <PlayerTechInfo>((Func <PlayerTechInfo, bool>)(y => y.TechFileID == x.Tech.Id))));
                    }
                    if (familyWeights != null)
                    {
                        List <Weighted <Tech> > weightedList = new List <Weighted <Tech> >();
                        foreach (Tech tech2 in culledProspects.Select <AIResearchFramework.TechBeat, Tech>((Func <AIResearchFramework.TechBeat, Tech>)(x => x.Tech)).ToList <Tech>())
                        {
                            int num;
                            if (familyWeights.TryGetValue(tech2.Family, out num))
                            {
                                weightedList.Add(new Weighted <Tech>()
                                {
                                    Value  = tech2,
                                    Weight = num
                                });
                            }
                        }
                        if (weightedList.Count > 0)
                        {
                            tech1 = WeightedChoices.Choose <Tech>(ai.Random, (IEnumerable <Weighted <Tech> >)weightedList);
                        }
                    }
                    if (tech1 == null)
                    {
                        tech1 = ai.Random.Choose <AIResearchFramework.TechBeat>((IList <AIResearchFramework.TechBeat>)culledProspects).Tech;
                    }
                }
            }
            return(tech1);
        }
コード例 #15
0
 private static List <Tech> AISelectAvailableTechs(
     StrategicAI ai,
     AIResearchModes?mode,
     TechFamilies?family)
 {
     return(ai.Game.GameDatabase.GetPlayerTechInfos(ai.Player.ID).Where <PlayerTechInfo>((Func <PlayerTechInfo, bool>)(x => AIResearchFramework.AIIsTechAvailable(x.State))).Select <PlayerTechInfo, Tech>((Func <PlayerTechInfo, Tech>)(y => ai.Game.AssetDatabase.MasterTechTree.Technologies.First <Tech>((Func <Tech, bool>)(z => y.TechFileID == z.Id)))).Where <Tech>((Func <Tech, bool>)(x => AIResearchFramework.AIContainsTech(mode, family, x))).ToList <Tech>());
 }
コード例 #16
0
 private IEnumerable <Tech> AIGetAvailableTechs(StrategicAI ai)
 {
     return(ai.Game.GameDatabase.GetPlayerTechInfos(ai.Player.ID).Where <PlayerTechInfo>((Func <PlayerTechInfo, bool>)(x => AIResearchFramework.AIIsTechAvailable(x.State))).Select <PlayerTechInfo, Tech>((Func <PlayerTechInfo, Tech>)(y => ai.Game.AssetDatabase.MasterTechTree.Technologies.First <Tech>((Func <Tech, bool>)(z => y.TechFileID == z.Id)))));
 }
コード例 #17
0
 private static int AICalcTechCost(StrategicAI ai, Tech tech)
 {
     return(AIResearchFramework.AICalcTechCost(AIResearchFramework.AICalcCombinedTechStyleCost(ai, tech), (double)tech.AICostFactors.Faction(ai.Player.Faction.Name), (double)AIResearchFramework.AIGetTurnsToComplete(ai, tech)));
 }
コード例 #18
0
 private IEnumerable <AIResearchFramework.TechBeat> AIGetProspects(
     StrategicAI ai,
     IEnumerable <AIResearchFramework.TechBeat> techs)
 {
     return((IEnumerable <AIResearchFramework.TechBeat>)techs.OrderBy <AIResearchFramework.TechBeat, int>((Func <AIResearchFramework.TechBeat, int>)(x => !this.AIIsShortTermTech(ai, x.Tech) ? 1 : 0)).ThenBy <AIResearchFramework.TechBeat, int>((Func <AIResearchFramework.TechBeat, int>)(y => y.Beat)).ThenBy <AIResearchFramework.TechBeat, int>((Func <AIResearchFramework.TechBeat, int>)(z => AIResearchFramework.AICalcTechCost(ai, z.Tech))));
 }
コード例 #19
0
 private bool AIIsShortTermTech(StrategicAI ai, Tech tech)
 {
     return(AIResearchFramework.AIGetTurnsToComplete(ai, tech) < 15);
 }
コード例 #20
0
 private AIResearchModes AIGetResearchMode(StrategicAI ai)
 {
     return(AIResearchFramework.AIGetResearchMode(this._rhythms[this.AIGetStance(ai)], this.AIGetPhase(ai)));
 }