Esempio n. 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);
        }
Esempio n. 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);
        }