Exemple #1
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]);
        }
    }
Exemple #2
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);
    }
    private HeuristicValue GetTaskFitness(BaseNavyArmy navyGarrison)
    {
        HeuristicValue heuristicValue = new HeuristicValue(0f);

        base.Owner.GetAgency <DepartmentOfForeignAffairs>();
        if (navyGarrison.Garrison.GUID == base.TargetGuid)
        {
            heuristicValue.Value = -1f;
            heuristicValue.Log("Cannot reinforce itself.", new object[0]);
        }
        else if (navyGarrison.Role == BaseNavyArmy.ArmyRole.Land || navyGarrison.Role == BaseNavyArmy.ArmyRole.Forteress || navyGarrison.Role == BaseNavyArmy.ArmyRole.Convoi)
        {
            heuristicValue.Value = -1f;
            heuristicValue.Log("Role is not valid for the task. Role={0}.", new object[]
            {
                navyGarrison.Role.ToString()
            });
        }
        else if (navyGarrison.Garrison.StandardUnits.Count == 0)
        {
            heuristicValue.Value = -1f;
            heuristicValue.Log("Army is empty, cannot be used as reinforcement.", new object[0]);
        }
        else
        {
            heuristicValue.Add(this.NavyFortress.WantToKeepArmyFitness, "Fortress army need", new object[0]);
            if (navyGarrison.Role == BaseNavyArmy.ArmyRole.TaskForce)
            {
                heuristicValue.Boost(-0.1f, "constant avoid reinforce while task force.", new object[0]);
                float          num             = (float)navyGarrison.Garrison.CurrentUnitSlot;
                float          operand         = Math.Abs((float)this.ReinforcementSlots - num);
                HeuristicValue heuristicValue2 = new HeuristicValue(0f);
                heuristicValue2.Add(operand, "ABS(TaskSlotNeeded - armySize)", new object[0]);
                heuristicValue2.Divide(num, "Army size", new object[0]);
                heuristicValue.Subtract(heuristicValue2, "Size ratio", new object[0]);
            }
            if (heuristicValue.Value > 0f)
            {
                if (this.NavyFortress.ArmySize < BaseNavyArmy.ArmyState.Medium)
                {
                    heuristicValue.Boost(0.2f, "(constant)Under medium", new object[0]);
                }
                else if (this.NavyFortress.ArmySize < BaseNavyArmy.ArmyState.High)
                {
                    heuristicValue.Boost(0.1f, "(constant)Under high", new object[0]);
                }
                float numberOfTurnToReach = (float)this.worldPositionService.GetDistance(navyGarrison.Garrison.WorldPosition, this.NavyFortress.Garrison.WorldPosition) / navyGarrison.GetMaximumMovement();
                heuristicValue.Multiply(base.ComputeDistanceFitness(numberOfTurnToReach, navyGarrison.Role), "Distance", new object[0]);
            }
        }
        return(heuristicValue);
    }
Exemple #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);
    }