Пример #1
0
        public List <Hand> Compare(List <Hand> handsToCompare)
        {
            Logger.Log($"Entering criteria check for {nameof(HighCard)}.");

            // create the hand wrappers from the given hands
            List <HandWrapper> handWrappers = new List <HandWrapper>();

            handsToCompare.ForEach(x => handWrappers.Add(new HandWrapper(x)));

            // put all cards into remaining cards list so they can be evaluated like a tie-breaker
            handWrappers.ForEach(x => x.RemainingCards = x.WorkingCards);
            handWrappers = WinCriteriaHelpers.FindHighestHandByRemainingCards(handWrappers);

            if (handWrappers.Count > 0)
            {
                Logger.Log($"Exiting criteria check for {nameof(HighCard)} with winner(s).");
                return(handWrappers.Select(x => x.Hand).ToList());
            }

            Logger.Log($"Exiting criteria check for {nameof(HighCard)} with no winner.");
            return(null);
        }
Пример #2
0
 List <HandWrapper> DetermineHighestWinners(List <HandWrapper> handWrappers)
 {
     // copy winning cards into remaining card hands, to break the tie as if they're the "remaining" cards
     handWrappers.ForEach(x => { x.RemainingCards = x.WinningCards; });
     return(WinCriteriaHelpers.FindHighestHandByRemainingCards(handWrappers));
 }
Пример #3
0
        public List <Hand> Compare(List <Hand> handsToCompare)
        {
            Logger.Log($"Entering criteria check for {WinName} with {handsToCompare.Count} hands.");

            // create the hand wrappers from the given hands
            List <HandWrapper> handWrappers = new List <HandWrapper>();

            handsToCompare.ForEach(x => handWrappers.Add(new HandWrapper(x)));

            // first check to see if each hand passes the match criteria
            for (int i = 0; i < handWrappers.Count; i++)
            {
                handWrappers[i].Result = Ranker.CompareResult.None;
                CheckIfQualifies(handWrappers[i], numberRequirement);
            }

            // next check if any met criteria
            handWrappers.RemoveAll(x => x.Result != Ranker.CompareResult.Win);
            if (!handWrappers.Any())       // if there are no winners, return null
            {
                Logger.Log($"Exiting criteria check for {WinName} with no winner.");
                return(null);
            }
            else if (numberRequirementSecond > 0)   // if needs to look for a 2nd match in remaining cards...
            {
                Logger.Log($"Checking for secondary match of {numberRequirementSecond} cards.");

                // copy remaining cards from the already winning hands to a new temporary working card list
                List <HandWrapper> localCopyOfHands = new List <HandWrapper>();
                foreach (var winningHand in handWrappers)
                {
                    localCopyOfHands.Add(new HandWrapper(new Hand(winningHand.Hand.Name, winningHand.RemainingCards)));
                }

                // check to see if each one qualifies for the 2nd match
                for (int i = 0; i < localCopyOfHands.Count; i++)
                {
                    CheckIfQualifies(localCopyOfHands[i], numberRequirementSecond);
                }

                // remove any that didn't meet criteria
                localCopyOfHands.RemoveAll(x => x.Result != Ranker.CompareResult.Win);

                if (!localCopyOfHands.Any())
                {
                    Logger.Log($"Exiting criteria check for {WinName} with no winner.");
                    return(null);
                }

                // remove any winningHandWrappers that don't have a matching localCopyOfHands
                handWrappers.RemoveAll(x => !localCopyOfHands.Any(y => y.Hand.Name == x.Hand.Name));

                // for each of the hands with a primary match
                foreach (var winningHandWrapper in handWrappers)
                {
                    HandWrapper secondaryHandWrapper = localCopyOfHands.Single(x => x.Hand.Name == winningHandWrapper.Hand.Name);

                    // put in its respective winning/remaining lists to be compared as a final tie-breaker
                    winningHandWrapper.WinningCards   = winningHandWrapper.WinningCards.Where(x => x.Number != Card.Numbers.Joker).ToList();
                    winningHandWrapper.RemainingCards = secondaryHandWrapper.WinningCards;
                }
            }
            else if (handWrappers.Count() == 1)  //  or if there's a single winner, return results
            {
                Logger.Log($"Exiting criteria check for {WinName} with a winner (immediately).");
                return(handWrappers.Select(x => x.Hand).ToList());
            }

            // try to break the tie with best winning cards
            List <HandWrapper> winningTiedHandWrappers = DetermineHighestWinners(handWrappers);

            if (winningTiedHandWrappers.Count == 1)
            {
                Logger.Log($"Exiting criteria check for {WinName} with a winner (tie breaker with higher match).");
                return(winningTiedHandWrappers.Select(x => x.Hand).ToList());
            }

            // break the tie with remaining cards
            List <HandWrapper> winningRemainingTiedHandWrappers = WinCriteriaHelpers.FindHighestHandByRemainingCards(winningTiedHandWrappers);

            if (winningRemainingTiedHandWrappers.Count > 0)
            {
                Logger.Log($"Exiting criteria check for {WinName} with winner(s) (tie breaker with higher kickers).");
                return(winningRemainingTiedHandWrappers.Select(x => x.Hand).ToList());
            }

            Logger.Log($"Exiting criteria check for {WinName} with no winner.");
            return(null);
        }