コード例 #1
0
        public static Moves CalculateBreakTerritoryTask(BotMain state, BotTerritory opponentTerritory, int maxDeployment, BotTerritory.DeploymentType conservativeLevel)
        {
            var outvar                  = new Moves();
            var opponentArmies          = opponentTerritory.GetArmiesAfterDeploymentAndIncomingAttacks(conservativeLevel);
            var neededAttackArmies      = opponentTerritory.getNeededBreakArmies(opponentArmies.DefensePower);
            var ownedNeighbors          = opponentTerritory.GetOwnedNeighbors();
            var presortedOwnedNeighbors = state.TerritoryValueCalculator.SortDefenseValue(ownedNeighbors);
            var sortedOwnedNeighbors    = BotMap.GetOrderedListOfTerritoriesByIdleArmies(presortedOwnedNeighbors);
            var territoryToUse          = sortedOwnedNeighbors[0];
            var idleArmies              = territoryToUse.GetIdleArmies();
            var neededDeployment        = Math.Max(0, neededAttackArmies - idleArmies.AttackPower);

            if (neededDeployment > maxDeployment)
            {
                return(null);
            }

            if (neededDeployment > 0)
            {
                outvar.AddOrder(new BotOrderDeploy(state.Me.ID, territoryToUse, neededDeployment));
            }

            Armies attackArmies = new Armies(neededAttackArmies);

            //var atm = new BotOrderAttackTransfer(state.Me.ID, territoryToUse, opponentTerritory, idleArmies.Add(new Armies(neededDeployment)), "OneHitBreakTerritoryTask");
            var atm = new BotOrderAttackTransfer(state.Me.ID, territoryToUse, opponentTerritory, attackArmies, "OneHitBreakTerritoryTask");

            outvar.AddOrder(atm);
            return(outvar);
        }
コード例 #2
0
        private Moves CalculateAttackNeutralMoves(BotTerritory neutralTerritory, int maxDeployment)
        {
            Moves outvar             = null;
            var   neededAttackArmies = neutralTerritory.getNeededBreakArmies(neutralTerritory.Armies.DefensePower);
            var   ownedNeighbors     = neutralTerritory.GetOwnedNeighbors();
            var   bestNeighbor       = ownedNeighbors[0];

            foreach (var ownedNeighbor in ownedNeighbors)
            {
                if (ownedNeighbor.GetIdleArmies().AttackPower > bestNeighbor.GetIdleArmies().ArmiesOrZero)
                {
                    bestNeighbor = ownedNeighbor;
                }
            }
            var neededDeployment = Math.Max(0, neededAttackArmies - bestNeighbor.GetIdleArmies().ArmiesOrZero);

            if (neededDeployment <= maxDeployment)
            {
                outvar = new Moves();
                if (neededDeployment > 0)
                {
                    outvar.AddOrder(new BotOrderDeploy(BotState.Me.ID, bestNeighbor, neededDeployment));
                }

                var atm = new BotOrderAttackTransfer(BotState.Me.ID, bestNeighbor, neutralTerritory, new Armies(neededAttackArmies), "PreventOpponentExpandBonusTask");
                // TODO bad?
                if (bestNeighbor.GetOpponentNeighbors().Count == 0)
                {
                    atm.Message = AttackMessage.Snipe;
                }

                outvar.AddOrder(atm);
            }
            return(outvar);
        }
コード例 #3
0
        private Moves CalculateBreakTerritoryMoves(BotTerritory opponentTerritory, int maxDeployment, int opponentDeployment, string source)
        {
            var outvar         = new Moves();
            var opponentArmies = opponentTerritory.Armies.DefensePower;

            opponentArmies += opponentDeployment;
            var neededAttackArmies = opponentTerritory.getNeededBreakArmies(opponentArmies);
            //var neededAttackArmies = SharedUtility.Round(opponentArmies / BotState.Settings.OffensiveKillRate);
            var ownedNeighbors          = opponentTerritory.GetOwnedNeighbors();
            var presortedOwnedNeighbors = BotState.TerritoryValueCalculator.SortDefenseValue(ownedNeighbors);
            var sortedOwnedNeighbors    = BotMap.GetOrderedListOfTerritoriesByIdleArmies(
                presortedOwnedNeighbors);
            // First deploy and then pull in more territories if necessary.
            // First deploy and then pull in more territories if necessary.
            var attackedWithSoFar = 0;

            for (var i = 0; i < sortedOwnedNeighbors.Count; i++)
            {
                if (i == 0)
                {
                    var neededDeployment = Math.Max(0, neededAttackArmies - sortedOwnedNeighbors[0].GetIdleArmies().NumArmies);
                    var totalDeployment  = Math.Min(neededDeployment, maxDeployment);
                    if (totalDeployment > 0)
                    {
                        var pam = new BotOrderDeploy(BotState.Me.ID, sortedOwnedNeighbors[0], totalDeployment);
                        outvar.AddOrder(pam);
                    }
                    var attackingArmies = Math.Min(neededAttackArmies, sortedOwnedNeighbors[0].GetIdleArmies().NumArmies + totalDeployment);

                    outvar.AddOrder(new BotOrderAttackTransfer(BotState.Me.ID, sortedOwnedNeighbors[0], opponentTerritory, new Armies(attackingArmies), source));
                    attackedWithSoFar += attackingArmies;
                }
                else
                {
                    // i != 0
                    var stillNeededArmies = neededAttackArmies - attackedWithSoFar;
                    if (stillNeededArmies > 0 && sortedOwnedNeighbors[i].GetIdleArmies().NumArmies > 1)
                    {
                        var newAttackingArmies = Math.Min(stillNeededArmies, sortedOwnedNeighbors[i].GetIdleArmies().NumArmies);
                        outvar.AddOrder(new BotOrderAttackTransfer(BotState.Me.ID, sortedOwnedNeighbors[i], opponentTerritory, new Armies(newAttackingArmies), "BreakTerritoryTask2"));
                        attackedWithSoFar += newAttackingArmies;
                    }
                }
            }
            if (attackedWithSoFar >= neededAttackArmies)
            {
                return(outvar);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        private int GetMissingArmies(BotTerritory expandingTerritory, BotTerritory toBeTakenTerritory, Moves madeExpansionDecisions, BotTerritory.DeploymentType conservativeLevel)
        {
            var idleArmies = GetOverflowIdleArmies(expandingTerritory, madeExpansionDecisions);
            //var toBeTakenTerritoryArmies = toBeTakenTerritory.GetArmiesAfterDeploymentAndIncomingAttacks(conservativeLevel);
            var neededArmies = toBeTakenTerritory.getNeededBreakArmies(toBeTakenTerritory.Armies.DefensePower);

            if (idleArmies.AttackPower >= neededArmies)
            {
                return(0);
            }
            else
            {
                return(neededArmies - idleArmies.AttackPower);
            }
        }