Beispiel #1
0
        protected virtual string GetBestCards(IEnumerable <string> totalCombination, ICardsComparer comparer)
        {
            string bestCards = null;

            foreach (var cards in totalCombination)
            {
                if (!comparer.IsValid(cards))
                {
                    continue;
                }

                if (bestCards == null)
                {
                    bestCards = cards;
                    continue;
                }

                var compareResult = comparer.Compare(cards, bestCards);

                if (compareResult > 0)
                {
                    bestCards = cards;
                }
            }

            return(bestCards);
        }
Beispiel #2
0
        protected override IEnumerable <int> GetWinnersInternal(ICardsComparer comparer)
        {
            // omaha rules
            // 2 from player cards and 3 from table
            // get all possbile player combinations and get higher of them
            // compare best combinations between players and select the highest
            var bestCardsByPlayer = playersCards
                                    .Select(playerCards => new { Seat = playerCards.Key, BestCards = GetPlayerBestCards(playerCards.Value, comparer) })
                                    .Where(player => player.BestCards != null)
                                    .ToArray();

            var bestPlayers = new List <int>();

            int?   bestPlayerSeat  = null;
            string bestPlayerCards = null;

            foreach (var bestCards in bestCardsByPlayer)
            {
                if (bestPlayerSeat == null)
                {
                    bestPlayerSeat  = bestCards.Seat;
                    bestPlayerCards = bestCards.BestCards;
                    bestPlayers.Add(bestCards.Seat);
                    continue;
                }

                // compare player best cards to current best cards
                var compareResult = comparer.Compare(bestCards.BestCards, bestPlayerCards);

                // if player cards are better then clear all best players and reset best cards and seat
                if (compareResult > 0)
                {
                    bestPlayers.Clear();
                    bestPlayerSeat  = bestCards.Seat;
                    bestPlayerCards = bestCards.BestCards;
                    bestPlayers.Add(bestCards.Seat);
                }
                else if (compareResult == 0)
                {
                    bestPlayers.Add(bestCards.Seat);
                }
            }

            return(bestPlayers);
        }