public Moves CalculateOneStepExpandBonusTask(int maxDeployment, BotBonus bonus, bool acceptStackOnly, BotMap workingMap, BotTerritory.DeploymentType conservativeLevel)
        {
            var outvar = new Moves();

            if (maxDeployment == -1)
            {
                maxDeployment = 1000;
            }

            var visibleNeutralTerritories = bonus.GetVisibleNeutralTerritories();
            var territoriesToRemove       = new List <BotTerritory>();

            foreach (var territory in visibleNeutralTerritories)
            {
                if (workingMap.Territories[territory.ID].OwnerPlayerID == BotState.Me.ID)
                {
                    territoriesToRemove.Add(territory);
                }
            }

            visibleNeutralTerritories.RemoveAll(territoriesToRemove);
            if (visibleNeutralTerritories.Count == 0)
            {
                return(null);
            }

            var sortedNeutralTerritories = BotState.TerritoryValueCalculator.SortExpansionValue(visibleNeutralTerritories);
            var territoryToTake          = new List <BotTerritory>();

            territoryToTake.Add(sortedNeutralTerritories[0]);
            var takeTerritoryMoves = CalculateTakeTerritoriesTask(-1, territoryToTake, conservativeLevel, "CalculateOneStepExpandBonusTask");

            if (takeTerritoryMoves.GetTotalDeployment() > maxDeployment)
            {
                if (acceptStackOnly)
                {
                    if (maxDeployment > 0)
                    {
                        var territoryToDeploy = takeTerritoryMoves.Orders.OfType <BotOrderDeploy>().First().Territory;
                        var pam = new BotOrderDeploy(BotState.Me.ID, territoryToDeploy, maxDeployment);
                        outvar.AddOrder(pam);
                        return(outvar);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                outvar = takeTerritoryMoves;
                return(outvar);
            }
        }
Exemple #2
0
        public Moves CalculatePreventOpponentExpandBonusTaskk(BotBonus bonusToPrevent, int maxDeployment, BotMap visibleMap, BotMap mapSoFar)
        {
            Moves outvar = null;

            if (!IsPreventingUseful(visibleMap, mapSoFar, bonusToPrevent))
            {
                return(null);
            }

            // Step 1: Try to hit the opponent directly
            var possibleBreakTerritories = new List <BotTerritory>();

            possibleBreakTerritories.AddRange(bonusToPrevent.GetVisibleOpponentTerritories());
            outvar = BreakTerritoriesTask.CalculateBreakTerritoriesTask(BotState, possibleBreakTerritories, maxDeployment, BotTerritory.DeploymentType.Normal, BotTerritory.DeploymentType.Normal);
            if (outvar != null)
            {
                return(outvar);
            }
            // Step 2: Try to hit a neutral territory there
            var attackableNeutrals = new List <BotTerritory>();

            attackableNeutrals.AddRange(bonusToPrevent.GetVisibleNeutralTerritories());
            var sortedAttackableNeutrals = new List <BotTerritory>();

            while (attackableNeutrals.Count != 0)
            {
                var bestNeutral = attackableNeutrals[0];
                foreach (var neutral in attackableNeutrals)
                {
                    if (neutral.AttackTerritoryValue > bestNeutral.AttackTerritoryValue)
                    {
                        bestNeutral = neutral;
                    }
                }
                sortedAttackableNeutrals.Add(bestNeutral);
                attackableNeutrals.Remove(bestNeutral);
            }
            foreach (var attackableNeutral in sortedAttackableNeutrals)
            {
                var attackTerritoryMoves = CalculateAttackNeutralMoves(attackableNeutral, maxDeployment);
                if (attackTerritoryMoves != null)
                {
                    return(attackTerritoryMoves);
                }
            }
            return(null);
        }