コード例 #1
0
        // positive then bad, negative then good
        private double GetNeighborBonusesFactor(BotBonus bonus)
        {
            if (BotState.NumberOfTurns != -1)
            {
                return(0);
            }
            List <BotBonus> betterSmallerBonuses = new List <BotBonus>();
            List <BotBonus> betterLargerBonuses  = new List <BotBonus>();
            double          neighborBonusValueToleranceFactor = 1.3;
            double          betterBiggerBonusesMultiplicator  = 0.001;
            double          betterSmallerBonusesMultiplicator = 0.01;

            List <BotBonus> neighborBonuses = bonus.GetNeighborBonuses();
            double          ourValue        = GetExpansionValue(bonus, false);

            foreach (BotBonus neighborBonus in neighborBonuses)
            {
                if (neighborBonus.Territories.Count(o => o.OwnerPlayerID == TerritoryStanding.AvailableForDistribution) == 0)
                {
                    continue;
                }
                double neighborBonusValue = GetExpansionValue(neighborBonus, false);
                neighborBonusValue = neighborBonusValue * neighborBonusValueToleranceFactor;
                if (neighborBonusValue >= ourValue && bonus.Territories.Count > neighborBonus.Territories.Count)
                {
                    betterSmallerBonuses.Add(bonus);
                }
                else if (neighborBonusValue >= ourValue && bonus.Territories.Count < neighborBonus.Territories.Count)
                {
                    betterLargerBonuses.Add(bonus);
                }
            }
            int amountBetterLittleSmallerBonuses = 0;
            int amountBetterVerySmallerBonuses   = 0;

            foreach (BotBonus smallerNeighbor in betterSmallerBonuses)
            {
                if (smallerNeighbor.Territories.Count <= bonus.Territories.Count / 2)
                {
                    amountBetterVerySmallerBonuses++;
                }
                else
                {
                    amountBetterLittleSmallerBonuses++;
                }
            }
            double adjustedFactor =
                (betterBiggerBonusesMultiplicator * betterLargerBonuses.Count - betterSmallerBonusesMultiplicator * amountBetterLittleSmallerBonuses - betterSmallerBonusesMultiplicator
                 * 2 * amountBetterVerySmallerBonuses);

            adjustedFactor = Math.Max(-0.2, Math.Min(0.2, adjustedFactor));

            return(-1 * adjustedFactor);
        }
コード例 #2
0
        public double GetExpansionValue(BotBonus bonus, Boolean useNeighborBonusFactor)
        {
            double expansionValue = 0.0;

            if (IsExpansionWorthless(bonus))
            {
                return(expansionValue);
            }

            expansionValue = GetIncomeCostsRatio(bonus);

            var    neutralArmies       = bonus.NeutralArmies.DefensePower;
            double neutralArmiesFactor = GetNeutralArmiesFactor(neutralArmies);

            int    allTerritories  = bonus.Territories.Count;
            double territoryFactor = GetTerritoryFactor(allTerritories);


            int    immediatelyCounteredTerritories       = bonus.GetOwnedTerritoriesBorderingOpponent().Count;
            double immediatelyCounteredTerritoriesFactor = GetImmediatelyCounteredTerritoryFactor(immediatelyCounteredTerritories);

            var    allCounteredTerritories       = GetCounteredTerritories(bonus, BotState.Me.ID);
            double allCounteredTerritoriesFactor = GetAllCounteredTerritoryFactor(allCounteredTerritories);

            int amountNeighborBonusesWithOpponent = 0;
            var neighborBonuses = bonus.GetNeighborBonuses();

            foreach (var neighborBonus in neighborBonuses)
            {
                if (neighborBonus.ContainsOpponentPresence())
                {
                    amountNeighborBonusesWithOpponent++;
                }
            }
            double opponentNeighborBonusFactor = GetOpponentInNeighborBonusFactor(amountNeighborBonusesWithOpponent);
            double borderTerritoriesFactor     = getBorderTerritoriesFactor(bonus);

            double completeFactor = neutralArmiesFactor + territoryFactor + immediatelyCounteredTerritoriesFactor + allCounteredTerritoriesFactor + opponentNeighborBonusFactor + borderTerritoriesFactor;

            if (useNeighborBonusFactor)
            {
                completeFactor += GetNeighborBonusesFactor(bonus);
            }
            completeFactor = Math.Min(completeFactor, 0.8);

            expansionValue = expansionValue - (expansionValue * completeFactor);

            return(expansionValue);
        }