public static Moves CalculateDefendBonusTask(BotMain state, BotBonus bonus, int maxDeployment, bool acceptNotAllDefense, BotTerritory.DeploymentType lowerConservativeLevel, BotTerritory.DeploymentType upperConservativeLevel) { var outvar = new Moves(); var threateningTerritories = GetThreateningTerritories(bonus); // First see if we can remove the threat by hitting the threatening // territory if (threateningTerritories.Count == 1) { var threatTerritory = threateningTerritories[0]; var territoriesUnderThreat = GetAmountOfTerritoriesUnderThreat(threatTerritory, bonus); if (territoriesUnderThreat >= 2 && lowerConservativeLevel != 0) { var removeThreatMoves = OneHitBreakTerritoryTask.CalculateBreakTerritoryTask(state, threatTerritory, maxDeployment, lowerConservativeLevel); if (removeThreatMoves != null) { removeThreatMoves.Orders.OfType <BotOrderAttackTransfer>().First().Message = AttackMessage.EarlyAttack; return(removeThreatMoves); } } } // If this is not possible try the classic defense var territoriesUnderThreat_1 = bonus.GetOwnedTerritoriesBorderingNeighborsOwnedByOpponent(); outvar = state.DefendTerritoriesTask.CalculateDefendTerritoriesTask(territoriesUnderThreat_1, maxDeployment, acceptNotAllDefense, lowerConservativeLevel, upperConservativeLevel); return(outvar); }
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; } }