Beispiel #1
0
 public bool IsPlayerPresent(PlayerIDType playerID)
 {
     if (playerID == BotState.Me.ID && this.ContainsOwnPresence())
     {
         return(true);
     }
     if (BotState.IsOpponent(playerID) && this.ContainsOpponentPresence())
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 public void Init(PlayerIDType myPlayerID, Dictionary<PlayerIDType, GamePlayer> players, MapDetails map, GameStanding distributionStanding, GameSettings gameSettings, int numberOfTurns, Dictionary<PlayerIDType, PlayerIncome> incomes, GameOrder[] prevTurn, GameStanding latestTurnStanding, GameStanding previousTurnStanding, Dictionary<PlayerIDType, TeammateOrders> teammatesOrders, List<CardInstance> cards, int cardsMustPlay)
 {
     this.DistributionStanding = distributionStanding;
     this.LatestTurnStanding = latestTurnStanding;
     this.MyPlayerID = myPlayerID;
     this.Players = players;
     this.Map = map;
     this.Settings = gameSettings;
     this.TeammatesOrders = teammatesOrders;
     this.Cards = cards;
     this.CardsMustPlay = cardsMustPlay;
     this.Incomes = incomes;
 }
Beispiel #3
0
 public static void PushMoveState(PlayerIDType myPlayerId, Dictionary <PlayerIDType, GamePlayer> players,
                                  MapDetails map, GameStanding distributionStanding, GameSettings gameSettings, int numberOfTurns,
                                  Dictionary <PlayerIDType, PlayerIncome> incomes, GameOrder[] prevTurn, GameStanding latestTurnStanding,
                                  GameStanding previousTurnStanding)
 {
     MyPlayerId           = myPlayerId;
     OpponentPlayerId     = players.Keys.Where(o => o != MyPlayerId).First();
     Players              = players;
     DistributionStanding = distributionStanding;
     GameSettings         = gameSettings;
     Map = map;
     TurnStates.Add(new TurnState(numberOfTurns, incomes, prevTurn, latestTurnStanding, previousTurnStanding));
 }
Beispiel #4
0
        public int GetGuessedOpponentIncome(PlayerIDType opponentID, BotMap mapToUse)
        {
            var outvar = Settings.MinimumArmyBonus;

            foreach (var bonus in mapToUse.Bonuses.Values)
            {
                if (bonus.IsOwnedByOpponent(opponentID))
                {
                    outvar += bonus.Amount;
                }
            }

            return(outvar);
        }
Beispiel #5
0
        private static void PrintOpponentBonuses(PlayerIDType opponentID, BotMain state)
        {
            var message = new StringBuilder();

            message.Append("Opponent owns Bonuses: ");
            foreach (var bonus in state.VisibleMap.Bonuses.Values)
            {
                if (bonus.IsOwnedByOpponent(opponentID))
                {
                    message.Append(bonus.Details.Name + ", ");
                }
            }
            AILog.Log("Debug", message.ToString());
        }
Beispiel #6
0
        private bool CanOpponentAttackTerritory(PlayerIDType opponentID, BotTerritory ourTerritory)
        {
            if (ourTerritory.GetOpponentNeighbors().Count == 0)
            {
                return(false);
            }
            var opponentIncome          = BotState.GetGuessedOpponentIncome(opponentID, BotState.VisibleMap);
            var ourArmies               = ourTerritory.Armies;
            var opponentAttackingArmies = opponentIncome;

            foreach (var opponentNeighbor in ourTerritory.GetOpponentNeighbors())
            {
                opponentAttackingArmies += opponentNeighbor.Armies.AttackPower - BotState.MustStandGuardOneOrZero;
            }

            return(Math.Round(opponentAttackingArmies * BotState.Settings.OffensiveKillRate) >= Math.Round(ourArmies.DefensePower * BotState.Settings.DefensiveKillRate));
        }
        private int GetCounteredTerritories(BotBonus bonus, PlayerIDType playerID)
        {
            var outvar = 0;

            foreach (var territory in bonus.Territories)
            {
                if (territory.GetOpponentNeighbors().Count > 0 && playerID == BotState.Me.ID)
                {
                    outvar++;
                }
                else if (territory.GetOwnedNeighbors().Count > 0 && BotState.IsOpponent(playerID))
                {
                    outvar++;
                }
            }
            return(outvar);
        }
Beispiel #8
0
        public TakePlayingTurnContainer(MapDetails map, GameStanding noFogStanding, Dictionary <PlayerIDType, GamePlayer> players, GameSettings settings, PlayerIDType player, PlayerIncome income, List <CardInstance> cards, int cardsMustPlay, Dictionary <PlayerIDType, TeammateOrders> activeOrders, Stopwatch aiTimer)
        {
            this.Map             = map;
            this.Standing        = noFogStanding;
            this.Players         = players;
            this.Settings        = settings;
            this.PlayerID        = player;
            this.Income          = income;
            this.Cards           = cards;
            this.CardsMustPlay   = cardsMustPlay;
            this.TeammatesOrders = activeOrders;
            this._aiTimer        = aiTimer;

            Orders    = new List <GameOrder>();
            Neighbors = players.Keys.ExceptOne(player).ConcatOne(TerritoryStanding.NeutralPlayerID).ToDictionary(o => o, o => new Neighbor(this, o));

            BuildOrders();
        }
Beispiel #9
0
        public void Init(GameIDType gameID, PlayerIDType myPlayerID, Dictionary <PlayerIDType, GamePlayer> players, MapDetails map, GameStanding distributionStanding, GameSettings gameSettings, int numberOfTurns, Dictionary <PlayerIDType, PlayerIncome> incomes, GameOrder[] prevTurn, GameStanding latestTurnStanding, GameStanding previousTurnStanding, Dictionary <PlayerIDType, TeammateOrders> teammatesOrders, List <CardInstance> cards, int cardsMustPlay, Stopwatch timer, List <string> directives)
        {
            this.Me                   = players[myPlayerID];
            this.Players              = players;
            this.NumberOfTurns        = numberOfTurns;
            this.Settings             = gameSettings;
            this.Map                  = map;
            this.DistributionStanding = distributionStanding;
            this.LatestStanding       = latestTurnStanding;
            this.PreviousTurnStanding = previousTurnStanding;
            this.MyIncome             = incomes[myPlayerID];
            this.PreviousTurn         = prevTurn;

            //teammatesOrders
            //cards
            //cardsMustPlay

            this.BotMap = new BotMap(this, Map, LatestStanding ?? DistributionStanding);
        }
 public void GuessOpponentDeployment(PlayerIDType opponentID)
 {
     Assert.Fatal(BotState.NumberOfTurns != -1);
     if (BotState.NumberOfTurns == 0)
     {
         foreach (var vmTerritory in BotState.VisibleMap.OpponentTerritories(opponentID))
         {
             var armies = BotState.Settings.MinimumArmyBonus;
             MovesCommitter.CommittPlaceArmiesMove(new BotOrderDeploy(opponentID, vmTerritory, armies));
         }
     }
     else
     {
         foreach (var vmTerritory1 in BotState.VisibleMap.OpponentTerritories(opponentID))
         {
             var lvmTerritory = BotState.LastVisibleMapX.Territories[vmTerritory1.ID];
             var guessedOpponentDeployment = 0;
             if (lvmTerritory.IsVisible && lvmTerritory.OwnerPlayerID == opponentID)
             {
                 var opponentIncome = BotState.GetGuessedOpponentIncome(opponentID, BotState.VisibleMap);
                 guessedOpponentDeployment = Math.Min(lvmTerritory.GetTotalDeployment(BotTerritory.DeploymentType.Normal), opponentIncome);
                 if (HasDeploymentReasonDisapeared(lvmTerritory, vmTerritory1))
                 {
                     var boundDeployment = GetBoundOpponentDeployment(opponentID, vmTerritory1);
                     var maxDeployment   = BotState.GetGuessedOpponentIncome(opponentID, BotState.VisibleMap) - boundDeployment;
                     guessedOpponentDeployment = Math.Min(5, maxDeployment);
                 }
             }
             else
             {
                 var boundDeployment = GetBoundOpponentDeployment(opponentID, vmTerritory1);
                 var maxDeployment   = BotState.GetGuessedOpponentIncome(opponentID, BotState.VisibleMap) - boundDeployment;
                 guessedOpponentDeployment = Math.Max(1, Math.Min(5, maxDeployment));
             }
             var pam = new BotOrderDeploy(opponentID, vmTerritory1, guessedOpponentDeployment);
             MovesCommitter.CommittPlaceArmiesMove(pam);
             var conservativePam = new BotOrderDeploy(opponentID, vmTerritory1, BotState.GetGuessedOpponentIncome(opponentID, BotState.VisibleMap));
             MovesCommitter.CommittPlaceArmiesMove(conservativePam, BotTerritory.DeploymentType.Conservative);
         }
     }
 }
Beispiel #11
0
        /// <summary>Calculates the minimum opponent moves that he needs to make if we don't deploy.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="ownedTerritories"></param>
        /// <returns></returns>
        private static Moves CalculateMinimumOpponentMoves(BotMain state, PlayerIDType opponentID, List <BotTerritory> ownedTerritories, BotTerritory.DeploymentType conservativeLevel)
        {
            var outvar = new Moves();

            foreach (var ownedTerritory in ownedTerritories)
            {
                var attackingOpponentTerritory = GetOpponentNeighborMaxIdleArmies(state, opponentID, ownedTerritory, outvar);

                if (attackingOpponentTerritory == null)
                {
                    continue;
                }

                var stilIdleArmies          = CalculateStillOpponentIdleArmies(state, attackingOpponentTerritory, outvar);
                var attackingOpponentArmies = SharedUtility.Round(ownedTerritory.GetArmiesAfterDeploymentAndIncomingAttacks(conservativeLevel).DefensePower / state.Settings.OffensiveKillRate);
                var opponentDeployment      = Math.Max(0, attackingOpponentArmies - stilIdleArmies.DefensePower);
                if (opponentDeployment > 0)
                {
                    outvar.AddOrder(new BotOrderDeploy(opponentID, attackingOpponentTerritory, opponentDeployment));
                }

                outvar.AddOrder(new BotOrderAttackTransfer(opponentID, attackingOpponentTerritory, ownedTerritory, new Armies(attackingOpponentArmies), "PreventTerritoriesTask"));
            }
            // Now let's assume that the opponent doesen't leave armies idle
            var hasSomethingChanged = true;

            while (hasSomethingChanged)
            {
                hasSomethingChanged = false;
                foreach (var attackTransferMove in outvar.Orders.OfType <BotOrderAttackTransfer>())
                {
                    var stillIdleArmies = CalculateStillOpponentIdleArmies(state, attackTransferMove.From, outvar);
                    if (stillIdleArmies.IsEmpty == false)
                    {
                        hasSomethingChanged       = true;
                        attackTransferMove.Armies = attackTransferMove.Armies.Add(new Armies(1));
                    }
                }
            }
            return(outvar);
        }
Beispiel #12
0
        public void Init(GameIDType gameID, PlayerIDType myPlayerID, Dictionary <PlayerIDType, GamePlayer> players, MapDetails map, GameStanding distributionStanding, GameSettings settings, int numTurns, Dictionary <PlayerIDType, PlayerIncome> playerIncomes, GameOrder[] prevTurn, GameStanding latestTurnStanding, GameStanding previousTurnStanding, Dictionary <PlayerIDType, TeammateOrders> teammatesOrders, List <CardInstance> cards, int cardsMustPlay, Stopwatch timer, List <string> directives)
        {
            this.Players  = players;
            this.Me       = players[myPlayerID];
            this.Settings = settings;

            this.Map        = map;
            this.VisibleMap = new BotMap(this);
            foreach (var bonus in this.Map.Bonuses.Values)
            {
                VisibleMap.Bonuses.Add(bonus.ID, new BotBonus(VisibleMap, bonus.ID));
            }

            foreach (var terr in this.Map.Territories.Values)
            {
                VisibleMap.Territories.Add(terr.ID, new BotTerritory(VisibleMap, terr.ID, TerritoryStanding.FogPlayerID, new Armies(0)));
            }

            VisibleMap = BotMap.FromStanding(this, latestTurnStanding);
            if (numTurns > 0)
            {
                LastVisibleMapX = BotMap.FromStanding(this, previousTurnStanding);
            }

            this.DistributionStanding = distributionStanding;

            this.NumberOfTurns = numTurns;
            this.PlayerIncomes = playerIncomes;

            this.PrevTurn        = prevTurn;
            this.TeammatesOrders = teammatesOrders ?? new Dictionary <PlayerIDType, TeammateOrders>();

            var allTeammatesOrders = TeammatesOrders.Values.Where(o => o.Orders != null).SelectMany(o => o.Orders).ToList();

            this.CardsPlayedByTeammates = allTeammatesOrders.OfType <GameOrderPlayCard>().Select(o => o.CardInstanceID).Concat(allTeammatesOrders.OfType <GameOrderDiscard>().Select(o => o.CardInstanceID)).ToHashSet(true);

            this.Cards         = cards;
            this.CardsMustPlay = cardsMustPlay;
            this.CardsHandler.initCards();
        }
Beispiel #13
0
        public List <BotBonus> SortBonuses(BotMap mapToUse, PlayerIDType playerID)
        {
            var allBonuses    = mapToUse.Bonuses.Values.ToList();
            var sortedBonuses = new List <BotBonus>();

            while (allBonuses.Count != 0)
            {
                var    bestBonus = allBonuses[0];
                double bestValue = 0;
                if (playerID == BotState.Me.ID)
                {
                    bestValue = bestBonus.ExpansionValue;
                }
                else
                {
                    bestValue = -1;
                }
                foreach (BotBonus bonus in allBonuses)
                {
                    double value = 0;
                    if (playerID == BotState.Me.ID)
                    {
                        value = bonus.ExpansionValue;
                    }
                    else
                    {
                        value = -1;
                    }

                    if (value > bestValue)
                    {
                        bestBonus = bonus;
                        bestValue = value;
                    }
                }
                allBonuses.Remove(bestBonus);
                sortedBonuses.Add(bestBonus);
            }
            return(sortedBonuses);
        }
Beispiel #14
0
 public void Init(GameIDType gameID, PlayerIDType myPlayerID, Dictionary <PlayerIDType, GamePlayer> players, MapDetails map, GameStanding distributionStanding, GameSettings gameSettings, int numberOfTurns, Dictionary <PlayerIDType, PlayerIncome> incomes, GameOrder[] prevTurn, GameStanding latestTurnStanding, GameStanding previousTurnStanding, Dictionary <PlayerIDType, TeammateOrders> teammatesOrders, List <CardInstance> cards, int cardsMustPlay, Stopwatch timer, List <string> directives)
 {
     this.DistributionStandingOpt = distributionStanding;
     this.Standing          = latestTurnStanding;
     this.PlayerID          = myPlayerID;
     this.Players           = players;
     this.Map               = map;
     this.Settings          = gameSettings;
     this.TeammatesOrders   = teammatesOrders;
     this.Cards             = cards;
     this.CardsMustPlay     = cardsMustPlay;
     this.Incomes           = incomes;
     this.BaseIncome        = Incomes[PlayerID];
     this.EffectiveIncome   = this.BaseIncome.Clone();
     this.Neighbors         = players.Keys.ExceptOne(PlayerID).ConcatOne(TerritoryStanding.NeutralPlayerID).ToDictionary(o => o, o => new Neighbor(this, o));
     this.Opponents         = players.Values.Where(o => o.State == GamePlayerState.Playing && !IsTeammateOrUs(o.ID)).ToList();
     this.IsFFA             = Opponents.Count > 1 && (Opponents.Any(o => o.Team == PlayerInvite.NoTeam) || Opponents.GroupBy(o => o.Team).Count() > 1);
     this.WeightedNeighbors = WeightNeighbors();
     this.Timer             = timer;
     this.Directives        = directives;
     AILog.Log("BotMain", "Prod initialized.  Starting at " + timer.Elapsed.TotalSeconds + " seconds");
 }
Beispiel #15
0
        private static BotTerritory GetOpponentNeighborMaxIdleArmies(BotMain state, PlayerIDType opponentID, BotTerritory ownedTerritory, Moves alreadyMadeAttacks)
        {
            var opponentNeighbors = ownedTerritory.Neighbors.Where(o => o.OwnerPlayerID == opponentID).ToList();

            if (opponentNeighbors.Count == 0)
            {
                return(null);
            }

            var maxIdleArmiesTerritory = opponentNeighbors[0];
            var maxIdleArmies          = CalculateStillOpponentIdleArmies(state, maxIdleArmiesTerritory, alreadyMadeAttacks);

            foreach (var territory in opponentNeighbors)
            {
                var idleArmies = CalculateStillOpponentIdleArmies(state, territory, alreadyMadeAttacks);
                if (idleArmies.AttackPower > maxIdleArmies.AttackPower)
                {
                    maxIdleArmies          = idleArmies;
                    maxIdleArmiesTerritory = territory;
                }
            }
            return(maxIdleArmiesTerritory);
        }
Beispiel #16
0
 public List <BotTerritory> GetOwnedTerritoriesBorderingNeighborsOwnedBy(PlayerIDType playerID)
 {
     return(this.GetOwnedTerritories().Where(owned => owned.Neighbors.Any(z => z.OwnerPlayerID == playerID)).ToList());
 }
Beispiel #17
0
 public bool ContainsPresenseBy(PlayerIDType playerID)
 {
     return(this.Territories.Any(o => o.OwnerPlayerID == playerID));
 }
Beispiel #18
0
 public bool IsTeammateOrUs(PlayerIDType playerID)
 {
     return(PlayerID == playerID || IsTeammate(playerID));
 }
Beispiel #19
0
 public bool IsTeammate(PlayerIDType playerID)
 {
     return(Players[PlayerID].Team != PlayerInvite.NoTeam && Players.ContainsKey(playerID) && Players[playerID].Team == Players[PlayerID].Team);
 }
Beispiel #20
0
 public bool IsOpponent(PlayerIDType playerID)
 {
     return(Players.ContainsKey(playerID) && !IsTeammateOrUs(playerID));
 }
Beispiel #21
0
 /// <summary>
 /// dummy constructor for testing purposes
 /// </summary>
 /// <param name="state"></param>
 public BotTerritory(CowzowBot bot)
 {
     this.Bot      = bot;
     ID            = (TerritoryIDType)DummyID;
     OwnerPlayerID = TerritoryStanding.FogPlayerID;
 }
Beispiel #22
0
 public Neighbor(BotMain bot, PlayerIDType id)
 {
     ID  = id;
     Bot = bot;
 }
 public int GetOpponentDeployment(PlayerIDType opponentID)
 {
     return(BotState.PrevTurn.Where(o => o.PlayerID == opponentID).OfType <GameOrderDeploy>().Sum(o => o.NumArmies));
 }
 public BotOrderDeploy(PlayerIDType playerName, BotTerritory territory, int armies)
 {
     PlayerID       = playerName;
     this.Territory = territory;
     this.Armies    = armies;
 }
Beispiel #25
0
 public List <BotTerritory> VisibleOpponentTerritories(PlayerIDType opponentID)
 {
     return(this.OpponentTerritories(opponentID).Where(o => o.IsVisible).ToList());
 }
Beispiel #26
0
 public List <BotTerritory> OpponentTerritories(PlayerIDType opponentID)
 {
     return(this.Territories.Values.Where(o => o.OwnerPlayerID == opponentID).ToList());
 }
Beispiel #27
0
 public virtual void Update(PlayerIDType opponentID, int opponentDeployment)
 {
     OpponentDeployments.Add(opponentID, opponentDeployment);
     AILog.Log("VisibleDeployment for " + opponentID + ": " + opponentDeployment);
 }
        public static Moves CalculatePreventBonusTask(BotMain state, BotBonus bonusToPrevent, PlayerIDType opponentID, int maxDeployment, BotTerritory.DeploymentType conservativeLevel)
        {
            var territoriesToPrevent = bonusToPrevent.GetOwnedTerritories();

            var opponentAttacks = PreventTerritoriesTask.CalculateGuessedOpponentTakeOverMoves(state, territoriesToPrevent, opponentID, true, conservativeLevel);

            if (opponentAttacks == null)
            {
                return(new Moves());
            }

            var preventTerritoryMovesByDeploying = PreventTerritoriesTask.CalculatePreventTerritoriesTask(state, territoriesToPrevent, opponentID, maxDeployment, conservativeLevel);
            var visibleOpponentTerritories       = bonusToPrevent.GetVisibleOpponentTerritories();
            var breakBestTerritoryMoves          = NoPlanBreakBestTerritoryTask.CalculateNoPlanBreakBestTerritoryTask(state, maxDeployment, visibleOpponentTerritories, state.VisibleMap, state.WorkingMap, "PreventBonusTask");

            if (breakBestTerritoryMoves == null)
            {
                return(preventTerritoryMovesByDeploying);
            }
            else if (breakBestTerritoryMoves.GetTotalDeployment() <= preventTerritoryMovesByDeploying.GetTotalDeployment())
            {
                return(breakBestTerritoryMoves);
            }
            else
            {
                return(preventTerritoryMovesByDeploying);
            }
        }
 public int OpponentDeployment(PlayerIDType opponentID)
 {
     return(DeploymentHistory.GetOpponentDeployment(opponentID));
 }
Beispiel #30
0
        public static List <BotTerritory> FilterTerritoriesByPlayerList(ICollection <BotTerritory> territories, PlayerIDType playerName)
        {
            var result = new List <BotTerritory>();

            foreach (var r in territories)
            {
                if (r.OwnerPlayerID == playerName)
                {
                    result.Add(r);
                }
            }
            return(result);
        }