private static BotTerritory GetCloserTerritory(BotTerritory territory1, BotTerritory territory2) { if (GetAdjustedDistance(territory1) < GetAdjustedDistance(territory2)) { return(territory1); } else if (GetAdjustedDistance(territory2) < GetAdjustedDistance(territory1)) { return(territory2); } if (territory1.DistanceToImportantOpponentBorder < territory2.DistanceToImportantOpponentBorder) { return(territory1); } else if (territory2.DistanceToImportantOpponentBorder < territory1.DistanceToImportantOpponentBorder) { return(territory2); } if (territory1.DistanceToOpponentBorder < territory2.DistanceToOpponentBorder) { return(territory1); } else if (territory2.DistanceToOpponentBorder < territory1.DistanceToOpponentBorder) { return(territory2); } if (territory1.DistanceToHighlyImportantSpot < territory2.DistanceToHighlyImportantSpot) { return(territory1); } else if (territory2.DistanceToHighlyImportantSpot < territory1.DistanceToHighlyImportantSpot) { return(territory2); } if (territory1.DistanceToImportantSpot < territory2.DistanceToImportantSpot) { return(territory1); } else if (territory2.DistanceToImportantSpot < territory1.DistanceToImportantSpot) { return(territory2); } if (territory1.GetArmiesAfterDeploymentAndIncomingMoves().AttackPower > territory2.GetArmiesAfterDeploymentAndIncomingMoves().AttackPower) { return(territory1); } else if (territory2.GetArmiesAfterDeploymentAndIncomingMoves().AttackPower > territory1.GetArmiesAfterDeploymentAndIncomingMoves().AttackPower) { return(territory2); } // Prefer territory2 by default since the initial territory is territory1 so we move more return(territory2); }
private bool CanOpponentGetAGoodAttack(BotTerritory ourTerritory) { var oppNeighbors = ourTerritory.GetOpponentNeighbors(); if (oppNeighbors.Count == 0) { return(false); } foreach (var group in oppNeighbors.GroupBy(o => o.OwnerPlayerID)) { var opponentIncome = BotState.GetGuessedOpponentIncome(group.Key, BotState.VisibleMap); var ourArmies = ourTerritory.GetArmiesAfterDeploymentAndIncomingMoves(); var opponentAttackingArmies = opponentIncome; foreach (var opponentNeighbor in group) { opponentAttackingArmies += opponentNeighbor.Armies.AttackPower - BotState.MustStandGuardOneOrZero; } if (Math.Round(opponentAttackingArmies * BotState.Settings.OffensiveKillRate) >= Math.Round(ourArmies.DefensePower * BotState.Settings.DefensiveKillRate)) { return(true); } } return(false); }
private Moves CalculateDefendTerritoryMoves(BotTerritory territoryToDefend, int maxDeployment, bool useBackgroundArmies, int step, BotTerritory.DeploymentType lowerConservativeLevel, BotTerritory.DeploymentType upperConservativeLevel) { var outvar = new Moves(); var maxAttackingArmies = 0; var currentDeployment = 0; foreach (var opponentNeighbor in territoryToDefend.GetOpponentNeighbors()) { currentDeployment += opponentNeighbor.GetTotalDeployment(lowerConservativeLevel); var opponentArmies = opponentNeighbor.GetArmiesAfterDeployment(lowerConservativeLevel).AttackPower; var upperOpponentArmies = opponentNeighbor.GetArmiesAfterDeployment(upperConservativeLevel).AttackPower; var deploymentDifference = upperOpponentArmies - opponentArmies; for (var i = 0; i < step; i++) { if (deploymentDifference > 0) { deploymentDifference--; opponentArmies++; currentDeployment++; } } var idleArmies = opponentArmies - 1; maxAttackingArmies += idleArmies; } // Adjust stuff so opponent can't deploy eyerything to every territory var maxOpponentDeployment = territoryToDefend.GetOpponentNeighbors().Select(o => o.OwnerPlayerID).Distinct().Max(o => BotState.GetGuessedOpponentIncome(o, BotState.VisibleMap)); var deploymentDifference_1 = maxOpponentDeployment - currentDeployment; maxAttackingArmies -= deploymentDifference_1; var opponentKills = SharedUtility.Round(maxAttackingArmies * BotState.Settings.OffenseKillRate); var ownArmies = territoryToDefend.GetArmiesAfterDeploymentAndIncomingMoves().DefensePower; var missingArmies = Math.Max(0, opponentKills - ownArmies + 1); // First try to pull in more armies if (missingArmies > 0 && useBackgroundArmies) { var neighborsWithIdleArmies = GetNeighborsWithIdleArmies(territoryToDefend); foreach (var neighbor in neighborsWithIdleArmies) { var armiesToTransfer = Math.Min(missingArmies, neighbor.GetIdleArmies().NumArmies); if (armiesToTransfer > 0) { outvar.AddOrder(new BotOrderAttackTransfer(BotState.Me.ID, neighbor, territoryToDefend, new Armies(armiesToTransfer), "DefendTerritoryTask")); missingArmies -= armiesToTransfer; } } } // Then try to deploy if (missingArmies <= maxDeployment && missingArmies > 0) { outvar.AddOrder(new BotOrderDeploy(BotState.Me.ID, territoryToDefend, missingArmies)); } else if (missingArmies > maxDeployment) { return(null); } return(outvar); }
public static Moves CalculatePreventTerritoriesTask(BotMain state, List <BotTerritory> territoriesToPrevent, PlayerIDType opponentID, int maxDeployment, BotTerritory.DeploymentType conservativeLevel) { var outvar = new Moves(); if (territoriesToPrevent.Count == 0) { return(outvar); } var opponentAttacks = CalculateGuessedOpponentTakeOverMoves(state, territoriesToPrevent, opponentID, true, conservativeLevel); if (opponentAttacks == null) { return(outvar); } // Just try to prevent the territory with the highest defense territory value var highestDefenceTerritoryValue = 0d; BotTerritory highestDefenceValueTerritory = null; foreach (var territory in territoriesToPrevent) { if (territory.OwnerPlayerID == state.Me.ID && territory.DefenceTerritoryValue >= highestDefenceTerritoryValue) { highestDefenceValueTerritory = territory; highestDefenceTerritoryValue = territory.DefenceTerritoryValue; } } var currentArmies = highestDefenceValueTerritory.GetArmiesAfterDeploymentAndIncomingMoves().DefensePower; var attackingArmies = CalculateOpponentAttackingArmies(highestDefenceValueTerritory, opponentAttacks); var minimumNeededArmies = SharedUtility.Round(attackingArmies.AttackPower * state.Settings.OffensiveKillRate); //var minimumNeededArmies = SharedUtility.Round(attackingArmies.AttackPower * state.Settings.OffensiveKillRate); var maximumNeededArmies = minimumNeededArmies; var maximumMissingArmies = Math.Max(0, maximumNeededArmies - currentArmies); var minimumMissingArmies = Math.Max(0, minimumNeededArmies - currentArmies); if (maximumMissingArmies <= maxDeployment && maximumMissingArmies > 0) { outvar.AddOrder(new BotOrderDeploy(state.Me.ID, highestDefenceValueTerritory, maximumMissingArmies)); } else if (minimumMissingArmies <= maxDeployment && maxDeployment > 0) { outvar.AddOrder(new BotOrderDeploy(state.Me.ID, highestDefenceValueTerritory, maxDeployment)); } // If no solution then empty moves instead of null return(outvar); }