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 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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }