private int GetOwnedTerritoriesValue(PlayerIDType playerId) { var ownedTerritories = MapInformer.GetOwnedTerritories(FinalStandings.Values.ToList(), playerId); int amountOwned = ownedTerritories.Count(); int value = amountOwned * TERRITORIES_MULTIPLICATOR; return(value); }
private TerritoryIDType GetBestAttackingTerritory(List <TerritoryIDType> takeTargets, MultiMoves presentMoves) { var currentGameStandings = presentMoves.GetTerritoryStandingsAfterAllMoves(); var ownedTerritories = MapInformer.GetOwnedTerritories(currentGameStandings.Values.ToList(), GameState.MyPlayerId); var possibleStartTerritories = new List <TerritoryStanding>(); foreach (var ownedTerritory in ownedTerritories) { List <TerritoryIDType> neighbors = MapInformer.GetNeighborTerritories(ownedTerritory.ID); var matchingNeighbors = neighbors.Where(n => takeTargets.Contains(n)).ToList(); if (matchingNeighbors.Count > 0) { possibleStartTerritories.Add(ownedTerritory); } } var bestStartTerritory = possibleStartTerritories.First(); var beginTurnStandings = GameState.CurrentTurn().LatestTurnStanding.Territories; foreach (var testTerritory in possibleStartTerritories) { bool bestTerritoryOwnedByMyself = beginTurnStandings[bestStartTerritory.ID].OwnerPlayerID == GameState.MyPlayerId; bool testTerritoryOwnedByMyself = beginTurnStandings[testTerritory.ID].OwnerPlayerID == GameState.MyPlayerId; // if one of them has no neighbors to take prefer the other one bool bestTerritoryCanContinue = MapInformer.GetNeighborTerritories(bestStartTerritory.ID).Where(n => takeTargets.Contains(n)).Count() > 0; bool testTerritoryCanContinue = MapInformer.GetNeighborTerritories(testTerritory.ID).Where(n => takeTargets.Contains(n)).Count() > 0; if (testTerritoryCanContinue && !bestTerritoryCanContinue) { bestStartTerritory = testTerritory; } // if both are already owned by myself at the beginning of the round prefer the one with more armies on it else if (bestTerritoryOwnedByMyself && testTerritoryOwnedByMyself) { if (testTerritory.NumArmies.ArmiesOrZero > bestStartTerritory.NumArmies.ArmiesOrZero) { bestStartTerritory = testTerritory; } } // if only one of them is owned by myself at the beginning of the round prefer the one not owned else if (bestTerritoryOwnedByMyself && !testTerritoryOwnedByMyself) { bestStartTerritory = testTerritory; } // if both aren't owned by myself at the beginning of the round prefer the one with the longer attack path else if (!bestTerritoryOwnedByMyself && !testTerritoryOwnedByMyself) { var bestPathCount = presentMoves.GetMovePath(bestStartTerritory.ID).Count(); var testPathCount = presentMoves.GetMovePath(testTerritory.ID).Count(); if (testPathCount > bestPathCount) { bestStartTerritory = testTerritory; } } } return(bestStartTerritory.ID); }
private int GetOwnedArmiesValue(PlayerIDType playerId) { var ownedTerritories = MapInformer.GetOwnedTerritories(FinalStandings.Values.ToList(), playerId); int amountArmiesOwned = 0; ownedTerritories.ForEach(o => amountArmiesOwned += o.NumArmies.ArmiesOrZero); int value = amountArmiesOwned * ARMIES_MULTIPLICATOR; return(value); }
private void AddBorderTerritoryDeployment(MultiMoves movesSoFar, int availableDeployment) { TerritoryStanding territoryToDeployTo = MapInformer.GetOwnedBorderTerritories(movesSoFar.GetTerritoryStandingsAfterAllMoves(), GameState.MyPlayerId).FirstOrDefault(); if (territoryToDeployTo == null) { territoryToDeployTo = MapInformer.GetOwnedTerritories(GameState.CurrentTurn().LatestTurnStanding.Territories.Values.ToList(), GameState.MyPlayerId).First(); } movesSoFar.AddDeployOrder(GameOrderDeploy.Create(GameState.MyPlayerId, availableDeployment, territoryToDeployTo.ID, REASON)); }
/* * 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 int GetClassification(GameOrderAttackTransfer attackMove) { var initialState = GameState.CurrentTurn().LatestTurnStanding.Territories; bool opponentAttack = initialState[attackMove.To].OwnerPlayerID == GameState.OpponentPlayerId; var attackFromNeighbors = MapInformer.GetNeighborTerritories(initialState[attackMove.From].ID); var opponentTerritories = MapInformer.GetOwnedTerritories(initialState.Values.ToList(), GameState.OpponentPlayerId); var opponentNeighboringAttack = false; foreach (var opponentTerritory in opponentTerritories) { if (attackFromNeighbors.Contains(opponentTerritory.ID)) { opponentNeighboringAttack = true; } } bool clearOpponentBreak = false; int opponentIncome = GameState.CurrentTurn().Incomes[GameState.OpponentPlayerId].FreeArmies; int maxOpponentArmies = 0; if (opponentAttack) { maxOpponentArmies = initialState[attackMove.To].NumArmies.ArmiesOrZero + opponentIncome; int maxNeededArmies = AttackInformer.GetNeededBreakArmies(maxOpponentArmies); if (attackMove.NumArmies.ArmiesOrZero >= maxNeededArmies) { clearOpponentBreak = true; } } bool isTransfer = initialState[attackMove.To].OwnerPlayerID == GameState.MyPlayerId; bool isExpansion = initialState[attackMove.To].IsNeutral; if (clearOpponentBreak) { return(1); } if (isTransfer) { return(2); } if (isExpansion && !opponentNeighboringAttack) { return(3); } if (isExpansion && opponentNeighboringAttack) { return(4); } // non clear opponent attacks return(5); }
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); }
private TerritoryIDType GetBestOwnTerritoryToMakeAttack(Dictionary <TerritoryIDType, TerritoryStanding> ownedNeighbors, TerritoryIDType territoryToTake, MultiMoves currentMoves) { TerritoryIDType bestNeighbor = ownedNeighbors.First().Key; foreach (TerritoryIDType territoryId in ownedNeighbors.Keys) { var attackMoves = currentMoves.AttackMoves.Where(o => o.From == bestNeighbor && o.To == territoryId).ToList(); if (attackMoves.Count > 0) { bestNeighbor = attackMoves.First().To; } } // if we have all neighbors already choose the one with the max armies var ownedTerritories = MapInformer.GetOwnedTerritories(GameState.CurrentTurn().LatestTurnStanding.Territories.Values.ToList(), GameState.MyPlayerId); bool allNeighborsOwnedAtStart = true; foreach (TerritoryIDType ownedNeighbor in ownedNeighbors.Keys) { if (ownedTerritories.Where(o => o.ID == ownedNeighbor).Count() == 0) { allNeighborsOwnedAtStart = false; break; } } if (allNeighborsOwnedAtStart) { var territoryStandings = currentMoves.GetTerritoryStandingsAfterAllMoves(); foreach (TerritoryIDType ownedNeighbor in ownedNeighbors.Keys) { if (territoryStandings[ownedNeighbor].NumArmies.ArmiesOrZero > territoryStandings[bestNeighbor].NumArmies.ArmiesOrZero) { bestNeighbor = ownedNeighbor; } } } return(bestNeighbor); }