Beispiel #1
0
        public bool OpponentMightControlBonus(BonusDetails b)
        {
            PlayerIDType?oppID = null;

            foreach (var territoryID in b.Territories)
            {
                var ts = Standing.Territories[territoryID];
                if (ts.OwnerPlayerID == TerritoryStanding.FogPlayerID)
                {
                    continue;
                }

                if (ts.OwnerPlayerID == TerritoryStanding.AvailableForDistribution || ts.OwnerPlayerID == TerritoryStanding.NeutralPlayerID || IsTeammateOrUs(ts.OwnerPlayerID))
                {
                    return(false);
                }
                if (!oppID.HasValue)
                {
                    oppID = ts.OwnerPlayerID;
                }
                else if (oppID.Value != ts.OwnerPlayerID)
                {
                    return(false); //nobody has it
                }
            }

            return(true);
        }
Beispiel #2
0
 private int GetFudgeFactor(BonusDetails bonus, PlayerIDType playerId)
 {
     if (playerId == GameState.OpponentPlayerId)
     {
         return(100);
     }
     return(GetBonusDistanceMultiplicator(bonus));
 }
Beispiel #3
0
 public void Init(BonusDetails itemDetails)
 {
     currentItem  = itemDetails;
     price.text   = itemDetails.Price.ToString();
     name.text    = itemDetails.Bonus.ToString();
     amount.text  = itemDetails.Amount.ToString();
     image.sprite = itemDetails.Image;
     buy.onClick.AddListener(Buy);
 }
        /// <summary>
        /// Returns the probability the enemy controls a given bonus. Calculated as Sqrt(minimum prob of enemy contrlling territory in bonus). The sqrt is to account for the fact that the enemy will not attack randomly but will instead concentrate forces in a bonus. Also assumes enemies don't split bonuses.
        /// </summary>
        /// <param name="bonus">The bonus we are seeing if the enemy controls.</param>
        /// <returns>Probability enemy controls bonus.</returns>
        public double probEnemyControls(BonusDetails bonus)
        {
            double minProb = 1.0;

            foreach (TerritoryIDType territory in bonus.Territories)
            {
                minProb = Math.Min(minProb, enemyProbs[territory]);
            }
            return(Math.Sqrt(minProb));
        }
Beispiel #5
0
        /*
         * private int GetAverageTerritoryDistance()
         * {
         *  var opponentTerritories = MapInformer.GetOwnedTerritories(FinalStandings.Values.ToList(), GameState.OpponentPlayerId);
         *  var opponentTerritoryIds = new List<TerritoryIDType>();
         *  opponentTerritories.ForEach(t => opponentTerritoryIds.Add(t.ID));
         *  var distances = MapInformer.GetDistancesFromTerritories(opponentTerritoryIds);
         *  int territoryCount = 0;
         *  int allDistances = 0;
         *  foreach (int distance in distances.Values)
         *  {
         *      if (distance > 0)
         *      {
         *          territoryCount++;
         *          allDistances += distance;
         *      }
         *  }
         *  return allDistances / territoryCount;
         * }
         */


        private int GetBonusDistanceMultiplicator(BonusDetails bonus)
        {
            var opponentTerritories  = MapInformer.GetOwnedTerritories(FinalStandings.Values.ToList(), GameState.OpponentPlayerId);
            var opponentTerritoryIds = new List <TerritoryIDType>();

            opponentTerritories.ForEach(t => opponentTerritoryIds.Add(t.ID));
            if (distancesCache == null)
            {
                distancesCache = MapInformer.GetDistancesFromTerritories(opponentTerritoryIds);
            }
            int territoryCount          = 0;
            int allDistances            = 0;
            int bonusTerritoryCount     = 0;
            int bonusTerritoryDistances = 0;

            foreach (var territory in distancesCache.Keys)
            {
                var distance = distancesCache[territory];
                if (distance > 0)
                {
                    territoryCount++;
                    allDistances += distance;
                }

                if (bonus.Territories.Contains(territory))
                {
                    bonusTerritoryCount++;
                    bonusTerritoryDistances += distancesCache[territory];
                }
            }
            int averageDistance;

            if (territoryCount != 0)
            {
                averageDistance = allDistances / territoryCount;
            }
            else
            {
                averageDistance = 0;
            }
            int bonusAverageDistance = bonusTerritoryDistances / bonusTerritoryCount;
            int difference           = bonusAverageDistance - averageDistance;

            int multiplicator;

            if (bonusAverageDistance >= 0)
            {
                multiplicator = Math.Min(difference, MAX_BONUS_DISTANCE_ADJUSTMENT);
            }
            else
            {
                multiplicator = Math.Max(difference, -MAX_BONUS_DISTANCE_ADJUSTMENT);
            }
            return(multiplicator + 100);
        }
Beispiel #6
0
        private int GetOwnedBonusValue(BonusDetails bonus, PlayerIDType playerId)
        {
            // we like high income
            int value = bonus.Amount * BONUS_MULTIPLICATOR;

            value = value * GetFudgeFactor(bonus, playerId) / 100;



            return(value);
        }
Beispiel #7
0
        public static List <TerritoryIDType> GetBonusTerritoriesAndNeighbors(BonusDetails bonus)
        {
            HashSet <TerritoryIDType> result = new HashSet <TerritoryIDType>(bonus.Territories);

            // System.InvalidOperationException: "Die Sammlung wurde geändert. Der Enumerationsvorgang kann möglicherweise nicht ausgeführt werden."
            foreach (TerritoryIDType testTerritory in bonus.Territories)
            {
                List <TerritoryIDType> neighbors = GetNeighborTerritories(testTerritory);
                result.UnionWith(neighbors);
            }
            return(result.ToList());
        }
        private List <TerritoryIDType> GetMissingBonusTerritories(BonusDetails bonus, MultiMoves presentMoves)
        {
            var bonusTerritories = bonus.Territories;
            var currentStatus    = presentMoves.GetTerritoryStandingsAfterAllMoves();
            List <TerritoryIDType> territories = new List <TerritoryIDType>();

            foreach (var bonusTerritory in bonusTerritories)
            {
                if (currentStatus[bonusTerritory].OwnerPlayerID != GameState.MyPlayerId)
                {
                    territories.Add(bonusTerritory);
                }
            }
            return(territories);
        }
Beispiel #9
0
        private int GetBonusSizeMultiplicator(BonusDetails bonus)
        {
            int medianBonusSize      = GetMedianBonusSize();
            int bonusSize            = bonus.Territories.Count;
            int differenceFromMedian = bonusSize - medianBonusSize;
            int multiplicator;

            if (differenceFromMedian >= 0)
            {
                multiplicator = Math.Min(differenceFromMedian, MAX_BONUS_SIZE_ADJUSTMENT);
            }
            else
            {
                multiplicator = Math.Max(differenceFromMedian, -MAX_BONUS_SIZE_ADJUSTMENT);
            }
            return(multiplicator + 100);
        }
Beispiel #10
0
        public static Dictionary <BonusIDType, BonusDetails> GetOwnedBonuses(Dictionary <TerritoryIDType, TerritoryStanding> territoryStandings, PlayerIDType player)
        {
            Dictionary <BonusIDType, BonusDetails> allBonuses   = GameState.Map.Bonuses;
            Dictionary <BonusIDType, BonusDetails> ownedBonuses = new Dictionary <BonusIDType, BonusDetails>();
            List <TerritoryIDType> ownedTerritories             = territoryStandings.Keys.Where(t => territoryStandings[t].OwnerPlayerID == player).ToList();

            foreach (BonusIDType bonusId in allBonuses.Keys)
            {
                BonusDetails           bonusDetails          = allBonuses[bonusId];
                List <TerritoryIDType> ownedBonusTerritories = bonusDetails.Territories.Where(t => ownedTerritories.Contains(t)).ToList();
                if (ownedBonusTerritories.Count() == bonusDetails.Territories.Count())
                {
                    ownedBonuses.Add(bonusId, bonusDetails);
                }
            }

            return(ownedBonuses);
        }
Beispiel #11
0
        public bool PlayerControlsBonus(BonusDetails b)
        {
            var c = b.ControlsBonus(Standing);

            return(c.HasValue && c.Value == PlayerID);
        }
Beispiel #12
0
 public string BonusString(BonusDetails bonus)
 {
     return(bonus.Name + " (id=" + bonus.ID + " val=" + BonusValue(bonus.ID) + ")");
 }
Beispiel #13
0
 public static List <TerritoryIDType> GetNonOwnedBonusTerritories(BonusDetails bonus, Dictionary <TerritoryIDType, TerritoryStanding> territoryStandings)
 {
     return(bonus.Territories.Where(o => territoryStandings[o].OwnerPlayerID != GameState.MyPlayerId).ToList());
 }