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); }
/// <summary> /// Method for taking new card and adding to card holder's hand /// </summary> /// <param name="card">The card received by card holder</param> public void TakeCard(Card card) { hand.AddCard(card); int score = scoreCounter.CountScore(hand); // throw exception if card holder's got blackjack (watch out!) if (score == 21) { throw new BlackjackException(name); } // throw exception if card holder's got bust (watch out!) if (score > 21) { throw new BustException(name, score); } }
private CardSet searchforCards() { cards = FindObjectsOfType(typeof(GameObject)) as GameObject[]; CardSet cs = new CardSet(); for (var i = 0; i < cards.Length; i++) { if (cards[i].name.StartsWith("Coin") | cards[i].name.StartsWith("Cucumber") | cards[i].name.StartsWith("Sword") | cards[i].name.StartsWith("Goblet")) { var trackable = cards[i].GetComponent <TrackableBehaviour>(); var status = trackable.CurrentStatus; if (status == TrackableBehaviour.Status.TRACKED) { //Debug.LogWarning(cards[i].name); //outText = outText + cards[i].name + ", "; cs.AddCard(BuildCard(cards[i])); } } } return(cs); }
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); }
void ClassifyCards(ref CardSet oneSetCards, ref CardSet twoSetsCards) { for (int i = 0; i < cards.Count; i++) { int numSameRank = 0; for (int j = 0; j < cards.Count; j++) { if (i != j && cards [i].HasSameRank(cards [j])) { numSameRank++; if (numSameRank >= 3) { break; } } } bool isInStraight = false; bool hasLowerCard = false; bool hasLowerCard2 = false; bool hasHigherCard = false; bool hasHigherCard2 = false; for (int j = 0; j < cards.Count; j++) { if (i != j && cards [i].HasSameSuit(cards [j])) { if (cards [i].GetRank() == cards [j].GetRank() + 1) { hasLowerCard = true; } else if (cards [i].GetRank() == cards [j].GetRank() - 1) { hasHigherCard = true; } else if (cards[i].GetRank() == cards [j].GetRank() - 2) { hasHigherCard2 = true; } else if (cards[i].GetRank() == cards [j].GetRank() + 2) { hasLowerCard2 = true; } } isInStraight = ((hasLowerCard && hasHigherCard) || (hasLowerCard && hasLowerCard2) || (hasHigherCard && hasHigherCard2)); if (isInStraight) { break; } } if (numSameRank > 1 && isInStraight) { twoSetsCards.AddCard(cards [i]); } else if (numSameRank > 1 || isInStraight) { oneSetCards.AddCard(cards [i]); } } // Debug.Log ("Check:" + ToCardString ()); // Debug.Log ("One:" + oneSetCards.ToCardString ()); // Debug.Log ("Two:" + twoSetsCards.ToCardString () + " " + twoSetsCards.Length()); }
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); }