/// <summary> /// Generate random hands, and write out the details of those under-ranked /// by the rank predicate methods. This would happen if one or more of the /// rank predicate methods returned false negatives. /// </summary> public static void WriteErrantRandomHands( int numSamplesPerSimpleRank = 100, int numCardsDealt = 5, int numCardsInFinalHand = 5) { Ranker ranker = new Ranker(numCardsInFinalHand, false); TestHandGenerator handGen = new TestHandGenerator(0); foreach (SimpleRank sRank in Ranker.StandardRanks) { // Console.WriteLine(); Console.Write("Press enter to see errant hands of type {0:s}", sRank.ToString()); Console.Out.Flush(); Console.ReadLine(); for (int i = 0; i < 1000; i++) { Hand h = handGen.Generators[sRank](numCardsDealt, numCardsInFinalHand); FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; ranker.GetFullRank(h, null, out fRank, out hcsRank, out hcsFill); if (fRank.SRank != sRank) { Console.WriteLine("Attempt to create {0:s} yielded {1:s}", sRank.ToString(), fRank.SRank.ToString()); Console.Write(" "); Hand.WriteHandData(h, null, fRank, hcsRank, hcsFill); } } } }
public static void WriteErrantRandomHands(Ranker ranker, int numSamplesPerSimpleRank) { Console.WriteLine(); Console.WriteLine("Press enter to display hands that might uncover rank predicate errors."); Console.Out.Flush(); Console.ReadLine(); TestHandGenerator.WriteErrantRandomHands(numSamplesPerSimpleRank, 7, 5); }
static void Main(string[] args) { Ranker ranker = new Ranker(); // which execution mode? Console.WriteLine("1. Enter Cards\n2. Run Tests"); int userAnswer; int.TryParse(Console.ReadLine(), out userAnswer); // enable debug logging? Console.WriteLine("Use verbose logging? (Y/N)"); string answerLogging = Console.ReadLine().ToUpper(); Logger.LogDebug = answerLogging == "Y"; if (userAnswer == 1) // enter cards { Console.WriteLine("\n\nEnter Player's Cards, each card separated by a comma, " + "and each player separated by a period." + "\n\nexample: Two Heart, Five Diamond, Jack Spade, Joker Wild, Ace Club. " + "Seven Diamond, Six Heart, Seven Club, Six Spade, Joker Wild.\n"); List <Hand> handsFromPlayer = ParseUserHands(Console.ReadLine()); if (handsFromPlayer == null) { Console.WriteLine("Exiting program."); Console.ReadLine(); return; } string winType = ""; List <Hand> winningHands = ranker.DetermineWinner(handsFromPlayer, ref winType); if (winningHands == null) { Console.WriteLine($"Sorry, no winning hand could be determined."); Console.ReadLine(); return; } Console.WriteLine($"\n--The Hands:--\n{string.Join("\n", handsFromPlayer)}"); Console.WriteLine($"\nThe winner is: {string.Join(" & ", winningHands.Select(x => x.Name))} with a {winType}!"); Console.ReadLine(); } else if (userAnswer == 2) // run test data sets { RunTests(ranker); Console.ReadLine(); return; } }
public static void WriteTestHandProfiles(Ranker ranker, IEnumerable <Card> wilds) { Console.WriteLine(); Console.WriteLine("Press enter to write out full evaluation of random hands."); Console.Out.Flush(); Console.ReadLine(); foreach (Hand h in TestHands.Hands) { TestRankProfile.WriteRankProfile(h, wilds, ranker); } }
public static void WriteTestHandProfiles(Ranker ranker, IEnumerable<Card> wilds) { Console.WriteLine(); Console.WriteLine("Press enter to write out full evaluation of random hands."); Console.Out.Flush(); Console.ReadLine(); foreach (Hand h in TestHands.Hands) { TestRankProfile.WriteRankProfile(h, wilds, ranker); } }
public static void WriteTestHandRanks(Ranker ranker, IEnumerable <Card> wilds) { Console.WriteLine(); Console.WriteLine("Press enter to write out evaluation of each test hand for each rank."); Console.ReadLine(); foreach (Hand h in TestHands.Hands) { FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; ranker.GetFullRank(h, wilds, out fRank, out hcsRank, out hcsFill); Hand.WriteHandData(h, wilds, fRank, hcsRank, hcsFill); } }
public static void WriteTestHandRanks(Ranker ranker, IEnumerable<Card> wilds) { Console.WriteLine(); Console.WriteLine("Press enter to write out evaluation of each test hand for each rank."); Console.ReadLine(); foreach (Hand h in TestHands.Hands) { FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; ranker.GetFullRank(h, wilds, out fRank, out hcsRank, out hcsFill); Hand.WriteHandData(h, wilds, fRank, hcsRank, hcsFill); } }
public static void WriteRankProfile(Hand hand, IEnumerable<Card> wildCards, Ranker ranker) { HandInfo hi = new HandInfo(hand, wildCards); foreach (SimpleRank sRank in Ranker.StandardRanks) { FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; if (ranker.RankPredicateMap[sRank](hi, out fRank, out hcsRank, out hcsFill)) { Console.WriteLine("Examining hand as a hand of rank {0:s}", fRank.SRank.ToString()); Console.Write(" "); Hand.WriteHandData(hand, wildCards, fRank, hcsRank, hcsFill); } } }
public static void WriteRankProfile(Hand hand, IEnumerable <Card> wildCards, Ranker ranker) { HandInfo hi = new HandInfo(hand, wildCards); foreach (SimpleRank sRank in Ranker.StandardRanks) { FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; if (ranker.RankPredicateMap[sRank](hi, out fRank, out hcsRank, out hcsFill)) { Console.WriteLine("Examining hand as a hand of rank {0:s}", fRank.SRank.ToString()); Console.Write(" "); Hand.WriteHandData(hand, wildCards, fRank, hcsRank, hcsFill); } } }
public Hand GetRandomHighCard(int numCardsDealt, int numCardsInFinalHand) { Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; Ranker ranker = new Ranker(numCardsInFinalHand, false); do { hand = new Hand(GetRandomCards(numCardsDealt)); hcsRank = null; hcsFill = null; ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > SimpleRank.HighCard); return(hand); }
static void Main(string[] args) { // List<Card> wilds = null; // List<Card> wilds = new List<Card>() { Card.S5, Card.S6, Card.S7, Card.S8 }; List <Card> wilds = new List <Card>() { Card.S9 }; Ranker ranker = new Ranker(5, false); WriteTestHandRanks(ranker, wilds); WriteTestHandProfiles(ranker, wilds); WriteErrantRandomHands(ranker, 100); WriteRandomHandProfiles(ranker, 7, 5, wilds, 10); Console.WriteLine("Press enter to exit program."); Console.Out.Flush(); Console.ReadLine(); }
public Hand GetRandomFlush5(int numCardsDealt, int numCardsInFinalHand) { Ranker ranker = new Ranker(numCardsInFinalHand, false); TSuit flushSuit = GetRandomSuit(); Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; do { Card[] chosen = GetRandomCardsWithSuit(flushSuit, 5); Card[] fill = GetRandomCards(numCardsDealt - 5).ToArray(); fRank = null; hcsRank = null; hcsFill = null; hand = new Hand(fill.Concat(chosen)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > SimpleRank.Flush5); return(hand); }
public static void WriteRandomHandProfiles( Ranker ranker, int numCardsDealt = 7, int numCardsInFinalHand = 5, IEnumerable <Card> wilds = null, int numSamplesPerSimpleRank = 10) { Console.WriteLine(); Console.WriteLine("Press enter to write out full evaluation of random hands."); Console.Out.Flush(); Console.ReadLine(); TestHandGenerator handGen = new TestHandGenerator(0); foreach (SimpleRank sRank in Ranker.StandardRanks) { Console.WriteLine(); Console.Write("Press enter to see full evaluation of hands of type {0:s}", sRank.ToString()); Console.Out.Flush(); Console.ReadLine(); for (int i = 0; i < numSamplesPerSimpleRank; i++) { Hand h = handGen.Generators[sRank](numCardsDealt, numCardsInFinalHand); HandInfo hi = new HandInfo(h, wilds); foreach (SimpleRank sRank2 in Ranker.StandardRanks) { FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; if (ranker.RankPredicateMap[sRank2](hi, out fRank, out hcsRank, out hcsFill)) { Console.WriteLine("Examining hand as a hand of rank {0:s}", fRank.SRank.ToString()); Console.Write(" "); Hand.WriteHandData(h, wilds, fRank, hcsRank, hcsFill); } } } } }
public static void WriteRandomHandProfiles( Ranker ranker, int numCardsDealt = 7, int numCardsInFinalHand = 5, IEnumerable<Card> wilds = null, int numSamplesPerSimpleRank = 10) { Console.WriteLine(); Console.WriteLine("Press enter to write out full evaluation of random hands."); Console.Out.Flush(); Console.ReadLine(); TestHandGenerator handGen = new TestHandGenerator(0); foreach (SimpleRank sRank in Ranker.StandardRanks) { Console.WriteLine(); Console.Write("Press enter to see full evaluation of hands of type {0:s}", sRank.ToString()); Console.Out.Flush(); Console.ReadLine(); for (int i = 0; i < numSamplesPerSimpleRank; i++) { Hand h = handGen.Generators[sRank](numCardsDealt, numCardsInFinalHand); HandInfo hi = new HandInfo(h, wilds); foreach (SimpleRank sRank2 in Ranker.StandardRanks) { FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; if (ranker.RankPredicateMap[sRank2](hi, out fRank, out hcsRank, out hcsFill)) { Console.WriteLine("Examining hand as a hand of rank {0:s}", fRank.SRank.ToString()); Console.Write(" "); Hand.WriteHandData(h, wilds, fRank, hcsRank, hcsFill); } } } } }
public Hand GetRandomTwoPair(int numCardsDealt, int numCardsInFinalHand) { Ranker ranker = new Ranker(numCardsInFinalHand, false); Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; do { TValue pair1Value = (TValue)random.Next(2, 14); TValue pair2Value = (TValue)random.Next(2, 13); if (pair2Value >= pair1Value) { pair2Value = pair2Value.Next(); } Card[] pair1Cards = GetRandomCardsWithValue(pair1Value, 2); Card[] pair2Cards = GetRandomCardsWithValue(pair2Value, 2); Card[] fill = GetRandomCards(numCardsDealt - 4).ToArray(); hand = new Hand(fill.Concat(pair1Cards).Concat(pair2Cards)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > SimpleRank.TwoPair); return(hand); }
public Hand GetRandomStraightOrStraightFlush5(int numCardsDealt, int numCardsInFinalHand, bool doRequireFlush) { Ranker ranker = new Ranker(numCardsInFinalHand, false); Hand hand; FullRank fRank; TSuit flushSuit = GetRandomSuit(); HandCard[] hcsRank; HandCard[] hcsFill; do { TValue maxValue = (TValue)random.Next((int)TValue.Six, (int)TValue.Ace); TValue minValue = maxValue.Prev(4); Card[] chosen = Enumerable.Range((int)minValue, ((int)maxValue - (int)minValue) + 1) .Select(k => doRequireFlush ? (new Card((TValue)k, flushSuit)) : GetRandomCardWithValue((TValue)k)) .Reverse().ToArray(); Card[] fill = GetRandomCards(numCardsDealt - 5).ToArray(); hand = new Hand(fill.Concat(chosen)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > (doRequireFlush ? SimpleRank.StraightFlush5 : SimpleRank.Straight5)); return(hand); }
public Hand GetRandomKindN(int numCardsDealt, int numCardsInFinalHand, int n) { Contract.Requires(n >= 2 && n <= 5, "Error: size of n-of-a-kind out of range"); Ranker ranker = new Ranker(numCardsInFinalHand, false); Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; SimpleRank[] availRanks = new SimpleRank[] { SimpleRank.Kind2, SimpleRank.Kind3, SimpleRank.Kind4, SimpleRank.Kind5 }; SimpleRank thisRank = availRanks[n - 2]; do { TValue value = (TValue)random.Next(2, 14); Card[] tuple = GetRandomCardsWithValue(value, n); Card[] fill = GetRandomCards(numCardsDealt - n); hand = new Hand(tuple.Concat(fill)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > thisRank); return(hand); }
// This method will run through pre-made datasets that should test the majority of use cases static void RunTests(Ranker ranker) { List <DataSet> dataSets = new List <DataSet>() { DataSets.GetHands_OnePair(), DataSets.GetHands_OnePairTieWinningCards(), DataSets.GetHands_OnePairTieRemainingCards(), DataSets.GetHands_OnePairWithJoker(), DataSets.GetHands_OnePairWithTie(), DataSets.GetHands_ThreeOfAKind(), DataSets.GetHands_FourOfAKind(), DataSets.GetHands_FiveOfAKind(), DataSets.GetHands_FiveOfAKindWithAllJokers(), DataSets.GetHands_FullHouse(), DataSets.GetHands_FullHouseTieBreaker(), // 10 DataSets.GetHands_FullHouseWithAJoker(), DataSets.GetHands_TwoPair(), DataSets.GetHands_Flush(), DataSets.GetHands_FlushWithTieBreaker(), DataSets.GetHands_FlushWithAJoker(), DataSets.GetHands_FlushWithTie(), DataSets.GetHands_Straight(), DataSets.GetHands_StraightWithAJoker(), DataSets.GetHands_StraightWithTieBreaker(), DataSets.GetHands_StraightWithTie(), // 20 DataSets.GetHands_StraightFlush(), DataSets.GetHands_StraightFlushWithTieBreaker(), DataSets.GetHands_StraightFlushWithTie(), DataSets.GetHands_HighCard(), DataSets.GetHands_HighCardTieBreaker(), DataSets.GetHands_HighCardTie(), DataSets.GetHands_OneHand(), DataSets.GetHands_TwoCards(), DataSets.GetHands_OneCard(), DataSets.GetHands_TenCards() // 30 }; for (int i = 0; i < dataSets.Count; i++) { string winType = ""; List <Hand> testWinningHands = ranker.DetermineWinner(dataSets[i].Hands, ref winType); if (testWinningHands == null || !testWinningHands.Any()) { Console.WriteLine($"Test Run {i}: FAIL - name: {dataSets[i].Winners}/NONE - " + $"type: {dataSets[i].IntendedWin}/NONE"); continue; } string result; string winningNames = string.Join(",", testWinningHands.Select(x => x.Name)); if (winningNames == dataSets[i].Winners && dataSets[i].IntendedWin == winType) { result = "SUCCESS"; } else { result = "FAIL"; } // print intended/actual Console.WriteLine($"Test Run {i}: {result} - name: {dataSets[i].Winners}/{winningNames} - " + $"type: {dataSets[i].IntendedWin}/{winType}"); } }
public Hand GetRandomKindN(int numCardsDealt, int numCardsInFinalHand, int n) { Contract.Requires(n >= 2 && n <= 5, "Error: size of n-of-a-kind out of range"); Ranker ranker = new Ranker(numCardsInFinalHand, false); Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; SimpleRank[] availRanks = new SimpleRank[] { SimpleRank.Kind2, SimpleRank.Kind3, SimpleRank.Kind4, SimpleRank.Kind5 }; SimpleRank thisRank = availRanks[n - 2]; do { TValue value = (TValue)random.Next(2, 14); Card[] tuple = GetRandomCardsWithValue(value, n); Card[] fill = GetRandomCards(numCardsDealt - n); hand = new Hand(tuple.Concat(fill)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > thisRank); return hand; }
public Hand GetRandomStraightOrStraightFlush5(int numCardsDealt, int numCardsInFinalHand, bool doRequireFlush) { Ranker ranker = new Ranker(numCardsInFinalHand, false); Hand hand; FullRank fRank; TSuit flushSuit = GetRandomSuit(); HandCard[] hcsRank; HandCard[] hcsFill; do { TValue maxValue = (TValue)random.Next((int)TValue.Six, (int)TValue.Ace); TValue minValue = maxValue.Prev(4); Card[] chosen = Enumerable.Range((int)minValue, ((int)maxValue - (int)minValue) + 1) .Select(k => doRequireFlush ? (new Card((TValue)k, flushSuit)) : GetRandomCardWithValue((TValue)k)) .Reverse().ToArray(); Card[] fill = GetRandomCards(numCardsDealt - 5).ToArray(); hand = new Hand(fill.Concat(chosen)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > (doRequireFlush ? SimpleRank.StraightFlush5 : SimpleRank.Straight5)); return hand; }
public Hand GetRandomTwoPair(int numCardsDealt, int numCardsInFinalHand) { Ranker ranker = new Ranker(numCardsInFinalHand, false); Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; do { TValue pair1Value = (TValue)random.Next(2, 14); TValue pair2Value = (TValue)random.Next(2, 13); if (pair2Value >= pair1Value) { pair2Value = pair2Value.Next(); } Card[] pair1Cards = GetRandomCardsWithValue(pair1Value, 2); Card[] pair2Cards = GetRandomCardsWithValue(pair2Value, 2); Card[] fill = GetRandomCards(numCardsDealt - 4).ToArray(); hand = new Hand(fill.Concat(pair1Cards).Concat(pair2Cards)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > SimpleRank.TwoPair); return hand; }
public Hand GetRandomHighCard(int numCardsDealt, int numCardsInFinalHand) { Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; Ranker ranker = new Ranker(numCardsInFinalHand, false); do { hand = new Hand(GetRandomCards(numCardsDealt)); hcsRank = null; hcsFill = null; ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > SimpleRank.HighCard); return hand; }
static void Main(string[] args) { // List<Card> wilds = null; // List<Card> wilds = new List<Card>() { Card.S5, Card.S6, Card.S7, Card.S8 }; List<Card> wilds = new List<Card>() { Card.S9 }; Ranker ranker = new Ranker(5, false); WriteTestHandRanks(ranker, wilds); WriteTestHandProfiles(ranker, wilds); WriteErrantRandomHands(ranker, 100); WriteRandomHandProfiles(ranker, 7, 5, wilds, 10); Console.WriteLine("Press enter to exit program."); Console.Out.Flush(); Console.ReadLine(); }
public Hand GetRandomFlush5(int numCardsDealt, int numCardsInFinalHand) { Ranker ranker = new Ranker(numCardsInFinalHand, false); TSuit flushSuit = GetRandomSuit(); Hand hand; FullRank fRank; HandCard[] hcsRank; HandCard[] hcsFill; do { Card[] chosen = GetRandomCardsWithSuit(flushSuit, 5); Card[] fill = GetRandomCards(numCardsDealt - 5).ToArray(); fRank = null; hcsRank = null; hcsFill = null; hand = new Hand(fill.Concat(chosen)); ranker.GetFullRank(hand, null, out fRank, out hcsRank, out hcsFill); } while (fRank.SRank > SimpleRank.Flush5); return hand; }