コード例 #1
0
        private void CalculateDefenseTerritoryValue(BotTerritory territory, BotMap mapToWriteIn)
        {
            var currentValue = 0;

            // Add 1000 to the value for each bordering own Bonus
            currentValue += LOWEST_MEDIUM_PRIORITY_VALUE * territory.GetAmountOfBordersToOwnBonus
                                ();
            // Add 1000 to the value for each bordering opponent Bonus
            currentValue += LOWEST_MEDIUM_PRIORITY_VALUE * territory.GetAmountOfBordersToOpponentBonus
                                ();
            // Add up to 30 to the armies reward for being close to an opponent Bonus
            if (territory.DistanceToOpponentBonus == 1)
            {
                currentValue += 30;
            }
            else if (territory.DistanceToOpponentBonus == 2)
            {
                currentValue += 20;
            }
            else if (territory.DistanceToOpponentBonus == 3)
            {
                currentValue += 10;
            }

            // Add up to 30 to the armies reward for being close to an own Bonus
            if (territory.DistanceToOwnBonus == 1)
            {
                currentValue += 30;
            }
            else if (territory.DistanceToOwnBonus == 2)
            {
                currentValue += 20;
            }
            else if (territory.DistanceToOwnBonus == 3)
            {
                currentValue += 10;
            }


            foreach (var vmBonus in territory.Bonuses)
            {
                // Add 100.000 * armies reward to the value if it's a spot in an owned Bonus
                if (vmBonus.IsOwnedByMyself())
                {
                    currentValue += LOWEST_HIGH_PRIORITY_VALUE * vmBonus.Amount;
                }
                // Add 100.000 * armies reward to the value if it's the only spot in an opponent Bonus
                if (vmBonus.IsOwnedByAnyOpponent())
                {
                    currentValue += LOWEST_HIGH_PRIORITY_VALUE * vmBonus.Amount;
                }

                // Add 10 - the amount of neutrals in the Bonus
                currentValue += Math.Max(0, 10 - vmBonus.NeutralArmies.DefensePower);
                // Add stuff if it's the most important Bonus
                var isMostImportantBonus = true;

                // vmBonus.setMyExpansionValueHeuristic();
                // vmBonus.setMyExpansionValueHeuristic();
                var bonusExpansionValue = vmBonus.ExpansionValue;
                foreach (var bonus in BotState.VisibleMap.Bonuses.Values)
                {
                    if (bonus.ExpansionValue > bonusExpansionValue)
                    {
                        isMostImportantBonus = false;
                    }
                }
                if (isMostImportantBonus && vmBonus.Amount > 0 && !vmBonus
                    .IsOwnedByMyself() && !vmBonus.ContainsOpponentPresence() && vmBonus.NeutralArmies.DefensePower < 8)
                {
                    currentValue += 1;
                }
            }
            currentValue *= DEFENSE_ADJUSTMENT_FACTOR;
            var territoryToWriteIn = mapToWriteIn.Territories[territory.ID];

            territoryToWriteIn.DefenceTerritoryValue = currentValue;
        }
コード例 #2
0
        public static List <BotTerritory> GetShortestPathToTerritories(BotMap mapToUse, BotTerritory fromTerritory, List <BotTerritory> toTerritories, List <BotTerritory> blockedTerritories)
        {
            List <BotTerritory> outvar = new List <BotTerritory>();
            var annotatedTerritories   = CalculateDistances(mapToUse, toTerritories, blockedTerritories);

            outvar.Add(fromTerritory);
            var currentTerritory = fromTerritory;
            var currentDistance  = annotatedTerritories[fromTerritory];

            while (currentDistance != 0)
            {
                var closestNeighbor = GetClosestNeighborToTargetTerritories(currentTerritory, annotatedTerritories, blockedTerritories);
                outvar.Add(closestNeighbor);
                currentTerritory = closestNeighbor;
                currentDistance  = annotatedTerritories[closestNeighbor];
            }
            return(outvar);
        }
コード例 #3
0
        /// <remarks>Calculates the attack territory values.</remarks>
        /// <param name="territory">allowed are neutral and opponent territories</param>
        public void CalculateAttackTerritoryValue(BotTerritory territory, BotMap mapToWriteIn
                                                  )
        {
            var currentValue = 0;

            // Add 100.000 * armies reward to the value if it's a spot in an
            // opponent Bonus
            if (territory.Bonuses.Any(o => o.IsOwnedByAnyOpponent()))
            {
                currentValue += LOWEST_HIGH_PRIORITY_VALUE * territory.Bonuses.Sum(o => o.Amount);
            }
            // Add 1000 to the value for each bordering own Bonus
            currentValue += territory.AttackTerritoryValue + LOWEST_MEDIUM_PRIORITY_VALUE * territory.GetAmountOfBordersToOwnBonus();
            // Add 1000 to the value for each bordering opponent Bonus
            currentValue += LOWEST_MEDIUM_PRIORITY_VALUE * territory.GetAmountOfBordersToOpponentBonus();

            foreach (var bonus in territory.Bonuses)
            {
                // Add 1000 * armies reward for the opponent having all but one neutral spot in the Bonus
                var neutralArmiesInBonus     = bonus.NeutralArmies.DefensePower;
                var amountOfOwnedTerritories = bonus.GetOwnedTerritories().Count;
                if (amountOfOwnedTerritories == 0 && neutralArmiesInBonus <= 2 && neutralArmiesInBonus > 0)
                {
                    currentValue += bonus.Amount * LOWEST_MEDIUM_PRIORITY_VALUE;
                }
            }

            // Add up to 30 to the armies reward for being close to an opponent
            // Bonus
            if (territory.DistanceToOpponentBonus == 1)
            {
                currentValue += 30;
            }
            else if (territory.DistanceToOpponentBonus == 2)
            {
                currentValue += 20;
            }
            else if (territory.DistanceToOpponentBonus == 3)
            {
                currentValue += 10;
            }

            // Add up to 30 to the armies reward for being close to an own bonus
            if (territory.DistanceToOwnBonus == 1)
            {
                currentValue += 30;
            }
            else if (territory.DistanceToOwnBonus == 2)
            {
                currentValue += 20;
            }
            else if (territory.DistanceToOwnBonus == 3)
            {
                currentValue += 10;
            }

            // Add 1 to the value for each opponent bordering territory
            currentValue += 1 * territory.GetOpponentNeighbors().Count;

            foreach (var vmBonus in territory.Bonuses)
            {
                // Add 10 - the amount of neutrals in the Bonus
                currentValue += Math.Max(0, 10 - vmBonus.NeutralArmies.DefensePower);


                // Add stuff if the opponent seems to currently expand in that Bonus
                if (BotState.NumberOfTurns > 0 && vmBonus.GetOwnedTerritories().Count == 0 && vmBonus.Amount > 0 && !vmBonus.IsOwnedByAnyOpponent())
                {
                    var opponentIsExpanding = false;
                    foreach (var opponentTerritory in vmBonus.GetVisibleOpponentTerritories())
                    {
                        var lwmTerritory = BotState.LastVisibleMapX.Territories[opponentTerritory.ID];
                        if (lwmTerritory.IsVisible && lwmTerritory.OwnerPlayerID == TerritoryStanding.NeutralPlayerID)
                        {
                            opponentIsExpanding = true;
                        }
                    }
                    if (opponentIsExpanding)
                    {
                        if (vmBonus.NeutralArmies.DefensePower <= 2)
                        {
                            currentValue += vmBonus.Amount * 30;
                        }
                        else if (vmBonus.NeutralArmies.DefensePower <= 4)
                        {
                            currentValue += vmBonus.Amount * 10;
                        }
                        else
                        {
                            currentValue += vmBonus.Amount * 5;
                        }
                    }
                }
            }

            currentValue *= ATTACK_ADJUSTMENT_FACTOR;
            mapToWriteIn.Territories[territory.ID].AttackTerritoryValue = currentValue;
        }
コード例 #4
0
        private static BotTerritory GetOpponentNeighborMaxIdleArmies(BotMain state, PlayerIDType opponentID, BotTerritory ownedTerritory, Moves alreadyMadeAttacks)
        {
            var opponentNeighbors = ownedTerritory.Neighbors.Where(o => o.OwnerPlayerID == opponentID).ToList();

            if (opponentNeighbors.Count == 0)
            {
                return(null);
            }

            var maxIdleArmiesTerritory = opponentNeighbors[0];
            var maxIdleArmies          = CalculateStillOpponentIdleArmies(state, maxIdleArmiesTerritory, alreadyMadeAttacks);

            foreach (var territory in opponentNeighbors)
            {
                var idleArmies = CalculateStillOpponentIdleArmies(state, territory, alreadyMadeAttacks);
                if (idleArmies.AttackPower > maxIdleArmies.AttackPower)
                {
                    maxIdleArmies          = idleArmies;
                    maxIdleArmiesTerritory = territory;
                }
            }
            return(maxIdleArmiesTerritory);
        }
コード例 #5
0
ファイル: Tree.cs プロジェクト: JustinReiter/WarLight.AI
 public NaryTree(BotTerritory root)
 {
     this.root = new Node(root);
 }
コード例 #6
0
        private static bool IsTerritoryAlreadySmallAttackedFromOurTerritory(BotTerritory ourTerritory, BotTerritory opponentTerritory)
        {
            var alreadySmallAttacked = false;

            foreach (var atm in ourTerritory.OutgoingMoves)
            {
                if (atm.Armies.AttackPower == 1 && atm.To.ID == opponentTerritory.ID)
                {
                    alreadySmallAttacked = true;
                }
            }
            return(alreadySmallAttacked);
        }
コード例 #7
0
        private static List <BotTerritory> GetOwnedNeighborsAfterExpansion(BotMain state, BotTerritory ourTerritory)
        {
            List <BotTerritory> outvar = new List <BotTerritory>();
            var emOurTerritory         = state.ExpansionMap.Territories[ourTerritory.ID];
            var emOwnedNeighbors       = emOurTerritory.GetOwnedNeighbors();

            foreach (var emOwnedNeighbor in emOwnedNeighbors)
            {
                outvar.Add(state.VisibleMap.Territories[emOwnedNeighbor.ID]);
            }
            return(outvar);
        }
コード例 #8
0
 public BotOrderDeploy(PlayerIDType playerID, BotTerritory territory, int armies)
 {
     this.PlayerID  = playerID;
     this.Territory = territory;
     this.Armies    = armies;
 }