Beispiel #1
0
        private TerritoryIDType GetBestAttackTerritory(List <TerritoryIDType> immediateTakeTargets, List <TerritoryIDType> allTakeTargets, TerritoryIDType attackingTerritory, MultiMoves presentMoves)
        {
            List <TerritoryIDType> borderingTargets = immediateTakeTargets.Where(t => MapInformer.GetNeighborTerritories(t).Contains(attackingTerritory)).ToList();

            // We prefer territories with a as little neighboring territories in the takeTargets as possible
            var bestAttackTerritory = borderingTargets.First();

            foreach (var testAttackTerritory in borderingTargets)
            {
                var bestAttackTerritoryNeighborCount = MapInformer.GetNeighborTerritories(bestAttackTerritory).Where(t => allTakeTargets.Contains(t)).Count();
                var testAttackTerritoryNeighborCount = MapInformer.GetNeighborTerritories(testAttackTerritory).Where(t => allTakeTargets.Contains(t)).Count();
                if (testAttackTerritoryNeighborCount < bestAttackTerritoryNeighborCount)
                {
                    bestAttackTerritory = testAttackTerritory;
                }
                else if (testAttackTerritoryNeighborCount == bestAttackTerritoryNeighborCount)
                {
                    // If both have the same amount we prefer territories with as little unowned neighbors as possible
                    var bestUnownedNeighborCount = MapInformer.GetNonOwnedNeighborTerritories(bestAttackTerritory, presentMoves.GetTerritoryStandingsAfterAllMoves()).Count();
                    var testUnownedNeighborCount = MapInformer.GetNonOwnedNeighborTerritories(testAttackTerritory, presentMoves.GetTerritoryStandingsAfterAllMoves()).Count();
                    if (testUnownedNeighborCount < bestUnownedNeighborCount)
                    {
                        bestAttackTerritory = testAttackTerritory;
                    }
                }
            }
            return(bestAttackTerritory);
        }
Beispiel #2
0
        private int GetNonOwnedNeighborTerritoryCount
            (TerritoryIDType territory, List <TerritoryIDType> territoryRange, Dictionary <TerritoryIDType, TerritoryStanding> territoryStandings)
        {
            var nonOwnedNeighborTerritories = MapInformer.GetNonOwnedNeighborTerritories(territory, territoryStandings).Keys.ToList();

            nonOwnedNeighborTerritories.RemoveWhere(t => !territoryRange.Contains(t));
            return(nonOwnedNeighborTerritories.Count());
        }
        private List <TerritoryIDType> GetNonOwnedBonusTerritoriesToTake(MultiMoves multiMoves)
        {
            // Choose an arbitrary territory with a non owned neighbor
            TerritoryIDType nonOwnedTerritory = new TerritoryIDType();

            foreach (var territory in multiMoves.GetTerritoryStandingsAfterAllMoves().Values.Where(t => t.OwnerPlayerID == GameState.MyPlayerId))
            {
                var nonOwnedNeighbors = MapInformer.GetNonOwnedNeighborTerritories(territory.ID, multiMoves.GetTerritoryStandingsAfterAllMoves());
                if (nonOwnedNeighbors.Count > 0)
                {
                    nonOwnedTerritory = nonOwnedNeighbors.First().Key;
                    break;
                }
            }
            var bonus = MapInformer.GetBonus(nonOwnedTerritory);

            AILog.Log("Debug", "Attempting to take bonus: " + bonus.Name);
            var nonOwnedBonusTerritories = MapInformer.GetNonOwnedBonusTerritories(bonus, multiMoves.GetTerritoryStandingsAfterAllMoves());

            return(nonOwnedBonusTerritories);
        }