private MultiMoves GetBreakBonusMoves(BonusIDType opponentBonus, MultiMoves presentMoves) { var bonusTerritories = GameState.Map.Bonuses[opponentBonus].Territories; var distances = MapInformer.GetDistancesFromTerritories(bonusTerritories); var ownedBorderTerritories = MapInformer.GetOwnedBorderTerritories(presentMoves.GetTerritoryStandingsAfterAllMoves(), GameState.MyPlayerId); int minDistance = ownedBorderTerritories.Min(o => distances[o.ID]); var bestStartTerritory = ownedBorderTerritories.Where(o => distances[o.ID] == minDistance).First(); int currentDistance = minDistance; var currentTerritoryInAttackPath = bestStartTerritory.ID; List <TerritoryIDType> territoriesToTake = new List <TerritoryIDType>(); while (currentDistance != 0) { var neighbors = MapInformer.GetNeighborTerritories(currentTerritoryInAttackPath); var possibleAttackNeighbors = neighbors.Where(n => distances[n] == currentDistance - 1).ToList(); var bestNeighborToAttack = GetBestNeighborToAttack(possibleAttackNeighbors); territoriesToTake.Add(bestNeighborToAttack); currentTerritoryInAttackPath = bestNeighborToAttack; currentDistance--; } TakeTerritoriesTask takeTerritoriesTask = new TakeTerritoriesTask(REASON); MultiMoves resultMoves = takeTerritoriesTask.CalculateTakeTerritoriesMoves(territoriesToTake, presentMoves); return(resultMoves); }
/* * private int GetAverageTerritoryDistance() * { * var opponentTerritories = MapInformer.GetOwnedTerritories(FinalStandings.Values.ToList(), GameState.OpponentPlayerId); * var opponentTerritoryIds = new List<TerritoryIDType>(); * opponentTerritories.ForEach(t => opponentTerritoryIds.Add(t.ID)); * var distances = MapInformer.GetDistancesFromTerritories(opponentTerritoryIds); * int territoryCount = 0; * int allDistances = 0; * foreach (int distance in distances.Values) * { * if (distance > 0) * { * territoryCount++; * allDistances += distance; * } * } * return allDistances / territoryCount; * } */ private int GetBonusDistanceMultiplicator(BonusDetails bonus) { var opponentTerritories = MapInformer.GetOwnedTerritories(FinalStandings.Values.ToList(), GameState.OpponentPlayerId); var opponentTerritoryIds = new List <TerritoryIDType>(); opponentTerritories.ForEach(t => opponentTerritoryIds.Add(t.ID)); if (distancesCache == null) { distancesCache = MapInformer.GetDistancesFromTerritories(opponentTerritoryIds); } int territoryCount = 0; int allDistances = 0; int bonusTerritoryCount = 0; int bonusTerritoryDistances = 0; foreach (var territory in distancesCache.Keys) { var distance = distancesCache[territory]; if (distance > 0) { territoryCount++; allDistances += distance; } if (bonus.Territories.Contains(territory)) { bonusTerritoryCount++; bonusTerritoryDistances += distancesCache[territory]; } } int averageDistance; if (territoryCount != 0) { averageDistance = allDistances / territoryCount; } else { averageDistance = 0; } int bonusAverageDistance = bonusTerritoryDistances / bonusTerritoryCount; int difference = bonusAverageDistance - averageDistance; int multiplicator; if (bonusAverageDistance >= 0) { multiplicator = Math.Min(difference, MAX_BONUS_DISTANCE_ADJUSTMENT); } else { multiplicator = Math.Max(difference, -MAX_BONUS_DISTANCE_ADJUSTMENT); } return(multiplicator + 100); }
private void ScheduleDeployMoves(MultiMoves multiMoves) { var deployMoves = multiMoves.DeployMoves; deployMoves = deployMoves.OrderBy(d => d.DeployOn.GetValue()).ToList(); var enemyTerritories = MapInformer.GetOwnedTerritories(GameState.CurrentTurn().LatestTurnStanding.Territories.Values.ToList(), GameState.OpponentPlayerId); var enemyTerritoryIds = new List <TerritoryIDType>(); enemyTerritories.ForEach(t => enemyTerritoryIds.Add(t.ID)); var distances = MapInformer.GetDistancesFromTerritories(enemyTerritoryIds); var opponentNeighboringDeployMoves = deployMoves.Where(d => distances[d.DeployOn] == 1); var nonOpponentNeighboringDeployMoves = deployMoves.Where(d => distances[d.DeployOn] > 1); multiMoves.DeployMoves.Clear(); multiMoves.DeployMoves.AddRange(opponentNeighboringDeployMoves); multiMoves.DeployMoves.AddRange(nonOpponentNeighboringDeployMoves); }