예제 #1
0
        /// <summary>
        /// Chooses the province to attack.
        /// </summary>
        /// <returns>The province to attack.</returns>
        /// <param name="factionId">Faction identifier.</param>
        public string ChooseProvinceToAttack(string factionId)
        {
            List <string> provincesOwnedIds = world.GetFactionProvinces(factionId)
                                              .Select(x => x.Id)
                                              .ToList();

            // TODO: Do not target factions with good relations
            Dictionary <string, int> targets = world.GetProvinces()
                                               .Where(r => r.FactionId != factionId &&
                                                      r.FactionId != GameDefines.GAIA_FACTION &&
                                                      r.Locked == false)
                                               .Select(x => x.Id)
                                               .Except(provincesOwnedIds)
                                               .Where(x => provincesOwnedIds.Any(y => world.ProvinceBordersProvince(x, y)))
                                               .ToDictionary(x => x, y => 0);

            Parallel.ForEach(world.GetProvinces().Where(r => targets.ContainsKey(r.Id)).ToList(), (province) =>
            {
                if (province.SovereignFactionId == factionId)
                {
                    targets[province.Id] += BLITZKRIEG_SOVEREIGNTY_IMPORTANCE;
                }


                Parallel.ForEach(world.GetProvinceHoldings(province.Id), (holding) =>
                {
                    switch (holding.Type)
                    {
                    case HoldingType.Castle:
                        targets[province.Id] += BLITZKRIEG_HOLDING_CASTLE_IMPORTANCE;
                        break;

                    case HoldingType.City:
                        targets[province.Id] += BLITZKRIEG_HOLDING_CITY_IMPORTANCE;
                        break;

                    case HoldingType.Temple:
                        targets[province.Id] += BLITZKRIEG_HOLDING_TEMPLE_IMPORTANCE;
                        break;
                    }
                });

                Resource provinceResource = world.GetResources().FirstOrDefault(x => x.Id == province.ResourceId);

                if (provinceResource != null)
                {
                    switch (provinceResource.Type)
                    {
                    case ResourceType.Military:
                        targets[province.Id] += BLITZKRIEG_RESOURCE_MILITARY_IMPORTANCE;
                        break;

                    case ResourceType.Economy:
                        targets[province.Id] += BLITZKRIEG_RESOURCE_ECONOMY_IMPORTANCE;
                        break;
                    }
                }

                targets[province.Id] += provincesOwnedIds.Count(x => world.ProvinceBordersProvince(x, province.Id)) * BLITZKRIEG_BORDER_IMPORTANCE;
                targets[province.Id] -= world.GetFactionRelations(factionId)
                                        .FirstOrDefault(r => r.TargetFactionId == province.FactionId)
                                        .Value;

                // TODO: Maybe add a random importance to each province in order to reduce predictibility a little
            });

            if (targets.Count == 0)
            {
                return(null);
            }

            int           maxScore   = targets.Max(x => x.Value);
            List <string> topTargets = targets.Keys.Where(x => targets[x] == maxScore).ToList();
            string        provinceId = topTargets[random.Next(0, topTargets.Count())];

            return(provinceId);
        }
예제 #2
0
 /// <summary>
 /// Gets the relations of a faction.
 /// </summary>
 /// <returns>The relations of a faction.</returns>
 /// <param name="factionId">Faction identifier.</param>
 public IEnumerable <Relation> GetFactionRelations(string factionId)
 => world.GetFactionRelations(factionId);