public static bool TryFind(Card[] orderedCards, bool[] cards_equality_by_value_helper, out FullHouseHand hand) { var cardGroups = new List<Segment>(10); int startIndx = 0; int count = 1; for (int i = 1; i < orderedCards.Length; i++) { if (cards_equality_by_value_helper[i - 1]) { count++; continue; } else { if (count > 1) { cardGroups.Add(new Segment(startIndx, count)); } startIndx = i; count = 1; } } if (count > 1) { cardGroups.Add(new Segment(startIndx, count)); } Segment? triple = null; Segment? pair = null; foreach (Segment cardGroup in cardGroups) { if (triple != null && pair != null) { break; } if (triple == null && cardGroup.Count > 2) { triple = cardGroup; continue; } if (pair == null && cardGroup.Count > 1) { pair = cardGroup; continue; } } if (triple != null && pair != null) { Segment _triple = triple.Value; Segment _pair = pair.Value; hand = new FullHouseHand() { Card1 = orderedCards[_triple.StartIndx], Card2 = orderedCards[_triple.StartIndx + 1], Card3 = orderedCards[_triple.StartIndx + 2], Card4 = orderedCards[_pair.StartIndx], Card5 = orderedCards[_pair.StartIndx + 1], }; return true; } hand = null; return false; }
public static bool TryFind(Card[] orderedCards, out FullHouseHand hand) { var cardGroups = new List<Segment>(10); int startIndx = 0; int count = 1; Card sampleCard = orderedCards[0]; for (int i = 1; i < orderedCards.Length; i++) { Card card = orderedCards[i]; if (CardComparer.IsEqualByValue(sampleCard, card)) { count++; continue; } else { if (count > 1) { cardGroups.Add(new Segment(startIndx, count)); } startIndx = i; count = 1; sampleCard = card; } } if (count > 1) { cardGroups.Add(new Segment(startIndx, count)); } Segment? triple = null; Segment? pair = null; foreach (Segment cardGroup in cardGroups) { if (triple != null && pair != null) { break; } if (triple == null && cardGroup.Count > 2) { triple = cardGroup; continue; } if (pair == null && cardGroup.Count > 1) { pair = cardGroup; continue; } } if (triple != null && pair != null) { Segment _triple = triple.Value; Segment _pair = pair.Value; hand = new FullHouseHand() { Card1 = orderedCards[_triple.StartIndx], Card2 = orderedCards[_triple.StartIndx + 1], Card3 = orderedCards[_triple.StartIndx + 2], Card4 = orderedCards[_pair.StartIndx], Card5 = orderedCards[_pair.StartIndx + 1], }; return true; } hand = null; return false; }