Example #1
0
        private void PlayCards()
        {
            if (GamePlayerReference.Team != PlayerInvite.NoTeam && Players.Values.Any(o => o.ID != PlayerID && !o.IsAIOrHumanTurnedIntoAI && o.Team == this.GamePlayerReference.Team && o.State == GamePlayerState.Playing && !o.HasCommittedOrders))
            {
                return; //If there are any humans on our team that have yet to take their turn, do not play cards.
            }
            //For now, just play all reinforcement cards, and discard if we must use any others.

            var cardsPlayedByTeammate =
                TeammatesSubmittedOrders.OfType <GameOrderPlayCard>().Select(o => o.CardInstanceID)
                .Concat(TeammatesSubmittedOrders.OfType <GameOrderDiscard>().Select(o => o.CardInstanceID))
                .ToHashSet(true);

            int numMustPlay = this.CardsMustPlay;

            foreach (var card in Cards)
            {
                if (cardsPlayedByTeammate.Contains(card.ID))
                {
                    continue; //Teammate played it
                }
                if (card is ReinforcementCardInstance)
                {
                    AddOrder(GameOrderPlayCardReinforcement.Create(card.ID, PlayerID));
                    Income.FreeArmies += card.As <ReinforcementCardInstance>().Armies;
                    numMustPlay--;
                }
                else if (numMustPlay > 0) //For now, just discard all non-reinforcement cards if we must use the card
                {
                    AddOrder(GameOrderDiscard.Create(PlayerID, card.ID));
                    numMustPlay--;
                }
            }
        }
Example #2
0
        public static void PlayCards(BotMain state, Moves moves)
        {
            if (state.Me.Team != PlayerInvite.NoTeam && state.Players.Values.Any(o => state.IsTeammate(o.ID) && !o.IsAIOrHumanTurnedIntoAI && o.State == GamePlayerState.Playing && !o.HasCommittedOrders))
            {
                return; //If there are any humans on our team that have yet to take their turn, do not play cards.
            }
            //For now, just play all reinforcement cards, and discard if we must use any others.
            var teammatesOrders       = state.TeammatesOrders.Values.Where(o => o.Orders != null).SelectMany(o => o.Orders);
            var cardsPlayedByTeammate = teammatesOrders.OfType <GameOrderPlayCard>().Select(o => o.CardInstanceID).Concat(teammatesOrders.OfType <GameOrderDiscard>().Select(o => o.CardInstanceID)).ToHashSet(true);

            int numMustPlay = state.CardsMustPlay;

            foreach (var card in state.Cards)
            {
                if (cardsPlayedByTeammate.Contains(card.ID))
                {
                    continue;
                }

                if (card is ReinforcementCardInstance)
                {
                    moves.AddOrder(new BotOrderGeneric(GameOrderPlayCardReinforcement.Create(card.ID, state.Me.ID)));
                    state.MyIncome.FreeArmies += card.As <ReinforcementCardInstance>().Armies;
                    numMustPlay--;
                }
                else if (numMustPlay > 0) //For now, just discard all non-reinforcement cards if we must use the card
                {
                    moves.AddOrder(new BotOrderGeneric(GameOrderDiscard.Create(state.Me.ID, card.ID)));
                    numMustPlay--;
                }
            }
        }
Example #3
0
        public static void Go(BotMain bot)
        {
            if (bot.GamePlayerReference.Team != PlayerInvite.NoTeam && bot.Players.Values.Any(o => o.ID != bot.PlayerID && !o.IsAIOrHumanTurnedIntoAI && o.Team == bot.GamePlayerReference.Team && o.State == GamePlayerState.Playing && !o.HasCommittedOrders))
            {
                return; //If there are any humans on our team that have yet to take their turn, do not play cards.
            }
            var cardsPlayedByTeammate =
                bot.TeammatesSubmittedOrders.OfType <GameOrderPlayCard>().Select(o => o.CardInstanceID)
                .Concat(bot.TeammatesSubmittedOrders.OfType <GameOrderDiscard>().Select(o => o.CardInstanceID))
                .ToHashSet(true);

            int numMustPlay = bot.CardsMustPlay;

            if (numMustPlay > 0)
            {
                AILog.Log("PlayCards", "Must play " + numMustPlay + " cards, have " + bot.Cards.Count + ", teammate played " + cardsPlayedByTeammate.Count);
            }

            var availableCards = bot.Cards.ToDictionary(o => o.ID, o => o);


            foreach (var card in bot.Cards)
            {
                if (cardsPlayedByTeammate.Contains(card.ID))
                {
                    //Teammate played it
                    availableCards.Remove(card.ID);
                    continue;
                }

                Action <CardType, Func <BotMain, CardInstance, bool> > tryPlay = (cardType, playFn) =>
                {
                    if (card.CardID == cardType.CardID && playFn(bot, card))
                    {
                        availableCards.Remove(card.ID);
                        numMustPlay--;
                    }
                };

                tryPlay(CardType.Reinforcement, PlayReinforcementCard);
                tryPlay(CardType.Sanctions, PlaySanctionsCard);
                tryPlay(CardType.Bomb, PlayBombCard);
                tryPlay(CardType.Blockade, PlayBlockadeCard);
                tryPlay(CardType.Diplomacy, PlayDiplomacyCard);
            }

            while (numMustPlay > 0)
            {
                var card = availableCards.First().Value;
                AILog.Log("PlayCards", "Discarding card " + card + ", type=" + card.CardID);
                bot.Orders.AddOrder(GameOrderDiscard.Create(bot.PlayerID, card.ID));
                numMustPlay--;
                availableCards.Remove(card.ID);
            }
        }
Example #4
0
        public static void DiscardCardsEndTurn(BotMain state, Moves moves)
        {
            //If there are players on our team that have yet to take their turn, do not discard cards
            if (state.Me.Team != PlayerInvite.NoTeam && state.Players.Values.Any(o => state.IsTeammate(o.ID) && o.State == GamePlayerState.Playing && !o.HasCommittedOrders))
            {
                return;
            }

            // Discard as many cards as needed
            var cardsWePlayed       = moves.Convert().OfType <GameOrderPlayCard>().Select(o => o.CardInstanceID).ToHashSet(true);
            var cardsPlayedByAnyone = state.CardsPlayedByTeammates.Concat(cardsWePlayed).ToHashSet(true);

            int numMustPlay = state.CardsMustPlay;

            foreach (var card in state.Cards)
            {
                if (numMustPlay > 0 && !cardsPlayedByAnyone.Contains(card.ID))
                {
                    AILog.Log("PlayCardsTask", "Discarding card " + card.ID);
                    moves.AddOrder(new BotOrderGeneric(GameOrderDiscard.Create(state.Me.ID, card.ID)));
                    numMustPlay--;
                }
            }
        }