예제 #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);
    }
예제 #2
0
    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);
    }
예제 #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);
    }