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; }
/// <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 = BotMain.LastVisibleMap.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; }