public static double CellVsSpectrums(string heroCell, HandSpectrumCell[] opp1Spectrum, HandSpectrumCell[] opp2Spectrum = null) { if (heroCell.Length == 2 && opp2Spectrum != null) { bool holeLine1 = opp1Spectrum.Count(e => e.CellSymbol.Contains(heroCell[0])) == opp1Spectrum.Length; bool holeLine2 = opp2Spectrum.Count(e => e.CellSymbol.Contains(heroCell[0])) == opp1Spectrum.Length; bool hasSameCell1 = opp1Spectrum.Count(e => e.CellSymbol == heroCell) != 0; bool hasSameCell2 = opp2Spectrum.Count(e => e.CellSymbol == heroCell) != 0; if (hasSameCell1 && holeLine2) { opp1Spectrum = opp1Spectrum.Where(e => e.CellSymbol != heroCell).ToArray(); } if (hasSameCell2 && holeLine1) { opp2Spectrum = opp2Spectrum.Where(e => e.CellSymbol != heroCell).ToArray(); } } IAsyncResult[] results = new IAsyncResult[1000]; CalculateOddsDelegate d = new CalculateOddsDelegate(CalculateOdds); long wins = 0, ties = 0, ties2 = 0, total = 0; ulong[] heroPockets = PocketHands.Query(heroCell); var opp1Sp = new CellsArray(opp1Spectrum); CellsArray opp2Sp = null; if (opp2Spectrum != null) { opp2Sp = new CellsArray(opp2Spectrum); } for (int i = 0; i < results.Length; i++) { results[i] = d.BeginInvoke(heroPockets, opp1Sp, opp2Sp, null, null); } var situations = new Dictionary <string, long>(); for (int i = 0; i < results.Length; i++) { Results r = d.EndInvoke(results[i]); wins += r.win; ties += r.ties; ties2 += r.ties2; total += r.total; } return((double)(wins + ties / 2 + ties2 / 3) / total * 100); }
static void Main(string[] args) { // This code calculates the probablity of As Ks winning against // another random hand. ulong pocketmask = Hand.ParseHand("As Ks"); // Hole hand ulong board = Hand.ParseHand(""); // No board cards yet long wins = 0, ties = 0, count = 0; // Iterate through all possible opponent hole cards ulong [] opphands = HandList(0UL, board | pocketmask, 2); // Create Array of Opponent Hands // Create delegate CalculateOddsDelegate d = new CalculateOddsDelegate(CalculateOdds); // Create results array IAsyncResult[] results = new IAsyncResult[opphands.Length]; // start time double start = Hand.CurrentTime; // Put calculation requests into the threadpool for (int i = 0; i < opphands.Length; i++) { results[i] = d.BeginInvoke(pocketmask, opphands[i], 0UL, 0UL, null, null); } // Collect results once the threads have completed for (int i = 0; i < opphands.Length; i++) { Results r = d.EndInvoke(results[i]); wins += r.win; ties += r.ties; count += r.count; } // Prints: Win 67.0446323092352% Console.WriteLine("Win {0}%, Elapsed Time {1}", (((double)wins) + ((double)ties) / 2.0) / ((double)count) * 100.0, Hand.CurrentTime - start); }