public static Moves CalculatePreventBonusTask(BotMain state, BotBonus bonusToPrevent, PlayerIDType opponentID, int maxDeployment, BotTerritory.DeploymentType conservativeLevel) { var territoriesToPrevent = bonusToPrevent.GetOwnedTerritories(); var opponentAttacks = PreventTerritoriesTask.CalculateGuessedOpponentTakeOverMoves(state, territoriesToPrevent, opponentID, true, conservativeLevel); if (opponentAttacks == null) { return(new Moves()); } var preventTerritoryMovesByDeploying = PreventTerritoriesTask.CalculatePreventTerritoriesTask(state, territoriesToPrevent, opponentID, maxDeployment, conservativeLevel); var visibleOpponentTerritories = bonusToPrevent.GetVisibleOpponentTerritories(); var breakBestTerritoryMoves = NoPlanBreakBestTerritoryTask.CalculateNoPlanBreakBestTerritoryTask(state, maxDeployment, visibleOpponentTerritories, state.VisibleMap, state.WorkingMap, "PreventBonusTask"); if (breakBestTerritoryMoves == null) { return(preventTerritoryMovesByDeploying); } else if (breakBestTerritoryMoves.GetTotalDeployment() <= preventTerritoryMovesByDeploying.GetTotalDeployment()) { return(breakBestTerritoryMoves); } else { return(preventTerritoryMovesByDeploying); } }
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; }
public Moves CalculatePreventOpponentExpandBonusTaskk(BotBonus bonusToPrevent, int maxDeployment, BotMap visibleMap, BotMap mapSoFar) { Moves outvar = null; if (!IsPreventingUseful(visibleMap, mapSoFar, bonusToPrevent)) { return(null); } // Step 1: Try to hit the opponent directly var possibleBreakTerritories = new List <BotTerritory>(); possibleBreakTerritories.AddRange(bonusToPrevent.GetVisibleOpponentTerritories()); outvar = BreakTerritoriesTask.CalculateBreakTerritoriesTask(BotState, possibleBreakTerritories, maxDeployment, BotTerritory.DeploymentType.Normal, BotTerritory.DeploymentType.Normal); if (outvar != null) { return(outvar); } // Step 2: Try to hit a neutral territory there var attackableNeutrals = new List <BotTerritory>(); attackableNeutrals.AddRange(bonusToPrevent.GetVisibleNeutralTerritories()); var sortedAttackableNeutrals = new List <BotTerritory>(); while (attackableNeutrals.Count != 0) { var bestNeutral = attackableNeutrals[0]; foreach (var neutral in attackableNeutrals) { if (neutral.AttackTerritoryValue > bestNeutral.AttackTerritoryValue) { bestNeutral = neutral; } } sortedAttackableNeutrals.Add(bestNeutral); attackableNeutrals.Remove(bestNeutral); } foreach (var attackableNeutral in sortedAttackableNeutrals) { var attackTerritoryMoves = CalculateAttackNeutralMoves(attackableNeutral, maxDeployment); if (attackTerritoryMoves != null) { return(attackTerritoryMoves); } } return(null); }
/// <summary> /// Calculates the needed moves to push the opponent out of a Bonus that has no neutrals in it. /// </summary> /// <param name="maxDeployment"></param> /// <param name="Bonus"></param> /// <returns></returns> public static Moves CalculateTakeBonusOverTask(BotMain state, int maxDeployment, BotBonus bonus, BotTerritory.DeploymentType conservativeLevel) { var opponentTerritories = bonus.GetVisibleOpponentTerritories(); return(state.TakeTerritoriesTaskCalculator.CalculateTakeTerritoriesTask(maxDeployment, opponentTerritories, conservativeLevel, "TakeBonusOverTask")); }