Пример #1
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);
        }
Пример #2
0
        private void PumpBiggestAttack(MultiMoves movesSoFar, GameOrderAttackTransfer biggestAttack, int availableDeployment)
        {
            if (availableDeployment == 0)
            {
                return;
            }
            movesSoFar.AddDeployOrder(GameOrderDeploy.Create(GameState.MyPlayerId, availableDeployment, biggestAttack.From, REASON));
            var  endAttack = biggestAttack;
            bool foundStep = true;

            while (foundStep)
            {
                foundStep = false;
                // probably endless loop possible as soon as we add transfer moves back to attacking territory
                var nextAttack = movesSoFar.AttackMoves.Where(a => a.From == endAttack.To).FirstOrDefault();
                if (nextAttack != null)
                {
                    endAttack = nextAttack;
                    foundStep = true;
                }
            }
            movesSoFar.PumpArmies(endAttack.To, availableDeployment, REASON);
        }