Exemple #1
0
            // TODO:  implement a better default choice of which Ruins to player.
            private static int CompareRuins(Card first, Card second, GameState gameState, ICardPicker purchaseOrder)
            {
                PlayerState self = gameState.Self;

                int coinsToSpend = self.ExpectedCoinValueAtEndOfTurn;

                if (first == Cards.AbandonedMine || second == Cards.AbandonedMine)
                {
                    CardPredicate shouldGainCard = delegate(Card card)
                    {
                        int currentCardCost = card.CurrentCoinCost(self);

                        return(currentCardCost == coinsToSpend + 1);
                    };

                    Card cardType = purchaseOrder.GetPreferredCard(gameState, shouldGainCard);
                    if (cardType != null)
                    {
                        return(first == Cards.AbandonedMine ? 0 : 1);
                    }

                    //Card Card1 = purchaseOrder.GetPreferredCard(
                    //        gameState,
                    //        card => coinsToSpend >= card.CurrentCoinCost(currentPlayer) &&
                    //        gameState.GetPile(card).Any());
                    //Card Card2 = purchaseOrder.GetPreferredCard(
                    //        gameState,
                    //        card => coinsToSpend + 1 >= card.CurrentCoinCost(currentPlayer) &&
                    //        gameState.GetPile(card).Any());

                    //if (Card1 != Card2)
                    //    return first.name == "Abandoned Mine" ? 0 : 1;
                }
                return(0);
            }
Exemple #2
0
        private static bool ShouldGainCopper(GameState gameState, ICardPicker gainOrder)
        {
            PlayerState self = gameState.Self;

            int minValue = self.ExpectedCoinValueAtEndOfTurn;
            int maxValue = minValue + Strategy.CountInHand(Dominion.Cards.IllGottenGains, gameState);

            if (maxValue == minValue)
            {
                return(false);
            }

            CardPredicate shouldGainCard = delegate(Card card)
            {
                int currentCardCost = card.CurrentCoinCost(self);

                return(currentCardCost >= minValue &&
                       currentCardCost <= maxValue);
            };

            Card cardType = gainOrder.GetPreferredCard(gameState, shouldGainCard);

            if (cardType == null)
            {
                return(false);
            }

            int coppersToGain = PlayerAction.CostOfCard(cardType, gameState) - minValue;

            return(coppersToGain > 0);
        }
        public Card GetPreferredCardReverse(GameState gameState, CardPredicate cardPredicate)
        {
            if (predicate(gameState))
                return this.picker.GetPreferredCardReverse(gameState, cardPredicate);

            return null;
        }
Exemple #4
0
        public override Card GetCardFromHandOrDiscardToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, out DeckPlacement deckPlacement)
        {
            var  self   = gameState.Self;
            Card result = this.trashOrder.GetPreferredCard(
                gameState,
                card => (self.Hand.HasCard(card) || self.Discard.HasCard(card)) && acceptableCard(card));

            // warning, strategy didnt' include what to, try to do a reasonable default.
            if (result == null && !isOptional)
            {
                result = self.Hand.OrderBy(c => c, new DefaultPlayRules.CompareCardByFirstToTrash()).FirstOrDefault();
            }

            deckPlacement = DeckPlacement.Discard;
            if (result != null)
            {
                if (self.Discard.HasCard(result))
                {
                    deckPlacement = DeckPlacement.Discard;
                }
                else if (self.Hand.HasCard(result))
                {
                    deckPlacement = DeckPlacement.Hand;
                }
                else
                {
                    throw new Exception("Card should have been in hand or discard");
                }
            }

            return(result);
        }
Exemple #5
0
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            Card cardToReturn = playerAction.trashOrder.GetPreferredCard(gameState, card => gameState.Self.Hand.HasCard(card) && acceptableCard(card));

            if (cardToReturn == null)
            {
                return(null);
            }

            PlayerState self              = gameState.Self;
            int         currentCoin       = self.ExpectedCoinValueAtEndOfTurn;
            int         coinCountIfReturn = currentCoin - cardToReturn.plusCoin;


            if (currentCoin < Dominion.Cards.Gold.DefaultCoinCost)
            {
                return(cardToReturn);
            }

            Card cardWithAllCoin      = playerAction.GetCardFromSupplyToBuy(gameState, card => card.CurrentCoinCost(self) <= currentCoin);
            Card cardWithReturnedCard = playerAction.GetCardFromSupplyToBuy(gameState, card => card.CurrentCoinCost(self) <= coinCountIfReturn);

            if (cardWithAllCoin != cardWithReturnedCard)
            {
                return(null);
            }

            return(cardToReturn);
        }
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            if (gameState.Self.Hand.HasCard(gameState.BaneCard))
                return gameState.BaneCard;

            return null;
        }
Exemple #7
0
        public override Card GetTreasureFromHandToPlay(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            var self = gameState.Self;

            return(this.treasurePlayOrder.GetPreferredCard(
                       gameState,
                       card => self.Hand.HasCard(card) && acceptableCard(card)));
        }
Exemple #8
0
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            if (this.defaultCardResponses.ShouldDeferForCardInPlay(gameState))
            {
                return(this.defaultCardResponses.GetCardFromHandToReveal(gameState, acceptableCard));
            }

            return(base.GetCardFromHandToReveal(gameState, acceptableCard));
        }
Exemple #9
0
        public Card GetPreferredCardReverse(GameState gameState, CardPredicate cardPredicate)
        {
            if (predicate(gameState))
            {
                return(this.picker.GetPreferredCardReverse(gameState, cardPredicate));
            }

            return(null);
        }
Exemple #10
0
 public override Card GetCardFromHandToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, CollectionCards cardsTrashedSoFar)
 {
     if (gameState.Self == gameState.players.CurrentPlayer)
     {
         if (Strategy.CountInHand(Dominion.Cards.Gold, gameState) > 0)
             return Dominion.Cards.Gold;
     }
     return base.GetCardFromHandToTrash(gameState, acceptableCard, isOptional, cardsTrashedSoFar);
 }
Exemple #11
0
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            if (gameState.Self.Hand.HasCard(gameState.BaneCard))
            {
                return(gameState.BaneCard);
            }

            return(null);
        }
Exemple #12
0
        public override Card GetCardFromSupplyToGain(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            if (this.defaultCardResponses.ShouldDeferForCardInPlay(gameState))
            {
                return(this.defaultCardResponses.GetCardFromSupplyToGain(gameState, acceptableCard, isOptional));
            }

            return(DefaultGetCardFromSupplyToGain(gameState, acceptableCard, isOptional));
        }
        // always optional
        public Card GetCardFromHandToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, CollectionCards cardsTrashedSoFar)
        {
            var saved = gameState.self;

            gameState.self = this.self;
            var result = this.playerAction.GetCardFromHandToTrash(gameState, acceptableCard, isOptional, cardsTrashedSoFar);

            gameState.self = saved;
            return(result);
        }
Exemple #14
0
        public override Card GetCardFromHandToTopDeck(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            Card result = this.playerAction.discardOrder.GetPreferredCardReverse(gameState, card => gameState.Self.Hand.HasCard(card) && acceptableCard(card));
            if (result != null)
            {
                return result;
            }

            return gameState.Self.Hand.FirstOrDefault();
        }
        public Card GetCardFromSupplyToInherit(GameState gameState, CardPredicate acceptableCard)
        {
            var saved = gameState.self;

            gameState.self = this.self;
            var result = this.playerAction.GetCardFromSupplyToInherit(gameState, acceptableCard);

            gameState.self = saved;
            return(result);
        }
        public Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            var saved = gameState.self;

            gameState.self = this.self;
            var result = this.playerAction.GetCardFromHandToReveal(gameState, acceptableCard);

            gameState.self = saved;
            return(result);
        }
        public Card GetCardFromHandToDiscard(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            var saved = gameState.self;

            gameState.self = this.self;
            var result = this.playerAction.GetCardFromHandToDiscard(gameState, acceptableCard, isOptional);

            gameState.self = saved;
            return(result);
        }
        public Card GetCardFromHandOrDiscardToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, out DeckPlacement deckPlacement)
        {
            var saved = gameState.self;

            gameState.self = this.self;
            var result = this.playerAction.GetCardFromHandOrDiscardToTrash(gameState, acceptableCard, isOptional, out deckPlacement);

            gameState.self = saved;
            return(result);
        }
        public Card GetCardFromPlayToTopDeckDuringCleanup(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            var saved = gameState.self;

            gameState.self = this.self;
            var result = this.playerAction.GetCardFromPlayToTopDeckDuringCleanup(gameState, acceptableCard, isOptional);

            gameState.self = saved;
            return(result);
        }
        protected Card RemoveCard(CardPredicate acceptableCard)
        {
            Card result = this.FindCard(acceptableCard);

            if (result != null)
            {
                this.Remove(result);
            }
            return(result);
        }
Exemple #21
0
 public override Card GetCardFromHandToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, CollectionCards cardsTrashedSoFar)
 {
     if (gameState.Self == gameState.players.CurrentPlayer)
     {
         if (Strategy.CountInHand(Dominion.Cards.Gold, gameState) > 0)
         {
             return(Dominion.Cards.Gold);
         }
     }
     return(base.GetCardFromHandToTrash(gameState, acceptableCard, isOptional, cardsTrashedSoFar));
 }
Exemple #22
0
        public override Card GetCardFromHandToTopDeck(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            Card result = this.playerAction.discardOrder.GetPreferredCardReverse(gameState, card => gameState.Self.Hand.HasCard(card) && acceptableCard(card));

            if (result != null)
            {
                return(result);
            }

            return(gameState.Self.Hand.FirstOrDefault());
        }
Exemple #23
0
        public override Card GetCardFromHandToPlay(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            if (this.defaultCardResponses.ShouldDeferForCardInPlay(gameState))
            {
                return(this.defaultCardResponses.GetCardFromHandToPlay(gameState, acceptableCard, isOptional));
            }

            var self = gameState.Self;

            Card result = this.actionOrder.GetPreferredCard(
                gameState,
                card => self.Hand.HasCard(card) && acceptableCard(card),
                card => DefaultShouldPlayCard(gameState, card));

            // only choose default actions that weren't explicitly mentioned in the play order
            if (result == null && this.chooseDefaultActionOnNone)
            {
                var candidateCards = new SetOfCards(gameState.CardGameSubset);

                foreach (Card card in self.Hand)
                {
                    if (acceptableCard(card) && DefaultShouldPlayCard(gameState, card))
                    {
                        candidateCards.Add(card);
                    }
                }

                if (candidateCards.Count > 0)
                {
                    foreach (Card card in this.actionOrder.GetNeededCards())
                    {
                        candidateCards.Remove(card);
                    }
                }

                if (candidateCards.Count > 0)
                {
                    result = this.defaultActionOrder.GetPreferredCard(
                        gameState,
                        card => candidateCards.Contains(card));
                }
            }

            if (result == null && !isOptional)
            {
                result = this.defaultActionOrder.GetPreferredCard(
                    gameState,
                    card => self.Hand.HasCard(card) && acceptableCard(card));
            }

            return(result);
        }
Exemple #24
0
            public Card GetPreferredCardReverse(GameState gameState, CardPredicate cardPredicate)
            {
                IComparer <Card> comparer = this.comparerFactory.GetComparer(gameState);

                Card cardToPlay = gameState.Self.Hand.Where(card => cardPredicate(card)).OrderByDescending(card => card, comparer).FirstOrDefault();

                if (cardToPlay == null)
                {
                    return(null);
                }

                return(cardToPlay);
            }
Exemple #25
0
        public override Card GetTreasureFromHandToPlay(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            if (this.defaultCardResponses.ShouldDeferForCardInPlay(gameState))
            {
                return(this.defaultCardResponses.GetTreasureFromHandToPlay(gameState, acceptableCard, isOptional));
            }

            var self = gameState.Self;

            return(this.treasurePlayOrder.GetPreferredCard(
                       gameState,
                       card => self.Hand.HasCard(card) && acceptableCard(card)));
        }
Exemple #26
0
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            IPlayerAction playerAction = this.GetActionForCurrentCardContext(gameState);

            if (playerAction != null)
            {
                return(playerAction.GetCardFromHandToReveal(gameState, acceptableCard));
            }
            else
            {
                return(base.GetCardFromHandToReveal(gameState, acceptableCard));
            }
        }
Exemple #27
0
        public Card GetPreferredCard(GameState gameState, CardPredicate cardPredicate, CardPredicate defaultPredicate)
        {
            foreach (ICardPicker matcher in this.matchers)
            {
                Card result = matcher.GetPreferredCard(gameState, cardPredicate, defaultPredicate);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
        public Card GetPreferredCard(GameState gameState, CardPredicate cardPredicate)
        {
            foreach (CardAcceptance acceptance in this.cardAcceptances)
            {
                if (cardPredicate(acceptance.card) &&
                    acceptance.match(gameState))
                {
                    return acceptance.card;
                }
            }

            return null;
        }
Exemple #29
0
 public override void DoSpecializedAction(PlayerState currentPlayer, GameState gameState)
 {
     currentPlayer.GainCardFromSupply(Cards.Rats, gameState);
     CardPredicate cardsToTrash = card => card != Rats.card;
     if (currentPlayer.Hand.HasCard(cardsToTrash))
     {
         currentPlayer.RequestPlayerTrashCardFromHand(gameState, cardsToTrash, isOptional: false);
     }
     else
     {
         currentPlayer.RevealHand();
     }
 }
        public Card GetPreferredCard(GameState gameState, CardPredicate cardPredicate)
        {
            foreach (CardAcceptance acceptance in this.cardAcceptances)
            {
                if (cardPredicate(acceptance.card) &&
                    acceptance.match(gameState))
                {
                    return(acceptance.card);
                }
            }

            return(null);
        }
Exemple #31
0
        public override Card GetCardFromSupplyToBuy(GameState gameState, CardPredicate cardPredicate)
        {
            if (this.defaultCardResponses.ShouldDeferForCardInPlay(gameState))
            {
                return(this.defaultCardResponses.GetCardFromSupplyToBuy(gameState, cardPredicate));
            }

            var self = gameState.Self;

            return(this.purchaseOrder.GetPreferredCard(
                       gameState,
                       cardPredicate));
        }
        public Card GetPreferredCard(GameState gameState, CardPredicate cardPredicate)
        {
            foreach (ICardPicker matcher in this.matchers)
            {
                Card result = matcher.GetPreferredCard(gameState, cardPredicate);
                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }
Exemple #33
0
        public override Card GetTreasureFromHandToPlay(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            IPlayerAction playerAction = this.GetActionForCurrentCardContext(gameState);

            if (playerAction != null)
            {
                return(playerAction.GetTreasureFromHandToPlay(gameState, acceptableCard, isOptional));
            }
            else
            {
                return(base.GetTreasureFromHandToPlay(gameState, acceptableCard, isOptional));
            }
        }
Exemple #34
0
        public override Card GetCardFromHandOrDiscardToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, out DeckPlacement deckPlacement)
        {
            IPlayerAction playerAction = this.GetActionForCurrentCardContext(gameState);

            if (playerAction != null)
            {
                return(playerAction.GetCardFromHandOrDiscardToTrash(gameState, acceptableCard, isOptional, out deckPlacement));
            }
            else
            {
                return(base.GetCardFromHandOrDiscardToTrash(gameState, acceptableCard, isOptional, out deckPlacement));
            }
        }
Exemple #35
0
        public override Card GetCardFromHandToTrash(GameState gameState, CardPredicate acceptableCard, bool isOptional, CollectionCards cardsTrashedSoFar)
        {
            IPlayerAction playerAction = this.GetActionForCurrentCardContext(gameState);

            if (playerAction != null)
            {
                return(playerAction.GetCardFromHandToTrash(gameState, acceptableCard, isOptional, cardsTrashedSoFar));
            }
            else
            {
                return(base.GetCardFromHandToTrash(gameState, acceptableCard, isOptional, cardsTrashedSoFar));
            }
        }
        public Card GetPreferredCardReverse(GameState gameState, CardPredicate cardPredicate)
        {
            for (int i = this.matchers.Length-1; i > 0; --i)
            {
                ICardPicker matcher = this.matchers[i];
                Card result = matcher.GetPreferredCard(gameState, cardPredicate);
                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }
        public Card GetPreferredCardReverse(GameState gameState, CardPredicate cardPredicate)
        {
            for (int i = this.cardAcceptances.Length - 1; i >= 0; i--)
            {
                CardAcceptance acceptance = this.cardAcceptances[i];
                if (cardPredicate(acceptance.card) &&
                    acceptance.match(gameState))
                {
                    return acceptance.card;
                }
            }

            return null;
        }
Exemple #38
0
        public override void DoSpecializedAttack(PlayerState currentPlayer, PlayerState otherPlayer, GameState gameState)
        {
            CardPredicate acceptableCard = card => card.isVictory;
            Card          cardTopDecked  = otherPlayer.RequestPlayerTopDeckCardFromHand(gameState, acceptableCard, isOptional: false);

            if (cardTopDecked == null)
            {
                otherPlayer.RevealHand();
            }
            else
            {
                otherPlayer.RevealCard(cardTopDecked, DeckPlacement.TopOfDeck);
            }
        }
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            int maxCount = 0;
            // find out which card that is wanted to be trashed you have most of in hand.
            foreach (Card card in playerAction.trashOrder.GetNeededCards())
            {
                maxCount = Math.Max(maxCount, gameState.Self.Hand.CountOf(card));
            }

            if (maxCount > 2)
                maxCount = 2;

            Card cardToReturn = playerAction.trashOrder.GetPreferredCard(gameState, card => gameState.Self.Hand.CountOf(card) >= maxCount && acceptableCard(card));
            return cardToReturn;
        }
        public Card GetPreferredCard(GameState gameState, CardPredicate cardPredicate, CardPredicate defaultPredicate)
        {
            foreach (CardAcceptance acceptance in this.cardAcceptances)
            {
                if (cardPredicate(acceptance.card))
                {
                    if (acceptance.match == CardAcceptance.DefaultMatch && defaultPredicate(acceptance.card) ||
                        acceptance.match != CardAcceptance.DefaultMatch && acceptance.match(gameState))
                    {
                        return acceptance.card;
                    }
                }
            }

            return null;
        }
        public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
        {
            Card cardToReturn = playerAction.trashOrder.GetPreferredCard(gameState, card => gameState.Self.Hand.HasCard(card) && acceptableCard(card));
            if (cardToReturn == null)
                return null;

            PlayerState self = gameState.Self;
            int currentCoin = self.ExpectedCoinValueAtEndOfTurn;
            int coinCountIfReturn = currentCoin - cardToReturn.plusCoin;

            if (currentCoin < Dominion.Cards.Gold.DefaultCoinCost)
                return cardToReturn;

            Card cardWithAllCoin = playerAction.GetCardFromSupplyToBuy(gameState, card => card.CurrentCoinCost(self) <= currentCoin);
            Card cardWithReturnedCard = playerAction.GetCardFromSupplyToBuy(gameState, card => card.CurrentCoinCost(self) <= coinCountIfReturn);

            if (cardWithAllCoin != cardWithReturnedCard)
                return null;

            return cardToReturn;
        }
        public Card GetPreferredCard(GameState gameState, CardPredicate cardPredicate)
        {
            var existingCards = gameState.Self.AllOwnedCards.Clone();

            int numberOfTries = 2;

            for (int index = 0; index < this.buildOrder.Length; ++index)
            {
                CardAcceptance acceptance = this.buildOrder[index];

                if (acceptance == null)
                    continue;

                if (!acceptance.match(gameState))
                    continue;

                Card currentCard = acceptance.card;

                if (existingCards.HasCard(currentCard))
                {
                    existingCards.RemoveCard(currentCard);
                    continue;
                }
                numberOfTries--;

                if (cardPredicate(currentCard))
                {
                    return currentCard;
                }

                if (numberOfTries == 0)
                {
                    break;
                }
            }

            return null;
        }
        internal Card RequestPlayerTrashCardFromHand(GameState gameState, CardPredicate acceptableCardsToTrash, bool isOptional, CollectionCards cardsTrashedSoFar = null)
        {
            Card cardTypeToTrash = RequestPlayerTrashCardFromHandButDontTrash(gameState, acceptableCardsToTrash, isOptional, cardsTrashedSoFar);

            if (cardTypeToTrash != null)
                this.TrashCardFromHandOfType(gameState, cardTypeToTrash, guaranteeInHand: true);

            return cardTypeToTrash;
        }
 public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
 {
     Card cardToReturn = playerAction.trashOrder.GetPreferredCard(gameState, card => gameState.Self.Hand.HasCard(card) && acceptableCard(card));
     return cardToReturn;
 }
        internal bool RequestPlayerDiscardCardFromHand(GameState gameState, CardPredicate acceptableCardsToDiscard, bool isOptional)
        {
            if (!this.hand.HasCard(acceptableCardsToDiscard))
            {
                return false;
            }

            Card cardTypeToDiscard = this.actions.GetCardFromHandToDiscard(gameState, acceptableCardsToDiscard, isOptional);
            if (cardTypeToDiscard == null)
            {
                if (isOptional)
                {
                    return false;
                }
                else
                {
                    throw new Exception("Player must choose a card to discard");
                }
            }
            else
            {
                if (gameState.GetPile(cardTypeToDiscard) != null &&  // TODO: this currently can not find ruins ... rework this method so a card is returned instead of a type.
                    !acceptableCardsToDiscard( cardTypeToDiscard))
                    throw new Exception("Card does not meet constraint: ");
            }

            this.MoveCardFromHandToDiscard(cardTypeToDiscard, gameState);

            return true;
        }
 internal Card RequestPlayerGainCardFromSupply(GameState gameState, CardPredicate acceptableCard, string description, bool isOptional = false, DeckPlacement defaultLocation = DeckPlacement.Discard)
 {
     return RequestPlayerGainCardFromSupply(gameState, this, acceptableCard, description, isOptional, defaultLocation);
 }
        internal Card RequestPlayerGainCardFromSupply(GameState gameState, PlayerState playerGainingCard, CardPredicate acceptableCard, string description, bool isOptional = false, DeckPlacement defaultLocation = DeckPlacement.Discard)
        {
            PileOfCards exampleCard = gameState.supplyPiles.Where(cardPile => !cardPile.IsEmpty && acceptableCard(cardPile.TopCard())).FirstOrDefault();
            bool hasCardOfCost = exampleCard != null;
            if (!hasCardOfCost)
            {
                return null;
            }

            CardPredicate cardPredicate = card => gameState.GetSupplyPile(card) != null && acceptableCard(card);
            // how do you know which player you are gaining for?
            Card cardType = this.actions.GetCardFromSupplyToGain(gameState, cardPredicate, isOptional);
            if (cardType == null)
            {
                if (isOptional)
                {
                    return null;
                }
                throw new Exception("Must gain a card where " + description);
            }

            Card gainedCard = gameState.PlayerGainCardFromSupply(cardType, playerGainingCard, defaultLocation);
            if (gainedCard == null)
            {
                throw new Exception("Card specified can not be gained");
            }

            if (!acceptableCard(gainedCard))
            {
                throw new Exception("Card does not meet constraint: " + description);
            }

            return gainedCard;
        }
        internal Card RequestPlayerTrashCardFromHandButDontTrash(GameState gameState, CardPredicate acceptableCardsToTrash, bool isOptional, CollectionCards cardsTrashedSoFar = null)
        {
            if (!this.hand.HasCard(acceptableCardsToTrash))
            {
                return null;
            }

            if (cardsTrashedSoFar == null)
                cardsTrashedSoFar = gameState.emptyCardCollection;

            Card cardTypeToTrash = this.actions.GetCardFromHandToTrash(gameState, acceptableCardsToTrash, isOptional, cardsTrashedSoFar);
            if (cardTypeToTrash == null)
            {
                if (isOptional)
                {
                    return null;
                }
                else
                {
                    throw new Exception("Player must choose a card to trash");
                }
            }

            if (!acceptableCardsToTrash(cardTypeToTrash))
            {
                throw new Exception("Tried to trash a card that didn't match the constraint");
            }

            return cardTypeToTrash;
        }
        internal Card RequestPlayerTopDeckCardFromPlay(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            if (!this.cardsPlayed.HasCard(acceptableCard))
            {
                return null;
            }

            Card cardTypeToTopDeck = this.actions.GetCardFromPlayToTopDeckDuringCleanup(gameState, acceptableCard, isOptional);
            if (cardTypeToTopDeck == null)
            {
                if (isOptional)
                {
                    return null;
                }
                else
                {
                    throw new Exception("Player must choose a card to top deck");
                }
            }

            Card cardToTopDeck = this.cardsPlayed.RemoveCard(cardTypeToTopDeck);
            if (cardToTopDeck == null)
            {
                throw new Exception("Could not remove Card From Hand");
            }

            if (!acceptableCard(cardToTopDeck))
            {
                throw new Exception("Card does not meet constraint for top deck");
            }

            this.gameLog.PlayerTopDeckedCard(this, cardToTopDeck);
            this.deck.AddCardToTop(cardToTopDeck);

            return cardToTopDeck;
        }
 internal void RevealCardsFromDiscard(int cardCount, CardPredicate cardPredicate)
 {
     for (int i = 0; i < cardCount; ++i)
     {
         // warning, n^2 algorithm here.
         Card card = this.discard.RemoveCard(cardPredicate);
         if (card == null)
         {
             throw new System.Exception("Could not reveal needed number of cards from discard");
         }
         RevealCard(card, DeckPlacement.Discard);
         this.cardsBeingRevealed.AddCard(card);
     }
 }
 internal void MoveCardsFromPlayedAreaToTrash(CardPredicate acceptableCard, GameState gameState)
 {
     while (this.cardsPlayed.HasCard(acceptableCard))
     {
         Card cardRemoved = this.cardsPlayed.RemoveCard(acceptableCard);
         MoveCardToTrash(cardRemoved, gameState);
     }
 }
        internal Card RequestPlayerTrashRevealedCard(GameState gameState, CardPredicate acceptableCard)
        {
            if (!this.cardsBeingRevealed.AnyWhere(acceptableCard))
            {
                return null;
            }

            Card cardtoTrash = this.actions.GetCardFromRevealedCardsToTrash(gameState, acceptableCard);
            if (cardtoTrash == null)
            {
                throw new Exception("Player must choose a card to trash");
            }

            if (!acceptableCard(cardtoTrash))
            {
                throw new Exception("Card did not meet constraint");
            }

            this.MoveRevealedCardToTrash(cardtoTrash, gameState);

            return cardtoTrash;
        }
        internal Card RequestPlayerTrashOtherPlayersRevealedCard(GameState gameState, CardPredicate acceptableCard,  PlayerState otherPlayer)
        {
            Card cardtoTrash = null;
            if (otherPlayer.cardsBeingRevealed.HasCard(acceptableCard))
            {
                Card cardTypeToTrash = this.actions.GetCardFromOtherPlayersRevealedCardsToTrash(gameState, otherPlayer, acceptableCard);

                cardtoTrash = otherPlayer.cardsBeingRevealed.RemoveCard(cardTypeToTrash);
                if (cardtoTrash == null)
                {
                    throw new Exception("Must choose a revealed card to trash");
                }

                if (!acceptableCard(cardtoTrash))
                {
                    throw new Exception("Card constraint doesnt match.");
                }

                otherPlayer.MoveCardToTrash(cardtoTrash, gameState);
            }

            return cardtoTrash;
        }
        internal Card RequestPlayerTrashCardFromHandOrDiscard(GameState gameState, CardPredicate acceptableCardsToTrash, bool isOptional)
        {
            if (!this.hand.HasCard(acceptableCardsToTrash) &&
                !this.discard.HasCard(acceptableCardsToTrash))
            {
                return null;
            }

            DeckPlacement deckPlacement = DeckPlacement.Default;
            Card cardTypeToTrash = this.actions.GetCardFromHandOrDiscardToTrash(gameState, acceptableCardsToTrash, isOptional, out deckPlacement);
            if (cardTypeToTrash == null)
            {
                if (isOptional)
                {
                    return null;
                }
                else
                {
                    throw new Exception("Player must choose a card to trash");
                }
            }

            if (deckPlacement == DeckPlacement.Hand)
            {
                return this.TrashCardFromHandOfType(gameState, cardTypeToTrash, guaranteeInHand: true);
            }
            else if (deckPlacement == DeckPlacement.Discard)
            {
                return this.TrashCardFromDiscardOfType(gameState, cardTypeToTrash, guaranteeInDiscard: true);
            }
            else
            {
                throw new Exception("Must trash from hand or discard");
            }
        }
Exemple #55
0
 public override Card GetCardFromHandToReveal(GameState gameState, CardPredicate acceptableCard)
 {
     return playerAction.purchaseOrder.GetPreferredCard(gameState, acceptableCard);
 }
        internal Card RequestPlayerGainCardFromTrash(GameState gameState, CardPredicate acceptableCard, string description, bool isOptional = false, DeckPlacement defaultLocation = DeckPlacement.Discard)
        {
            if (!gameState.trash.HasCard(acceptableCard))
                return null;

            Card cardType = this.actions.GetCardFromTrashToGain(gameState, acceptableCard, isOptional);
            if (cardType == null)
            {
                if (isOptional)
                {
                    return null;
                }
                throw new Exception("Must gain a card where " + description);
            }

            if (!acceptableCard(cardType))
            {
                throw new Exception("Card does not meet constraint: " + description);
            }

            Card cardFromTrash = gameState.trash.RemoveCard(cardType);
            if (cardFromTrash == null)
            {
                throw new Exception("Card requested wasnt in the trash");
            }

            this.GainCard(gameState, cardFromTrash, DeckPlacement.Trash, defaultLocation, GainReason.Gain);

            return cardFromTrash;
        }
        internal Card RequestPlayerMoveRevealedCardToHand(GameState gameState, CardPredicate acceptableCard)
        {
            if (!this.cardsBeingRevealed.AnyWhere(acceptableCard))
            {
                return null;
            }

            Card cardToPutInHand = this.actions.GetCardFromRevealedCardsToPutInHand(gameState, acceptableCard);
            if (cardToPutInHand == null)
            {
                throw new Exception("Player must choose a card to put in hand");
            }

            if (!acceptableCard(cardToPutInHand))
            {
                throw new Exception("Card did not meet constraint");
            }

            this.MoveRevealedCardToHand(cardToPutInHand);

            return cardToPutInHand;
        }
        internal Card RequestPlayerTrashCardFromHandAndGainCard(
            GameState gameState,
            CardPredicate acceptableCardsToTrash,
            CostConstraint costConstraint,
            int cost,
            CardRelativeCost cardRelativeCost,
            bool isOptionalToTrash = false,
            bool isOptionalToGain = false,
            DeckPlacement defaultLocation = DeckPlacement.Discard)
        {
            Card trashedCard = this.RequestPlayerTrashCardFromHand(gameState, acceptableCardsToTrash, isOptionalToTrash);
            if (trashedCard != null)
            {
                int cardCost = cardRelativeCost == CardRelativeCost.RelativeCost ? trashedCard.CurrentCoinCost(this) + cost :
                                   cardRelativeCost == CardRelativeCost.AbsoluteCost ? cost : 0;

                CardPredicate cardPredicate;
                if (costConstraint == CostConstraint.Exactly)
                {
                    cardPredicate = acceptableCard => acceptableCard.CurrentCoinCost(this) == cardCost;
                }
                else if (costConstraint == CostConstraint.UpTo)
                {
                    cardPredicate = acceptableCard => acceptableCard.CurrentCoinCost(this) <= cardCost;
                }
                else
                {
                    throw new Exception("Invalid operation");
                }

                return this.RequestPlayerGainCardFromSupply(
                    gameState,
                    cardPredicate,
                    "",
                    isOptionalToGain,
                    defaultLocation);
            }

            return null;
        }
        internal Card RequestPlayerRevealCardFromHand(CardPredicate acceptableCard, GameState gameState)
        {
            if (!this.hand.HasCard(acceptableCard))
            {
                return null;
            }

            Card cardToReveal = this.actions.GetCardFromHandToReveal(gameState,
                card => acceptableCard(card) && this.hand.HasCard(card));

            if (cardToReveal != null)
            {
                Card revealedCard = RevealCardFromHand(cardToReveal, gameState);
                this.MoveAllRevealedCardsToHand();
                return revealedCard;
            }

            return null;
        }
        internal bool RequestPlayerPlayActionFromHand(GameState gameState, CardPredicate acceptableCard, bool isOptional)
        {
            Card cardToPlay = RequestPlayerChooseCardToRemoveFromHandForPlay(gameState, acceptableCard, isTreasure: false, isAction: true, isOptional: isOptional);

            if (cardToPlay != null)
            {
                this.DoPlayAction(cardToPlay, gameState);
            }

            return true;
        }