예제 #1
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForHighCard(List <Card> orderedCards, HandStats stats)
        {
            Rank = Rank.HighCard;

            Cards = orderedCards.Take(5).ToList();

            return(true);
        }
예제 #2
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private HandStats GetHandStats(List <Card> orderedCards)
        {
            var stats = new HandStats();

            var lastVal  = -1;
            var runCount = 1;


            for (int i = 0; i < orderedCards.Count; i++)
            {
                var c = orderedCards[i];

                if (++stats.suitCount[(int)c.Suit] == 5)
                {
                    stats.isFlush   = true;
                    stats.flushSuit = c.Suit;
                }

                switch (++stats.valCount[c.Value])
                {
                case 2:
                    stats.pairCount++;
                    break;

                case 3:
                    stats.pairCount--;
                    stats.tripCount++;
                    break;

                case 4:
                    stats.tripCount--;
                    stats.isQuad = true;
                    break;
                }

                if (!stats.isStraight)
                {
                    if (c.Value + 1 == lastVal)
                    {
                        stats.isStraight |= ++runCount == 5;
                    }
                    else if (c.Value != lastVal)
                    {
                        stats.runIdx = i;
                        runCount     = 1;
                    }

                    lastVal = c.Value;
                }
            }

            if (runCount == 4 && lastVal == 0 && stats.valCount[12] > 0)
            {
                stats.isStraight = true;
            }

            return(stats);
        }
예제 #3
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForStraight(List <Card> orderedCards, HandStats stats)
        {
            if (stats.isStraight)
            {
                Rank = Rank.Straight;

                Cards = GetStraightCards(orderedCards, stats);

                return(true);
            }

            return(false);
        }
예제 #4
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForFlush(List <Card> orderedCards, HandStats stats)
        {
            if (stats.isFlush)
            {
                Rank = Rank.Flush;

                Cards = new List <Card>(orderedCards.Where(c => c.Suit == stats.flushSuit).Take(5));

                return(true);
            }

            return(false);
        }
예제 #5
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForPair(List <Card> orderedCards, HandStats stats)
        {
            if (stats.pairCount == 1)
            {
                Rank = Rank.Pair;

                var pairVal = stats.valCount.LastIndexOf(2);

                Cards = new List <Card>(orderedCards.Where(c => c.Value == pairVal));

                BackfillCards(orderedCards, pairVal);

                return(true);
            }

            return(false);
        }
예제 #6
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForThreeOfAKind(List <Card> orderedCards, HandStats stats)
        {
            if (stats.tripCount > 0)
            {
                Rank = Rank.ThreeOfAKind;

                var tripVal = stats.valCount.LastIndexOf(3);

                Cards = new List <Card>(orderedCards.Where(c => c.Value == tripVal));

                BackfillCards(orderedCards, tripVal);

                return(true);
            }

            return(false);
        }
예제 #7
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForFourOfAKind(List <Card> orderedCards, HandStats stats)
        {
            if (stats.isQuad)
            {
                Rank = Rank.FourOfAKind;

                var quadVal = stats.valCount.LastIndexOf(4);

                Cards = new List <Card>(orderedCards.Where(c => c.Value == quadVal))
                {
                    orderedCards.First(c => c.Value != quadVal)
                };

                return(true);
            }

            return(false);
        }
예제 #8
0
        public void OnHand(HandStats hand, long timestamp)
        {
            bool wasMakingGesture = isMakingGesture && lastHandId == hand.Id;

            isMakingGesture = isGesture(hand);

            lastHandId = hand.Id;

            if (!wasMakingGesture && isMakingGesture)
            {
                lastGestureTime = timestamp;
            }
            else if (!isMakingGesture)
            {
                if (wasMakingGesture && timestamp >= lastGestureTime + MIN_COOLDOWN_TIME)
                {
                    lastTriggerHandId = -1;
                }
                return;
            }

            // Make sure the trigger is detected for a bit, not just random noise
            if (timestamp <= lastGestureTime + MIN_DETECTION_TIME)
            {
                return;
            }

            // Don't let the same hand trigger gesture again
            if (lastTriggerHandId == hand.Id)
            {
                return;
            }

            // Only trigger action at most once every second
            if (timestamp <= lastActionTime + MIN_TRIGGER_DEBOUNCE)
            {
                return;
            }

            // Trigger a gesture!
            lastActionTime    = timestamp;
            lastTriggerHandId = hand.Id;
            onGesture();
        }
예제 #9
0
        public void OnHand(HandStats hand, long timestamp)
        {
            if (!canGesture(hand))
            {
                return;
            }

            float currentValue = discreteValue(hand);

            if (float.IsNaN(lastTriggerValue))
            {
                lastTriggerValue = currentValue;
                return;
            }

            float diff = lastTriggerValue - currentValue;

            if (Math.Abs(diff) < triggerThreshold)
            {
                return;
            }

            bool isPositiveChange = diff >= 0;

            if (isPositiveChange)
            {
                if (lastNegativeTriggerTime + DirectionDebounceTime >= timestamp)
                {
                    return;
                }
                lastPositiveTriggerTime = timestamp;
            }
            else
            {
                if (lastPositiveTriggerTime + DirectionDebounceTime >= timestamp)
                {
                    return;
                }
                lastNegativeTriggerTime = timestamp;
            }

            lastTriggerValue = currentValue;
            onGesture(isPositiveChange);
        }
예제 #10
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForTwoPair(List <Card> orderedCards, HandStats stats)
        {
            if (stats.pairCount > 1)
            {
                Rank = Rank.TwoPair;

                var pairVal1 = stats.valCount.LastIndexOf(2);

                var pairVal2 = stats.valCount.LastIndexOf(2, pairVal1 - 1);

                Cards = new List <Card>(orderedCards.Where(c => c.Value == pairVal1 || c.Value == pairVal2));

                BackfillCards(orderedCards, pairVal1, pairVal2);

                return(true);
            }

            return(false);
        }
예제 #11
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForFullHouse(List <Card> orderedCards, HandStats stats)
        {
            if (stats.tripCount > 1 || (stats.tripCount > 0 && stats.pairCount > 0))
            {
                Rank = Rank.FullHouse;

                var tripVal = stats.valCount.LastIndexOf(3);

                Cards = new List <Card>(orderedCards.Where(c => c.Value == tripVal));

                var pairVal = stats.tripCount > 1 ? Math.Max(stats.valCount.LastIndexOf(3, tripVal - 1), stats.valCount.LastIndexOf(2)) : stats.valCount.LastIndexOf(2);

                Cards.AddRange(orderedCards.Where(c => c.Value == pairVal).Take(2));

                return(true);
            }

            return(false);
        }
예제 #12
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private bool EvalForStraightFlush(List <Card> orderedCards, HandStats stats)
        {
            if (stats.isFlush && stats.isStraight)
            {
                var flushCards = orderedCards.Where(c => c.Suit == stats.flushSuit).ToList();

                var flushStats = GetHandStats(flushCards);

                if (flushStats.isStraight)
                {
                    Rank = Rank.StraighFlush;

                    Cards = GetStraightCards(flushCards, flushStats);

                    return(true);
                }
            }

            return(false);
        }
예제 #13
0
파일: Program.cs 프로젝트: schaabs/sandbox
        private List <Card> GetStraightCards(List <Card> orderedCards, HandStats stats)
        {
            var cards = new List <Card>()
            {
                orderedCards[stats.runIdx]
            };

            for (int i = stats.runIdx + 1; i < orderedCards.Count && cards.Count < 5; i++)
            {
                if (orderedCards[i].Value != cards[cards.Count - 1].Value)
                {
                    cards.Add(orderedCards[i]);
                }
            }

            if (cards.Count < 5)
            {
                cards.Add(orderedCards[0]);
            }

            return(cards);
        }