コード例 #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
ファイル: GameManager.cs プロジェクト: dmaulikr/narivia
 /// <summary>
 /// Gets the resources.
 /// </summary>
 /// <returns>The resources.</returns>
 public IEnumerable <Resource> GetResources()
 => world.GetResources();