public CardSet FindRankSetCombination(PhomCard card) { CardSet combination = new CardSet(); foreach (PhomCard c in cards) { if (card.HasSameRank(c)) { combination.AddCard(c); } } if (combination.Length() <= 2) { combination.Reset(); } else { combination.Sort(Order.ASC); } return(combination); }
public CardSet FindStraightCombination(PhomCard card) { CardSet combination = new CardSet(); int topRank = card.GetRank(); int bottomRank = topRank; int index = cards.IndexOf(card); for (int i = index - 1; i >= 0; i--) { if (card.HasSameSuit(cards [i]) && cards [i].GetRank() == bottomRank - 1) { combination.AddCard(cards [i]); bottomRank--; } } combination.AddCard(card); for (int i = index + 1; i < cards.Count; i++) { if (card.HasSameSuit(cards [i]) && cards [i].GetRank() == topRank + 1) { combination.AddCard(cards [i]); topRank++; } } if (combination.Length() <= 2) { combination.Reset(); } else { combination.Sort(Order.ASC); } return(combination); }
public override List <Combination> FindCombinations() { singleCards.Reset(); combinations.Clear(); Sort(Order.ASC); int i = 0; while (true) { if (i >= numCards - 2) { for (int j = i; j < numCards; j++) { singleCards.AddCard(At(j)); } break; } PhomCombination combination = new PhomCombination(SubSetList(i, 3)); if (combination.IsRankSet()) { PhomCombination combination2 = null; if (i + 4 < numCards) { combination2 = new PhomCombination(SubSetList(i, 4)); } if (combination2 != null && combination2.IsRankSet()) { i += 4; combinations.Add(combination2); } else { combinations.Add(combination); i += 3; } } else if (combination.IsStraight()) { int j = 4; PhomCombination combination2 = null; while (i + j < numCards) { combination2 = new PhomCombination(SubSetList(i, j)); if (combination2.IsStraight()) { combination = combination2; } else { break; } j++; } combinations.Add(combination); i += j - 1; } else { singleCards.AddCard(At(i)); i++; } } return(combinations); }