/// <summary> /// Peek hand /// </summary> public CardHand PeekHand(int length) { if (length < 0 || length >= m_Items.Count) { throw new ArgumentOutOfRangeException(nameof(length)); } CardHand result = new CardHand(false); for (int i = 0; i < length; ++i) { result.m_Items.Add(m_Items[i]); } m_Items.RemoveRange(0, length); return(result); }
/// <summary> /// Build Pack /// </summary> /// <param name="from">From value (included)</param> /// <param name="to">To value (included)</param> /// <param name="jokers">jokers</param> /// <returns></returns> public static CardHand BuildPack(int from, int to, int jokers) { if (from <= 0) { throw new ArgumentOutOfRangeException(nameof(from)); } else if (to >= 15) { throw new ArgumentOutOfRangeException(nameof(to)); } else if (from > to) { throw new ArgumentOutOfRangeException(nameof(to)); } else if (jokers < 0) { throw new ArgumentOutOfRangeException(nameof(jokers)); } CardSuit[] suits = new CardSuit[] { CardSuit.Spades, CardSuit.Hearts, CardSuit.Diamonds, CardSuit.Clubs }; var cards = Enumerable .Range(from, to - from + 1) .SelectMany(index => suits.Select(suit => new Card(index, suit))) .Concat(Enumerable .Range(0, jokers) .Select(index => new Card(0, CardSuit.None))); CardHand result = new CardHand(true); result.m_Items.AddRange(cards); return(result); }