Exemple #1
0
    protected List <int> GetAllowedCardIndexes()
    {
        int lastCardValue = _MainGameModtroller.DiscardPileLastValue;

        MainGameModtroller.PlayDirection    direction = _MainGameModtroller.Direction;
        ReadOnlyCollection <CardController> handCards = Hand.ReadOnlyCards;
        List <int> allowedCardIndexes = new List <int>();

        if (_MainGameModtroller.MaxDeviationRule && direction != MainGameModtroller.PlayDirection.UNDECIDED)
        {
            allowedCardIndexes.AddRange(handCards.AllIndexesSuchThat(
                                            c => Mathf.Abs(c.CardValue - lastCardValue) <= _MainGameModtroller.MaxDeviationThreshold));

            if (_MainGameModtroller.WildcardRule)
            {
                allowedCardIndexes.AddRange(handCards.AllIndexesSuchThat(
                                                (c, i) => c.CardValue == _MainGameModtroller.WildCardValue && !allowedCardIndexes.Contains(i)));
            }
        }
        else
        {
            for (int i = 0, iMax = handCards.Count; i < iMax; ++i)
            {
                allowedCardIndexes.Add(i);
            }
        }

        for (int i = allowedCardIndexes.LastIndex(); i >= 0; --i)         // Reverse iterate to not invalidate
        {
            if (!((direction == MainGameModtroller.PlayDirection.UNDECIDED) ||
                  (_MainGameModtroller.WildcardRule && handCards[allowedCardIndexes[i]].CardValue == _MainGameModtroller.WildCardValue) ||
                  (direction == MainGameModtroller.PlayDirection.DOWN && handCards[allowedCardIndexes[i]].CardValue <= lastCardValue) ||
                  (direction == MainGameModtroller.PlayDirection.UP && handCards[allowedCardIndexes[i]].CardValue >= lastCardValue)))
            {
                allowedCardIndexes.RemoveAt(i);
            }
        }
        return(allowedCardIndexes);
    }