Esempio n. 1
0
    private HeuristicValue GetUnitPriority(UnitDesign unitDesign)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        heuristicValue.Add(this.currentProductionPriority, "Current unit priority", new object[0]);
        HeuristicValue heuristicValue2 = new HeuristicValue(0f);
        int            num             = this.availableMilitaryBody.IndexOf(unitDesign.UnitBodyDefinition.Name);

        if (num >= 0)
        {
            float num2 = this.bodyCount[num] / this.overralUnitCount;
            float num3 = this.wantedBodyRatio[num];
            if (num2 > num3)
            {
                heuristicValue2.Log("Too much of this body already", new object[0]);
                heuristicValue2.Add(num2, "Current ratio", new object[0]);
                heuristicValue2.Divide(num3, "Wanted ratio", new object[0]);
                heuristicValue2.Clamp(0f, 2f);
                heuristicValue2.Multiply(-1f, "invert", new object[0]);
            }
            else
            {
                heuristicValue2.Log("Not enough of this body for now.", new object[0]);
                heuristicValue2.Add(num3, "Wanted ratio", new object[0]);
                heuristicValue2.Divide(num2, "Current ratio", new object[0]);
                heuristicValue2.Clamp(0f, 2f);
            }
        }
        heuristicValue2.Multiply(0.05f, "constant", new object[0]);
        heuristicValue.Boost(heuristicValue2, "Body ratio boost", new object[0]);
        DepartmentOfTheInterior agency = this.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();

        if (unitDesign.Name.ToString().Contains("Preacher") && this.VillageLayer.ConversionArmiesCount > 0 && (this.VictoryLayer == null || this.VictoryLayer.CurrentVictoryDesign != AILayer_Victory.VictoryDesign.Preacher))
        {
            heuristicValue.Boost(-0.4f, "Bad Unit Malus", new object[0]);
        }
        else if (unitDesign.Name.ToString().Contains("EyelessOnesCaecator"))
        {
            heuristicValue.Boost(-0.3f, "Bad Unit Malus", new object[0]);
        }
        else if (unitDesign.Name.ToString().Contains("CeratanDrider"))
        {
            heuristicValue.Boost(-0.15f, "Bad Unit Malus", new object[0]);
        }
        if (unitDesign.Name.ToString().Contains("Mastermind") && agency.AssimilatedFactions.Count > 0)
        {
            foreach (Faction faction in agency.AssimilatedFactions)
            {
                if (faction.Name != "Ceratan" && faction.Name != "EyelessOnes")
                {
                    heuristicValue.Boost(-0.2f, "Bad Unit Malus", new object[0]);
                    break;
                }
            }
        }
        return(heuristicValue);
    }
Esempio n. 2
0
    private void ComputeCostalBoost()
    {
        DepartmentOfTheInterior agency = base.Empire.GetAgency <DepartmentOfTheInterior>();

        this.costalCityCount = 0;
        for (int i = 0; i < agency.Cities.Count; i++)
        {
            if (agency.Cities[i].Districts.Any((District match) => this.worldPositionningService.IsWaterTile(match.WorldPosition)))
            {
                this.costalCityCount++;
            }
        }
        this.costalColonizationBoost.Reset();
        if (this.costalCityCount < 3)
        {
            int            num            = 3;
            HeuristicValue heuristicValue = new HeuristicValue(0f);
            heuristicValue.Add((float)agency.Cities.Count, "City count", new object[0]);
            heuristicValue.Subtract((float)(this.costalCityCount * num), "Costal city * {0}", new object[]
            {
                num
            });
            heuristicValue.Divide((float)num, "Costal gap", new object[0]);
            heuristicValue.Clamp(0.1f, 1f);
            heuristicValue.Multiply(this.costalCityRatioMaxBoost, "Factor from xml", new object[0]);
            this.costalColonizationBoost.Boost(heuristicValue, "Costal city ratio boost", new object[0]);
        }
        if (base.Empire.SimulationObject.Tags.Contains(DownloadableContent16.AffinitySeaDemons))
        {
            this.costalColonizationBoost.Boost(0.1f, "Sea demons", new object[0]);
        }
    }
Esempio n. 3
0
    protected HeuristicValue ComputePowerFitness(float enemyPower, float myPower)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        enemyPower += 1f;
        myPower    += 1f;
        if (enemyPower > myPower)
        {
            float num = myPower / enemyPower;
            if (num < 0.8f)
            {
                heuristicValue.Value = -1f;
                heuristicValue.Log("Enemy really too strong. Ratio My/enemyPower = {0}", new object[]
                {
                    num
                });
                return(heuristicValue);
            }
            heuristicValue.Add(0.8f, "Max ratio as we are under the enemy power.", new object[0]);
            heuristicValue.Boost(-1f + num, "inverted negative ratio", new object[0]);
        }
        else
        {
            heuristicValue.Add(0.8f, "Max ratio as we are over the enemy power.", new object[0]);
            HeuristicValue heuristicValue2 = new HeuristicValue(0f);
            heuristicValue2.Add(enemyPower, "Enemy power", new object[0]);
            heuristicValue2.Divide(myPower, "My power", new object[0]);
            HeuristicValue heuristicValue3 = new HeuristicValue(0f);
            heuristicValue3.Add(1f, "constant", new object[0]);
            heuristicValue3.Subtract(heuristicValue2, "Enemy/my power ratio", new object[0]);
            heuristicValue3.Clamp(-1f, 1f);
            heuristicValue.Boost(heuristicValue3, "Boost based on power", new object[0]);
        }
        return(heuristicValue);
    }
Esempio n. 4
0
    protected HeuristicValue ComputeDistanceFitness(float numberOfTurnToReach, BaseNavyArmy.ArmyRole armyRole)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);
        float          num            = 5f;

        heuristicValue.Add(numberOfTurnToReach, "Turn to reach", new object[0]);
        float operand = 4f;

        heuristicValue.Divide(operand, "constant", new object[0]);
        heuristicValue.Clamp(0f, num);
        HeuristicValue heuristicValue2 = new HeuristicValue(0f);

        heuristicValue2.Add(num, "constant", new object[0]);
        heuristicValue2.Subtract(heuristicValue, "Turn ratio", new object[0]);
        HeuristicValue heuristicValue3 = new HeuristicValue(0f);

        heuristicValue3.Add(heuristicValue2, "inverted turn ratio", new object[0]);
        heuristicValue3.Divide(num, "constant for normalization", new object[0]);
        return(heuristicValue3);
    }
Esempio n. 5
0
 private void ResetProductionPriority(float currentMilitaryPower)
 {
     this.InitialProductionPriority.Reset();
     if (this.needMilitaryPower < currentMilitaryPower)
     {
         float          num            = 2f;
         HeuristicValue heuristicValue = new HeuristicValue(0f);
         heuristicValue.Add(currentMilitaryPower, "Current military power", new object[0]);
         heuristicValue.Divide(this.needMilitaryPower, "Wanted military power", new object[0]);
         HeuristicValue heuristicValue2 = new HeuristicValue(0f);
         heuristicValue2.Add(heuristicValue, "Ratio", new object[0]);
         heuristicValue2.Clamp(0f, num);
         heuristicValue2.Divide(num, "Normalize", new object[0]);
         heuristicValue2.Multiply(0.7f, "Max difference", new object[0]);
         this.InitialProductionPriority.Add(0.8f, "Max priority when over wanted", new object[0]);
         this.InitialProductionPriority.Subtract(heuristicValue2, "Current higher than wanted", new object[0]);
     }
     else if (currentMilitaryPower > 0f)
     {
         float          num2            = 4f;
         HeuristicValue heuristicValue3 = new HeuristicValue(0f);
         heuristicValue3.Add(this.needMilitaryPower, "Wanted military power", new object[0]);
         heuristicValue3.Divide(currentMilitaryPower, "Current military power", new object[0]);
         HeuristicValue heuristicValue4 = new HeuristicValue(0f);
         heuristicValue4.Add(heuristicValue3, "Ratio", new object[0]);
         heuristicValue4.Clamp(0f, num2);
         heuristicValue4.Divide(num2, "Normalize", new object[0]);
         heuristicValue4.Multiply(0.6f, "Max difference", new object[0]);
         this.InitialProductionPriority.Add(0.3f, "Minimal priority", new object[0]);
         this.InitialProductionPriority.Add(heuristicValue4, "Current is under needed", new object[0]);
     }
     else
     {
         this.InitialProductionPriority.Add(0.8f, "current == 0, max priority!", new object[0]);
     }
 }