public void HighCard4() { var whiteHand = new Hand("3H 4D 5S 9C KD"); var blackHand = new Hand("2C 4H 5S 9C KH"); Assert.Greater(whiteHand, blackHand, "White should be the winner"); }
public void HighCardWins() { var whiteHand = new Hand("2H 3D 5S 9C KD"); var blackHand = new Hand("2C 3H 4S 8C AH"); Assert.Greater(blackHand, whiteHand, "Black should be the winner"); }
public void HighCardTie() { var whiteHand = new Hand("3H 4D 5S 9C KD"); var blackHand = new Hand("3C 4H 5S 9C KH"); Assert.AreEqual(0, whiteHand.CompareTo(blackHand), "Should be a tie"); }
public void FourOfAKindBeatsFullHouse() { var low = new Hand("AH KS KC AD KH"); var high = new Hand("2H 2C 2D 2S 5H"); Assert.Greater(high, low, "White should be the winner"); }
public IScore Score(Hand hand) { var Cards = hand.Cards; CompositeScore handScore = new CompositeScore(); var sets = (from c in Cards group c by c.Value into g orderby g.Key select new ValueSet{ Value = g.Key, Count = g.Count() }).ToList(); var suits = (from c in Cards group c by c.Suit into g where g.Count() == 5 select new SuitSet {Suit = g.Key, Count = g.Count(), High = g.Max(c => c.Value)}). FirstOrDefault(); //linq-terbation? var scores = (from m in HandEvaluationMap.Map from s in sets where m.Condition(s, suits, sets) select m.ScoreFactory(s, suits, sets)).ToList(); scores.ForEach(handScore.Add); return handScore; }
public void FlushBeatsStraight() { var high = new Hand("2H 3H 4H 5H 7H"); var low = new Hand("10H JS QS KC AH"); Assert.Greater(high, low); }
private static bool isFlush(Hand hand) { return hand.Cards .Select(c => c.Suit) .GroupBy(s => s) .Count() == 1; }
public static Score GetScore(Hand hand) { if (isRoyalFlush(hand)) return Score.RoyalFlush; if (isStraightFlush(hand)) return Score.StraightFlush; if (isFourOfAKind(hand)) return Score.FourOfAKind; if (isFullHouse(hand)) return Score.FullHouse; if (isFlush(hand)) return Score.Flush; if (isStraight(hand)) return Score.Straight; if (isThreeOfAKind(hand)) return Score.ThreeOfAKind; if (isTwoPair(hand)) return Score.TwoPair; if (isPair(hand)) return Score.Pair; return Score.HighCard; }
public void FullHouseBeatsFlush() { var whiteHand = new Hand("2H 4S 4C 2D 4H"); var blackHand = new Hand("2H 3H 4H 5H 7H"); Assert.Greater(whiteHand, blackHand, "White should be the winner"); }
private static GroupResult[] duplicated(Hand hand) { return hand.Cards .Select(c => c.NumberValue) .OrderByDescending(n => n) .GroupBy(n => n) .Where(g => g.Count() > 1) .Select(g => new GroupResult { Value = g.Key, Count = g.Count() }) .ToArray(); }
public void ThreeOfAKindBeatsTwoPair() { var high = new Hand("2H 2S 5C 2D AH"); var low = new Hand("2S 5H 5D 2S JS"); Assert.Greater(high, low); }
public void StraightFlushBeatsFourOfAKind() { var high = new Hand("2H 3H 4H 5H 6H"); var low = new Hand("AH AC AD AS KH"); Assert.Greater(high, low, "White should be the winner"); }
public void StraightBeatsThreeOfAKind() { var high = new Hand("2H 3S 4S 5S 6S"); var low = new Hand("2H 3S 7S 7C 7H"); Assert.Greater(high, low); }
private static bool isStraight(Hand hand) { var ordered = orderedNumbers(hand); if (Enumerable.SequenceEqual(ordered, Enumerable.Range(ordered[0], 5))) return true; return isLowestStraight(ordered); }
private static int[] orderedNumbers(Hand hand) { return hand.Cards .Select(c => c.NumberValue) .OrderBy(n => n) .ToArray(); }
public void TwoPairTakeHighestPair() { var whiteHand = new Hand("2H 5S 5C 2D JH"); var blackHand = new Hand("2S 4S 4S 2H AS"); Assert.Greater(whiteHand, blackHand, "White should be the winner"); }
private static bool isFullHouse(Hand hand) { return isThreeOfAKind(hand) && isPair(hand); }
private static bool isFourOfAKind(Hand hand) { return duplicated(hand).SingleOrDefault(v => v.Count == 4) != null; }
public void Tie() { var whiteHand = new Hand("2H 3D 5S 9C KD"); var blackHand = new Hand("2D 3H 5C 9S KH"); Assert.AreEqual(0, whiteHand.CompareTo(blackHand), "This hand should be a tie"); }
public void TwoPairBeatsOnePair() { var whiteHand = new Hand("2H 3S 3C 2D JH"); var blackHand = new Hand("AS 8S 3H QS AS"); Assert.Greater(whiteHand, blackHand, "White should be the winner"); }
private static bool isThreeOfAKind(Hand hand) { var values = duplicated(hand); return values.Length > 0 && values.SingleOrDefault(v => v.Count == 3) != null; }
public void HighPairBeatsLowPair() { var whiteHand = new Hand("2H 4S 5C 2D 6H"); var blackHand = new Hand("2S 8S AS QS 8S"); Assert.Greater(blackHand, whiteHand, "Black should be the winner"); }
private static bool isTwoPair(Hand hand) { var values = duplicated(hand); return values.Length == 2 && values.All(v => v.Count == 2); }
public void PairBeatsHighCard() { var whiteHand = new Hand("2H 4S 5C 2D 6H"); var blackHand = new Hand("2S 8H AS QS 3S"); Assert.Greater(whiteHand, blackHand, "White should be the winner"); }
private static bool isStraightFlush(Hand hand) { return isStraight(hand) && isFlush(hand); }
public void SamePairTakeHighCard() { var whiteHand = new Hand("2H QS KC 2D JH"); var blackHand = new Hand("2S 8S AS QS 2S"); Assert.Greater(blackHand, whiteHand, "Black should be the winner"); }
public void SameTwoPairTakeHighestCard() { var whiteHand = new Hand("2H 5S 5C 2D AH"); var blackHand = new Hand("2S 5H 5D 2S JS"); Assert.Greater(whiteHand, blackHand, "White should be the winner"); }
public void NotAStraight() { var high = new Hand("2H 3S 3S 5S 6S"); var low = new Hand("2H 3S 4S 5C 7H"); Assert.Greater(high, low); }
private static bool isRoyalFlush(Hand hand) { return isStraightFlush(hand) && orderedNumbers(hand).Last() == ACE; }