/// <param name="opponentTerritory"></param>
        /// <param name="maxDeployment"></param>
        /// <returns></returns>
        public static Moves CalculateAttackTerritoryTask(BotMain state, BotTerritory opponentTerritory, int maxDeployment)
        {
            var outvar                  = new Moves();
            var ownedNeighbors          = opponentTerritory.GetOwnedNeighbors();
            var presortedOwnedNeighbors = state.TerritoryValueCalculator.SortDefenseValue(ownedNeighbors
                                                                                          );
            var sortedOwnedNeighbors = BotMap.GetOrderedListOfTerritoriesByIdleArmies(
                presortedOwnedNeighbors);

            // Calculate the attacks
            for (var i = 0; i < sortedOwnedNeighbors.Count; i++)
            {
                var attackingTerritory = sortedOwnedNeighbors[i];
                if (i == 0 && maxDeployment > 0)
                {
                    var pam = new BotOrderDeploy(state.Me.ID, attackingTerritory, maxDeployment);
                    outvar.AddOrder(pam);
                    if (attackingTerritory.GetIdleArmies().AttackPower + maxDeployment > 1)
                    {
                        var atm = new BotOrderAttackTransfer(state.Me.ID, attackingTerritory, opponentTerritory, attackingTerritory.GetIdleArmies().Add(new Armies(maxDeployment)), "AttackTerritoriesTask1");
                        outvar.AddOrder(atm);
                    }
                }
                else
                {
                    if (attackingTerritory.GetIdleArmies().AttackPower > 1)
                    {
                        var atm = new BotOrderAttackTransfer(state.Me.ID, attackingTerritory, opponentTerritory, attackingTerritory.GetIdleArmies(), "AttackTerritoriesTask2");
                        outvar.AddOrder(atm);
                    }
                }
            }
            // Check if we are killing more or equal armies than the opponent
            // double currentOpponentArmies = opponentTerritory.ArmiesAfterDeployment;
            var    currentOpponentArmies = opponentTerritory.GetArmiesAfterDeploymentAndIncomingAttacks(BotTerritory.DeploymentType.Normal).DefensePower;
            double opponentKills         = 0;
            double ownKills = 0;

            foreach (var atm_1 in outvar.Orders.OfType <BotOrderAttackTransfer>())
            {
                int ourKills = opponentTerritory.getOwnKills(atm_1.Armies.AttackPower, currentOpponentArmies);
                //var ourKills = Math.Min(currentOpponentArmies, atm_1.Armies.AttackPower * state.Settings.OffensiveKillRate);
                var opponentKillsAttack = Math.Min(atm_1.Armies.AttackPower, currentOpponentArmies * state.Settings.DefenseKillRate);
                ownKills             += ourKills;
                opponentKills        += opponentKillsAttack;
                currentOpponentArmies = Math.Max(0, currentOpponentArmies - ourKills);
            }
            if (ownKills >= opponentKills && outvar.Orders.OfType <BotOrderAttackTransfer>().Any())
            {
                return(outvar);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Returns whether it makes sense to perform an unplanned expansion step from our territory to the neutral territory.
        /// </summary>
        /// <remarks>
        /// Returns whether it makes sense to perform an unplanned expansion step from our territory to the neutral territory. The
        /// parameters considered therefore are the distance to the opponent and whether we can take that territory.
        /// </remarks>
        /// <param name="fromTerritory">an owned territory, not bordering the opponent</param>
        /// <param name="toTerritory">a neutral territory</param>
        /// <returns></returns>
        private static bool IsUnplannedExpansionStepSmart(BotMain state, BotTerritory fromTerritory, BotTerritory toTerritory)
        {
            var isSmart = true;

            if (fromTerritory.GetIdleArmies().AttackPower <= 1)
            {
                isSmart = false;
            }

            if (toTerritory.Armies.DefensePower > toTerritory.getOwnKills(fromTerritory.GetIdleArmies().AttackPower, toTerritory.Armies.DefensePower))
            {
                isSmart = false;
            }
            var distanceCondition1 = fromTerritory.DistanceToOpponentBorder <= 4;
            var distanceCondition2 = toTerritory.GetOpponentNeighbors().Count == 0;

            if (distanceCondition1 && distanceCondition2)
            {
                isSmart = false;
            }
            return(isSmart);
        }