Exemplo n.º 1
0
        public IAnalyzer Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            try
            {
                IAnalyzer result = null;

                var highestHand = CardHelper.FindBestHand(string.Join("", playerCards.Select(c => c.CardStringValue)), boardCards.ToString());

                var analyzers = ReferenceEquals(highestHand, null) ? _combinations : _combinations.Where(x => x.IsValidAnalyzer(highestHand)).ToArray();

                if (playerCards.Count() > 2 && !string.IsNullOrEmpty(highestHand.PocketCards))
                {
                    result = analyzers.FirstOrDefault(combination => combination.Analyze(CardGroup.Parse(highestHand.PocketCards), boardCards)) ?? new StubAnalyzer();
                }
                else
                {
                    result = analyzers.FirstOrDefault(combination => combination.Analyze(playerCards, boardCards)) ?? new StubAnalyzer();
                }

                return(result);
            }
            catch (Exception ex)
            {
                LogProvider.Log.Error(this, String.Format("Hand Analyzer Error occurred: Player cards = {0}; Board Cards = {1}", string.Join("", playerCards.Select(c => c.CardStringValue)), boardCards.ToString()), ex);
            }

            return(new StubAnalyzer());
        }