private Boolean IsThreeOfAKind(ref PokerPlayerEvaluator player) { Boolean result; List <PlayingCard> listOfPlayingCards = player.CardsOnHand; var queryFindThreeOfAKind = from cardsOnHand in listOfPlayingCards group cardsOnHand by cardsOnHand.Rank into cards where cards.Count() == 3 orderby Convert.ChangeType(cards.Key, cards.Key.GetTypeCode()) select new { last = cards.Key, count = cards.Count() }; if (queryFindThreeOfAKind.Count() >= 1) { var _rank = queryFindThreeOfAKind.DefaultIfEmpty().First().last; RankType d = (RankType)_rank; player.IsThreeOfAKind = true; result = true; } else { result = false; } return(result); }
private Boolean IsFlush(ref PokerPlayerEvaluator player) { Boolean result; List <PlayingCard> listOfPlayingCards = player.CardsOnHand; var queryFindFlush = from cardsOnHand in listOfPlayingCards group cardsOnHand by cardsOnHand.Suit into cards orderby Convert.ChangeType(cards.Key, cards.Key.GetTypeCode()) select new { Suit = cards.Key, Count = cards.Count() }; if (queryFindFlush.Count() == 1) { var _suit = queryFindFlush.DefaultIfEmpty().First().Suit; player.Suit = (SuitType)_suit; player.IsFlush = true; result = true; } else { result = false; } return(result); }
private void GetHighCard(ref PokerPlayerEvaluator player) { List <PlayingCard> list = player.CardsOnHand; var queryGetByGroupHaving = from student in list select new { Total = list.Sum(x => (int)x.Rank) }; var _cards = queryGetByGroupHaving.DefaultIfEmpty().First(); player.Score = _cards.Total; }
protected override void Evaluate() { foreach (KeyValuePair <string, PokerPlayer> pair in ListOfPokerPlayers) { string _playerName = pair.Value.Name; PokerPlayerEvaluator playerEvaluationResult = new PokerPlayerEvaluator(); playerEvaluationResult.Copy(pair.Value); // .CardsOnHand = pair.Value.CardsOnHand; //ListOfPokerPlayers[_playerName].Name = "d"; if (IsFlush(ref playerEvaluationResult)) { } else if (IsThreeOfAKind(ref playerEvaluationResult)) { } else { IsPair(ref playerEvaluationResult); } GetHighCard(ref playerEvaluationResult); listOfProcessed.Add(playerEvaluationResult); } var resultSet = from foobars in listOfProcessed orderby foobars.IsFlush descending, foobars.IsThreeOfAKind descending, foobars.IsPair descending, foobars.Score descending, Convert.ChangeType(foobars.Suit, foobars.Suit.GetTypeCode()) ascending select foobars; foreach (var single in resultSet) { Console.WriteLine("{0} {1} {2} {3} {4} {5} ", single.Name, single.Suit.ToString(), single.IsFlush, single.IsPair, single.IsThreeOfAKind, single.Score); } }