/// <summary> /// Calculates the strategy when there are no enemy regions in this super region. /// </summary> /// <param name="superRegion">The super region.</param> /// <returns></returns> public bool CalculateForNoEnemies(SuperRegion superRegion) { Region targetRegion = null, sourceRegion = null; bool transferDone = false; var targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerAll); /* No neutral armies found in this super region, that should mean we own the continent. * Let's explore the world and go to a new super region * */ if (targetRegions.None()) { targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerOtherSuperRegions); if (targetRegions.Any()) { //We'll want to make more than 1 move foreach (var cTargetRegion in targetRegions) { sourceRegion = StrategyManager.GetSourceRegion(cTargetRegion, Transfers, SourceStrategy.DominateOtherSuperRegions); transferDone = AddCurrentPairToTransferList(sourceRegion, cTargetRegion); } } else { targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.EnemyInvasionPaths); targetRegion = targetRegions.FirstOrDefault(); if (targetRegion != null) { sourceRegion = StrategyManager.GetSourceRegion(targetRegion, Transfers, SourceStrategy.AttackEnemyInvasionPath); transferDone = AddCurrentPairToTransferList(sourceRegion, targetRegion); } } } // Neutral regions found in this super region else { StrategyManager.ConquerNeutralRegions(targetRegions, Transfers, SourceStrategy.DominateOtherSuperRegions); } return(transferDone); }
/// <summary> /// Calculates the strategy when there are enemy regions in the super region /// </summary> /// <param name="superRegion">The super region.</param> /// <returns></returns> public bool CalculateForEnemyRegions(SuperRegion superRegion) { Region targetRegion = null, sourceRegion = null; bool transferDone = false; var hostileRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.HostileRegions); if (hostileRegions.Any()) { foreach (var hostileRegion in hostileRegions) { int enemyArmies = hostileRegion.NbrOfArmies; /* Let's see if we can attack. There is 60% change per attacking army. * We will be extra safe and use a 50% chance. * This means we'll need at least double as much armies as our opponent. * If this isn't the case, we'll send more armies to this region and defend our grounds. * * */ var possibleAttackingRegion = Regions .Find(PlayerType.Me) .Where(region => region.Neighbours.Contains(hostileRegion)) .Where( region => (region.NbrOfArmies >= enemyArmies * 2 + 1 || region.NbrOfArmies > Configuration.Current.GetMaximumTreshold())) .OrderByDescending(region => region.NbrOfArmies) .FirstOrDefault(); //We can attack! if (possibleAttackingRegion != null) { targetRegion = hostileRegion; sourceRegion = possibleAttackingRegion; var nbrOfArmies = enemyArmies * 2; //If we're enclosed by ourself, attack with everything if (sourceRegion.Neighbours.Count(n => n.IsOccupiedBy(PlayerType.Me)) == sourceRegion.Neighbours.Count - 1) { nbrOfArmies = sourceRegion.NbrOfArmies - 1; } transferDone = transferDone || AddCurrentPairToTransferList(sourceRegion, targetRegion, nbrOfArmies); } /* We can't attack, so let's defend. * We'll send armies to the region that can be attacked with the least number of armies * We'll prefer sending from regions that can't be attacked. **/ else { targetRegion = hostileRegion .Neighbours .Find(PlayerType.Me) .Where(region => region.SuperRegion == superRegion) .OrderBy(region => region.NbrOfArmies) .FirstOrDefault(); if (targetRegion != null) { sourceRegion = targetRegion .Neighbours .Find(PlayerType.Me) .OrderByDescending(region => region.NbrOfArmies) .FirstOrDefault(); } else { //We can't defend a region, probably because we don't have armies nearby, so let's conquer some regions instead var targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerCurrentSuperRegion); StrategyManager.ConquerNeutralRegions(targetRegions, Transfers, SourceStrategy.DominateCurrentSuperRegion); } } } } /* * There is a hostile region in this super regio but we can not attack it * Maybe we dont have enough armies nearby * So lets try doing something else, like conquering neutral armies */ else { var targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerCurrentSuperRegion); StrategyManager.ConquerNeutralRegions(targetRegions, Transfers, SourceStrategy.DominateCurrentSuperRegion); } return(transferDone); }
/// <summary> /// Calculates the strategy when there are enemy border territories. /// </summary> /// <param name="superRegion">The super region.</param> /// <returns></returns> public bool CalculateForEnemyBorderTerritories(SuperRegion superRegion) { Region targetRegion = null, sourceRegion = null; bool transferDone = false; var invadingBorderTerritories = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.EnemyInvasionPaths); var invadingBorderTerritory = invadingBorderTerritories.FirstOrDefault(); if (invadingBorderTerritory != null) { int enemyArmies = invadingBorderTerritory.NbrOfArmies; /* Let's see if we can attack. There is 60% change per attacking army. * We will be extra safe and use a 50% chance. * This means we'll need at least double as much armies as our opponent. * If this isn't the case, we'll send more armies to this region and defend our grounds. * * */ var possibleAttackingRegion = superRegion .ChildRegions .Find(PlayerType.Me) .Where(region => region.Neighbours.Contains(invadingBorderTerritory)) .Where(region => (region.NbrOfArmies >= enemyArmies * 2 || region.NbrOfArmies > Configuration.Current.GetMaximumTreshold()) && region.NbrOfArmies > 5) .OrderByDescending(region => region.NbrOfArmies) .FirstOrDefault(); //We can attack! if (possibleAttackingRegion != null) { targetRegion = invadingBorderTerritory; sourceRegion = possibleAttackingRegion; } /* We can't attack, so let's defend. * We'll send armies to the region that can be attacked with the least number of armies * We'll prefer sending from regions that can't be attacked. **/ else { targetRegion = invadingBorderTerritory .Neighbours .Find(PlayerType.Me) .Where(region => region.SuperRegion == superRegion) .OrderBy(region => region.NbrOfArmies) .FirstOrDefault(); if (targetRegion != null) { // Dont transfer from regions that have enemy neighbours sourceRegion = targetRegion .Neighbours .Find(PlayerType.Me) .Where(region => region.Neighbours.None(neighbour => neighbour.IsOccupiedBy(PlayerType.Opponent))) .OrderByDescending(region => region.NbrOfArmies) .FirstOrDefault(); } } transferDone = AddCurrentPairToTransferList(sourceRegion, targetRegion); var targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerCurrentSuperRegion); StrategyManager.ConquerNeutralRegions(targetRegions, Transfers, SourceStrategy.DominateCurrentSuperRegion); } return(transferDone); }