private static int AddToDataTmp(System.IO.StreamWriter file, HoleCards hand1, HoleCards hand2, float equity) { int total = 0; if (!(_data[hand1.ToInt()][hand2.ToInt()] > 0)) { _data[hand1.ToInt()][hand2.ToInt()] = equity; file.WriteLine(hand1.ToString() + ":" + hand2.ToString() + "=" + (equity * 100).ToString("f2")); total++; } return(total); }
/// <summary> /// Loads saved all pairs pre flop equities. /// </summary> public static void Load() { _data = new float[N_HOLECARDS_DOUBLE][]; for (int i = 0; i < N_HOLECARDS_DOUBLE; i++) { _data[i] = new float[N_HOLECARDS_DOUBLE]; for (int j = 0; j < N_HOLECARDS_DOUBLE; j++) { _data[i][j] = 0; } } using (var file = new StreamReader(File.OpenRead(fileName))) { while (!file.EndOfStream) { string line = file.ReadLine(); HoleCards hand1 = new HoleCards(line.Substring(0, 4)); HoleCards hand2 = new HoleCards(line.Substring(5, 4)); float eq = float.Parse(line.Substring(10), CultureInfo.InvariantCulture); _data[hand1.ToInt()][hand2.ToInt()] = eq; } } }
public float getHoleCardsProb(HoleCards holeCards) { for (var i = 0; i < N_HOLECARDS; i++) { if (Data[i].Ind == holeCards.ToInt()) { return(Data[i].Equity); } } return(0.0f); }
/// <summary> /// Calculates PFR for all hole cards against all other hole cards. /// Last couple hours. Saved to file afterwards. /// </summary> /// <param name="backgroundWorker">For reporting progress</param> public static void AllPairsPreFlopEquity(IProgressReporter progressReporter) { int total = TotalCombinations(); int done = 0; for (int i = 0; i < N_HOLECARDS_DOUBLE; i++) { for (int j = 0; j < N_HOLECARDS_DOUBLE; j++) { if (_data[i][j] > 0) { done++; } } } if (progressReporter != null) { progressReporter.ReportProgress((100 * done) / total, new ProgressReport(total, done, 0)); } for (int i = 0; i < 51; i++) { if (progressReporter != null && progressReporter.isCancellationPending()) { break; } for (int j = i + 1; j < 52; j++) { if (progressReporter != null && progressReporter.isCancellationPending()) { break; } // i < j HoleCards heroHand = new HoleCards(i, j); for (int k = 0; k < 51; k++) { if (progressReporter != null && progressReporter.isCancellationPending()) { break; } if (k == i || k == j) { continue; } float[] tmpEquity = new float[52]; for (int ppp = 0; ppp < 52; ppp++) { tmpEquity[ppp] = 0; } DateTime startTime = DateTime.Now; int previousDone = done; //for (int l = k + 1; l < 52; l++ ) Parallel.For(k + 1, 52, (l) => { if (l != i && l != j) { // k < l HoleCards villanHand = new HoleCards(k, l); if (_data[heroHand.ToInt()][villanHand.ToInt()] == 0) { tmpEquity[l] = Calculate(heroHand, villanHand); } } }); using (var file = File.AppendText(fileName)) { for (int l = k + 1; l < 52; l++) { if (tmpEquity[l] > 0) { HoleCards villanHand = new HoleCards(k, l); done += AddToData(file, heroHand, villanHand, tmpEquity[l]); } } } DateTime endTime = DateTime.Now; TimeSpan dTime = endTime - startTime; float msPerComb = (done > previousDone) ? (float)(dTime.TotalMilliseconds / (done - previousDone)) : 0; if (progressReporter != null) { progressReporter.ReportProgress((100 * done) / total, new ProgressReport(total, done, msPerComb)); } } } } }