Exemplo n.º 1
0
        public static Moves CalculatePreventBonusTask(BotMain state, BotBonus bonusToPrevent, PlayerIDType opponentID, int maxDeployment, BotTerritory.DeploymentType conservativeLevel)
        {
            var territoriesToPrevent = bonusToPrevent.GetOwnedTerritories();

            var opponentAttacks = PreventTerritoriesTask.CalculateGuessedOpponentTakeOverMoves(state, territoriesToPrevent, opponentID, true, conservativeLevel);

            if (opponentAttacks == null)
            {
                return(new Moves());
            }

            var preventTerritoryMovesByDeploying = PreventTerritoriesTask.CalculatePreventTerritoriesTask(state, territoriesToPrevent, opponentID, maxDeployment, conservativeLevel);
            var visibleOpponentTerritories       = bonusToPrevent.GetVisibleOpponentTerritories();
            var breakBestTerritoryMoves          = NoPlanBreakBestTerritoryTask.CalculateNoPlanBreakBestTerritoryTask(state, maxDeployment, visibleOpponentTerritories, state.VisibleMap, state.WorkingMap, "PreventBonusTask");

            if (breakBestTerritoryMoves == null)
            {
                return(preventTerritoryMovesByDeploying);
            }
            else if (breakBestTerritoryMoves.GetTotalDeployment() <= preventTerritoryMovesByDeploying.GetTotalDeployment())
            {
                return(breakBestTerritoryMoves);
            }
            else
            {
                return(preventTerritoryMovesByDeploying);
            }
        }
        public static Moves CalculateNoPlanAttackBestTerritoryTask(BotMain state, int maxDeployment)
        {
            var outvar = new Moves();
            // If true attacks are possible then go with them
            // If true attacks are possible then go with them
            var sortedOpponentTerritories = state.TerritoryValueCalculator.GetSortedAttackValueTerritories();
            var territoriesToAttack       = NoPlanBreakBestTerritoryTask.RemoveTerritoriesThatWeTook
                                                (state, sortedOpponentTerritories);

            foreach (var territory in territoriesToAttack)
            {
                if (territory.IsVisible)
                {
                    var attackTerritoryMoves = AttackTerritoryTask.CalculateAttackTerritoryTask(state, territory, maxDeployment);
                    if (attackTerritoryMoves != null)
                    {
                        return(attackTerritoryMoves);
                    }

                    // If we can't truly attack then attack with 1's
                    var allowedSmallAttacks = territory.Armies.NumArmies - state.MustStandGuardOneOrZero;
                    allowedSmallAttacks -= GetAlreadyPresentSmallAttacks(territory);
                    foreach (var ownedNeighbor in territory.GetOwnedNeighbors())
                    {
                        if (allowedSmallAttacks > 0 && ownedNeighbor.GetIdleArmies().NumArmies > 0 && !IsTerritoryAlreadySmallAttackedFromOurTerritory(ownedNeighbor, territory))
                        {
                            var alreadyAttacksOpponent = false;
                            foreach (var atm in ownedNeighbor.OutgoingMoves)
                            {
                                if (atm.Armies.AttackPower > 1 && state.IsOpponent(atm.To.OwnerPlayerID))
                                {
                                    alreadyAttacksOpponent = true;
                                }
                            }

                            if (!alreadyAttacksOpponent)
                            {
                                var atm_1 = new BotOrderAttackTransfer(state.Me.ID, ownedNeighbor, territory, new Armies(1), "NoPlanAttackBestTerritoryTask");
                                outvar.AddOrder(atm_1);
                                allowedSmallAttacks--;
                            }
                        }
                    }
                    if (outvar.Orders.OfType <BotOrderAttackTransfer>().Any())
                    {
                        return(outvar);
                    }
                }
            }
            // If absolutely no attack possible then return null
            return(null);
        }