Dominion.Strategy.Description.MatchDescription.GameStatePredicate C# (CSharp) Method

GameStatePredicate() public method

public GameStatePredicate ( GameState gameState ) : bool
gameState Dominion.GameState
return bool
        public bool GameStatePredicate(GameState gameState)
        {
            int countOfTheSource;

            switch (countSource)
            {
                case CountSource.CountOfPile:
                    countOfTheSource = Strategy.CountOfPile(this.cardType, gameState);
                    break;
                case CountSource.CountAllOwned:
                    countOfTheSource = Strategy.CountAllOwned(this.cardType, gameState);
                    break;
                case CountSource.CountInHand:
                    countOfTheSource = Strategy.CountInHand(this.cardType, gameState);
                    break;
                case CountSource.Always:
                    return true;
                case CountSource.AvailableCoin:
                    countOfTheSource = gameState.Self.AvailableCoins;
                    break;
                case CountSource.CardBeingPlayedIs:
                    return Strategy.CardBeingPlayedIs(this.cardType, gameState);
                default:
                    throw new Exception("Unhandled source case");
            }

            switch (this.comparison)
            {
                case Comparison.GreaterThan:
                    {
                        return countOfTheSource > this.countThreshHold;
                    }
                case Comparison.LessThan:
                    {
                        return countOfTheSource < this.countThreshHold;
                    }
                case Comparison.GreaterThanEqual:
                    {
                        return countOfTheSource >= this.countThreshHold;
                    }
                case Comparison.LessThanEqual:
                    {
                        return countOfTheSource <= this.countThreshHold;
                    }
                case Comparison.Equals:
                    {
                        return countOfTheSource == this.countThreshHold;
                    }
                default:
                    throw new Exception("Unhandled comparison case");
            }
        }

Usage Example

        public static CardAcceptance For(Card card, CountSource countSource, Comparison comparison, int threshhold, GameStatePredicate match)
        {
            MatchDescription descr = new MatchDescription(countSource, card, comparison, threshhold);

            return CardAcceptance.For(card, gameState => descr.GameStatePredicate(gameState) && match(gameState));
        }