예제 #1
0
        public MultiMoves CalculateMoveArmiesToBorderMoves(MultiMoves presentMoves)
        {
            MultiMoves result = presentMoves.Clone();
            var        nonOwnedTerritories = MapInformer.GetNonOwnedTerritories(result.GetTerritoryStandingsAfterAllMoves().Values.ToList(), GameState.MyPlayerId);
            var        keys = new List <TerritoryIDType>();

            nonOwnedTerritories.ForEach(k => keys.Add(k.ID));
            var distances = MapInformer.GetDistancesFromTerritories(keys);

            foreach (TerritoryIDType territoryId in distances.Keys)
            {
                int distance = distances[territoryId];
                if (distance <= 1)
                {
                    continue;
                }
                var neighbors = MapInformer.GetNeighborTerritories(territoryId);
                var lowestDistanceNeighborValue = neighbors.Min(c => distances[c]);
                var lowestDistanceNeighbor      = neighbors.Where(n => distances[n] == lowestDistanceNeighborValue).First();
                TerritoryStanding theTerritory  = result.GetTerritoryStandingsAfterAllMoves()[territoryId];
                int armiesAvailable             = theTerritory.NumArmies.ArmiesOrZero - theTerritory.ArmiesMarkedAsUsed.ArmiesOrZero - 1;
                if (armiesAvailable == 0)
                {
                    continue;
                }
                GameOrderAttackTransfer attackMove =
                    GameOrderAttackTransfer.Create
                        (GameState.MyPlayerId, territoryId, lowestDistanceNeighbor, AttackTransferEnum.AttackTransfer, new Armies(armiesAvailable), REASON);
                result.AddAttackOrder(attackMove);
            }
            return(result);
        }
예제 #2
0
        public MultiMoves CalculateTakeTerritoriesMoves(List <TerritoryIDType> territoriesToTake, MultiMoves precondition)
        {
            MultiMoves             resultMoves           = precondition.Clone();
            List <TerritoryIDType> territoriesToTakeCopy = new List <TerritoryIDType>(territoriesToTake);


            while (territoriesToTakeCopy.Count > 0)
            {
                var reachableTerritories = FilterNonBorderingTerritories(territoriesToTakeCopy, resultMoves);
                if (reachableTerritories.Count == 0)
                {
                    return(null);
                }
                var bestStartTerritory  = GetBestAttackingTerritory(reachableTerritories, resultMoves);
                var bestAttackTerritory = GetBestAttackTerritory(reachableTerritories, territoriesToTakeCopy, bestStartTerritory, resultMoves);
                int neededAttackArmies  = AttackInformer.GetNeededBreakArmies
                                              (resultMoves.GetTerritoryStandingsAfterAllMoves()[bestAttackTerritory].NumArmies.ArmiesOrZero);
                GameOrderAttackTransfer attackOrder = GameOrderAttackTransfer.Create
                                                          (GameState.MyPlayerId, bestStartTerritory, bestAttackTerritory, AttackTransferEnum.AttackTransfer, new Armies(neededAttackArmies), REASON);

                var  standing       = resultMoves.GetTerritoryStandingsAfterAllMoves().Where(o => o.Key == attackOrder.From).First().Value;
                int  leftoverArmies = standing.NumArmies.ArmiesOrZero - standing.ArmiesMarkedAsUsed.ArmiesOrZero - 1;
                int  armiesToPump   = Math.Max(0, attackOrder.NumArmies.ArmiesOrZero - leftoverArmies);
                bool successfull    = resultMoves.PumpArmies(attackOrder.From, armiesToPump, REASON);
                if (!successfull)
                {
                    return(null);
                }
                resultMoves.AddAttackOrder(attackOrder);
                territoriesToTakeCopy.Remove(bestAttackTerritory);
            }

            return(resultMoves);
        }
예제 #3
0
        private void AddAttack(TerritoryIDType from, TerritoryIDType to, AttackTransferEnum attackTransfer, int numArmies, bool attackTeammates)
        {
            IEnumerable <GameOrderAttackTransfer> attacks = Orders.OfType <GameOrderAttackTransfer>();
            var existingFrom   = attacks.Where(o => o.From == from).ToList();
            var existingFromTo = existingFrom.Where(o => o.To == to).ToList();

            if (existingFromTo.Any())
            {
                existingFromTo.Single().NumArmies = existingFromTo.Single().NumArmies.Add(new Armies(numArmies));
            }
            else
            {
                var specials = Standing.Territories[from].NumArmies.SpecialUnits;
                if (specials.Length > 0)
                {
                    var used = existingFrom.SelectMany(o => o.NumArmies.SpecialUnits).Select(o => o.ID).ToHashSet(false);
                    specials = specials.Where(o => used.Contains(o.ID) == false).ToArray();
                }

                AddOrder(GameOrderAttackTransfer.Create(this.PlayerID, from, to, attackTransfer, false, new Armies(numArmies, false, specials), attackTeammates));
            }
        }
예제 #4
0
        public void AddAttack(TerritoryIDType from, TerritoryIDType to, AttackTransferEnum attackTransfer, int numArmies, bool attackTeammates, bool byPercent = false, bool bosses = false, bool commanders = false)
        {
            Assert.Fatal(Bot.Map.Territories[from].ConnectedTo.ContainsKey(to), from + " does not connect to " + to);

            var actualArmies    = numArmies;
            var actualByPercent = byPercent;

            if (actualByPercent && Bot.Settings.AllowPercentageAttacks == false)
            {
                actualByPercent = false;
                actualArmies    = 1000000;
            }

            var actualMode = attackTransfer;

            if (actualMode == AttackTransferEnum.Transfer && Bot.Settings.AllowTransferOnly == false)
            {
                actualMode = AttackTransferEnum.AttackTransfer;
            }
            if (actualMode == AttackTransferEnum.Attack && Bot.Settings.AllowAttackOnly == false)
            {
                actualMode = AttackTransferEnum.AttackTransfer;
            }

            IEnumerable <GameOrderAttackTransfer> attacks = Orders.OfType <GameOrderAttackTransfer>();
            var existingFrom   = attacks.Where(o => o.From == from).ToList();
            var existingFromTo = existingFrom.Where(o => o.To == to).ToList();

            if (existingFromTo.Any())
            {
                var existing = existingFromTo.Single();
                existing.ByPercent      = actualByPercent;
                existing.AttackTransfer = actualMode;
                existing.NumArmies      = existing.NumArmies.Add(new Armies(actualArmies));

                if (actualByPercent && existing.NumArmies.NumArmies > 100)
                {
                    existing.NumArmies = existing.NumArmies.Subtract(new Armies(existing.NumArmies.NumArmies - 100));
                }
            }
            else
            {
                var specials = Bot.Standing.Territories[from].NumArmies.SpecialUnits;
                if (specials.Length > 0)
                {
                    var used = existingFrom.SelectMany(o => o.NumArmies.SpecialUnits).Select(o => o.ID).ToHashSet(false);
                    specials = specials.Where(o => used.Contains(o.ID) == false).ToArray();

                    if (bosses == false)
                    {
                        specials = specials.Where(o => o.IsBoss() == false).ToArray();
                    }

                    if (commanders == false)
                    {
                        specials = specials.Where(o => !(o is Commander)).ToArray();
                    }
                }

                AddOrder(GameOrderAttackTransfer.Create(Bot.PlayerID, from, to, actualMode, actualByPercent, new Armies(actualArmies, specials), attackTeammates));
            }
        }
예제 #5
0
파일: Moves.cs 프로젝트: Joi179/WarLight.AI
 private GameOrder Convert(BotOrderAttackTransfer o)
 {
     return(GameOrderAttackTransfer.Create(o.PlayerID, o.From.ID, o.To.ID, AttackTransferEnum.AttackTransfer, false, o.Armies, false));
 }
예제 #6
0
 private static GameOrder Convert(BotOrderAttackTransfer o)
 {
     return(GameOrderAttackTransfer.Create(o.PlayerID, o.FromTerritory.ID, o.ToTerritory.ID, AttackTransferEnum.AttackTransfer, false, new Armies(o.Armies), false));
 }