private void CalculateAttackValue(BotBonus bonus, BotMap mapToWriteIn)
        {
            var armiesReward                 = bonus.Amount;
            var ownedNeighbors               = bonus.GetOwnedNeighborTerritories();
            var amountOwnedNeighbors         = ownedNeighbors.Count;
            var territoriesUnderAttack       = bonus.GetVisibleOpponentTerritories();
            var amountTerritoriesUnderAttack = territoriesUnderAttack.Count;
            var opponentArmies               = 0;

            foreach (var opponentTerritory in territoriesUnderAttack)
            {
                opponentArmies += opponentTerritory.Armies.DefensePower;
            }
            var ownArmies = 0;

            foreach (var ownedNeighbor in ownedNeighbors)
            {
                ownArmies += ownedNeighbor.GetIdleArmies().AttackPower;
            }
            var opponentNeighbors = bonus.GetOpponentNeighbors().Count;
            var attackValue       = 0;

            attackValue += armiesReward * 10000;
            attackValue += opponentArmies * -1;
            attackValue += ownArmies * 3;
            attackValue += amountOwnedNeighbors * 100;
            attackValue += opponentNeighbors * 1;
            attackValue += amountTerritoriesUnderAttack * 1000;
            attackValue *= BonusAttackFactor;
            var bonusToWriteIn = mapToWriteIn.Bonuses[bonus.ID];

            bonusToWriteIn.AttackValue = attackValue;
        }
        private void CalculateDefenseValue(BotBonus bonus, BotMap mapToWriteIn)
        {
            var armiesReward = bonus.Amount;
            var opponentNeighborTerritories    = bonus.GetOpponentNeighbors();
            var opponentNeighbors              = opponentNeighborTerritories.Count;
            var territoriesUnderThreat         = bonus.GetOwnedTerritoriesBorderingNeighborsOwnedByOpponent();
            var amountOfTerritoriesUnderThreat = territoriesUnderThreat.Count;
            var opponentArmies = 0;

            foreach (var opponentNeighbor in opponentNeighborTerritories)
            {
                opponentArmies += opponentNeighbor.Armies.AttackPower;
            }

            var ownArmies = 0;

            foreach (var territoryUnderThread in territoriesUnderThreat)
            {
                ownArmies += territoryUnderThread.GetArmiesAfterDeploymentAndIncomingMoves().DefensePower;
            }

            var ownedNeighborTerritories = bonus.GetOwnedNeighborTerritories().Count;
            var amountTerritories        = bonus.Territories.Count;
            var defenseValue             = 0;

            defenseValue += armiesReward * 10000;
            defenseValue += opponentArmies * -10;
            defenseValue += ownArmies * 10;
            defenseValue += ownedNeighborTerritories * 1;
            defenseValue += opponentNeighbors * -100;
            defenseValue += amountOfTerritoriesUnderThreat * -1000;
            defenseValue += amountTerritories * -1;
            defenseValue *= BonusDefenseFactor;
            var bonusToWriteIn = mapToWriteIn.Bonuses[bonus.ID];

            bonusToWriteIn.DefenseValue = defenseValue;
            // TODO hack so Bonuses we are taking this turn don't already get a defense value of > 0
            if (!BotState.VisibleMap.Bonuses[bonus.ID].IsOwnedByMyself())
            {
                bonusToWriteIn.DefenseValue = -1;
            }
        }
        private void CalculateTakeOverValue(BotBonus bonus, BotMap mapToWriteIn)
        {
            var armiesReward              = bonus.Amount;
            var opponentTerritories       = bonus.GetOpponentTerritories();
            var amountOpponentTerritories = opponentTerritories.Count;
            var opponentArmies            = 0;

            foreach (var opponentTerritory in opponentTerritories)
            {
                opponentArmies += opponentTerritory.Armies.DefensePower;
            }

            var possibleAttackTerritories = new HashSet <BotTerritory>();

            foreach (var opponentTerritory_1 in opponentTerritories)
            {
                possibleAttackTerritories.AddRange(opponentTerritory_1.GetOwnedNeighbors());
            }

            var ownArmies = 0;

            foreach (var possibleAttackTerritory in possibleAttackTerritories)
            {
                ownArmies += possibleAttackTerritory.GetIdleArmies().AttackPower;
            }

            var amountTerritories = bonus.Territories.Count;
            var opponentNeighbors = bonus.GetOpponentNeighbors().Count;
            var takeOverValue     = 0;

            takeOverValue += armiesReward * 10000;
            takeOverValue += opponentArmies * -10;
            takeOverValue += ownArmies * 10;
            takeOverValue += opponentNeighbors * -1;
            takeOverValue += amountOpponentTerritories * -1000;
            takeOverValue += amountTerritories * -1;
            takeOverValue *= BonusTakeOverFactor;
            mapToWriteIn.Bonuses[bonus.ID].TakeOverValue = takeOverValue;
        }
Exemple #4
0
        public void CalculateExpansionMoves(Moves moves)
        {
            var armiesForExpansion = Math.Min(BotState.Settings.MinimumArmyBonus, BotState.MyIncome.Total - moves.GetTotalDeployment());
            var armiesForTakeOver  = BotState.MyIncome.Total - moves.GetTotalDeployment();

            if (BotState.VisibleMap.GetOpponentBorderingTerritories().Count == 0)
            {
                armiesForExpansion = BotState.MyIncome.Total - moves.GetTotalDeployment();
            }

            AddValueToImmediateBonuses(armiesForTakeOver);
            var sortedAccessibleBonuses = BotState.BonusExpansionValueCalculator.SortAccessibleBonuses(BotState.VisibleMap);
            var bonusesThatCanBeTaken   = GetBonusesThatCanBeTaken(armiesForTakeOver);
            var takenOverBonuses        = new List <BotBonus>();
            var armiesUsedForTakeOver   = 0;

            // calculate the moves for the bonuses that can be immediately taken
            foreach (var bonus in sortedAccessibleBonuses)
            {
                if (bonusesThatCanBeTaken.Contains(bonus))
                {
                    var expansionMoves = BotState.TakeTerritoriesTaskCalculator.CalculateTakeTerritoriesTask(armiesForTakeOver, bonus.GetNotOwnedTerritories(), BotTerritory.DeploymentType.Normal, "MovesCalculator.CalculateExpansionMoves");
                    MovesCommitter.CommittMoves(BotState, expansionMoves);
                    moves.MergeMoves(expansionMoves);
                    armiesForTakeOver    -= expansionMoves.GetTotalDeployment();
                    bonusesThatCanBeTaken = GetBonusesThatCanBeTaken(armiesForTakeOver);
                    takenOverBonuses.Add(bonus);
                    armiesUsedForTakeOver += expansionMoves.GetTotalDeployment();
                }
                else
                {
                    break;
                }
            }


            var isExpandingAfterTakeOverSmart = IsExpandingAfterTakeOverSmart();


            var opponentBorderPresent = BotState.VisibleMap.GetOpponentBorderingTerritories().Count > 0;

            armiesForExpansion = Math.Max(0, armiesForExpansion - armiesUsedForTakeOver);
            if (takenOverBonuses.Count == 0 || isExpandingAfterTakeOverSmart)
            {
                BotBonus bonusToExpand = null;
                foreach (var bonus in sortedAccessibleBonuses)
                {
                    if (!takenOverBonuses.Contains(bonus))
                    {
                        var condition1 = bonus.GetVisibleNeutralTerritories().Count > 0;
                        var condition2 = bonus.Amount > 0;
                        var condition3 = !opponentBorderPresent || bonus.ExpansionValueCategory > 0;
                        if (condition1 && condition2 && condition3)
                        {
                            bonusToExpand = bonus;
                            break;
                        }
                    }
                }
                if (bonusToExpand == null)
                {
                    return;
                }
                var foundMoves = true;
                var firstStep  = true;
                while (foundMoves)
                {
                    BotState.BonusValueCalculator.CalculateBonusValues(BotState.WorkingMap, BotState.VisibleMap);
                    foundMoves = false;
                    if (firstStep == false)
                    {
                        if (bonusToExpand.ExpansionValueCategory == 0)
                        {
                            return;
                        }
                        if (opponentBorderPresent)
                        {
                            armiesForExpansion = 0;
                        }
                        if (bonusToExpand.GetOpponentNeighbors().Count > 0)
                        {
                            return;
                        }
                    }
                    Moves oneStepMoves = null;
                    if (!opponentBorderPresent)
                    {
                        oneStepMoves = BotState.TakeTerritoriesTaskCalculator.CalculateOneStepExpandBonusTask(armiesForExpansion, bonusToExpand, true, BotState.WorkingMap, BotTerritory.DeploymentType.Normal);
                    }
                    else
                    {
                        oneStepMoves = BotState.TakeTerritoriesTaskCalculator.CalculateOneStepExpandBonusTask(armiesForExpansion, bonusToExpand, false, BotState.WorkingMap, BotTerritory.DeploymentType.Normal);
                    }

                    if (oneStepMoves != null)
                    {
                        firstStep           = false;
                        armiesForExpansion -= oneStepMoves.GetTotalDeployment();
                        MovesCommitter.CommittMoves(BotState, oneStepMoves);
                        moves.MergeMoves(oneStepMoves);
                        foundMoves = true;
                    }
                }
            }
        }