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;
        }
Example #2
0
        private bool IsBonusAlreadyFlanked(BotBonus opponentBonus)
        {
            var flankedTerritories = new HashSet <BotTerritory>();

            foreach (var ownedNeighbor in opponentBonus.GetOwnedNeighborTerritories())
            {
                foreach (var opponentNeighbor in ownedNeighbor.GetOpponentNeighbors())
                {
                    if (opponentNeighbor.Details.PartOfBonuses.Contains(opponentBonus.ID))
                    {
                        flankedTerritories.Add(opponentNeighbor);
                    }
                }
            }

            return(flankedTerritories.Count >= 2 ? true : false);
        }
        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;
            }
        }
Example #4
0
        private bool IsPreventingUseful(BotMap visibleMap, BotMap movesMap, BotBonus bonus)
        {
            if (bonus.GetOwnedTerritoriesAndNeighbors().Count == 0)
            {
                return(false);
            }

            var mmBonus = movesMap.Bonuses[bonus.ID];

            if (mmBonus.GetOwnedTerritories().Count > 0)
            {
                return(false);
            }
            if (bonus.IsOwnedByAnyOpponent())
            {
                return(false);
            }
            if (bonus.GetOwnedNeighborTerritories().Count == 0)
            {
                return(false);
            }
            if (bonus.Amount < 2)
            {
                return(false);
            }
            if (bonus.NeutralArmies.DefensePower > 4)
            {
                return(false);
            }
            foreach (var neutralTerritory in bonus.NeutralTerritories)
            {
                if (neutralTerritory.GetOpponentNeighbors().Count == 0)
                {
                    return(false);
                }
            }

            return(true);
        }