public XmlDocument create(TableData tableData) { var document = new XmlDocument(); var input = document.CreateElement("input"); document.AppendChild(input); setConfig(document, input); setHand(document, input, tableData); return document; }
TableData HandHistoryReader.read(string fileName, int backNum) { TableData result = new TableData(); string[] hh = System.IO.File.ReadAllLines(fileName); result.startTime = getStartTime(hh[0]); result.heroName = getHeroName(hh); result.StartingChip = getStartingChip(result.heroName, hh, System.Convert.ToInt32(Properties.Settings.Default.StartingChip)); List<int> hhLineList = getHHLineList(hh); string[] now_hh = getNowHH(hh, hhLineList, backNum); result.allHandCount = hhLineList.Count - 1; int line = 0; result.handTime = getStartTime(now_hh[0]); setBBSB(ref result, now_hh[line++]); result.buttonPos = getButtonPos(now_hh[line]); getStartSituation(ref result, now_hh, ref line); if (backNum == 0) { calcAntePayment(ref result, now_hh, ref line); calcBlindsPayment(ref result, now_hh, ref line); // bets, calls, raises, UNCALLED bet, collected for (; line < now_hh.Length; ++line) { if (calcBetPayment(ref result, now_hh[line])) continue; if (calcCallPayment(ref result, now_hh[line])) continue; if (calcRaisePayment(ref result, now_hh[line])) continue; if (calcUncalledPayment(ref result, now_hh[line])) continue; if (calcCollectedPayment(ref result, now_hh[line])) continue; if (now_hh[line].StartsWith("*** FLOP ***") || now_hh[line].StartsWith("*** TURN ***") || now_hh[line].StartsWith("*** RIVER ***")) { result.posted.Initialize(); } else if (now_hh[line].StartsWith("*** SUMMARY ***")) { break; } } result.nextButton(); if (IsHyper(fileName)) { if(isBlindUp(result)) { blindUp(ref result); } } } else countAnte(ref result, now_hh, ref line); return result; }
private void setHand(XmlDocument document, XmlElement input, TableData tableData) { var hand = document.CreateElement("hand"); hand.SetAttribute("id", "1"); input.AppendChild(hand); addElement(document, hand, "structure", tableData.Structure); addElement(document, hand, "blinds", tableData.BB.ToString() + "," + tableData.SB.ToString() + "," + tableData.Ante.ToString()); addElement(document, hand, "stacks", tableData.stacks); }
/// <summary>ハンド開始状況を取得</summary> /// <param name="result"></param> /// <param name="hh"></param> /// <param name="line"></param> private void getStartSituation(ref TableData result, string[] hh, ref int line) { Regex regex = new Regex("Seat" + Regex.Escape(" ") + "([0-9]+):" + Regex.Escape(" ") + "(.+)" + Regex.Escape(" ") + Regex.Escape("(") + "([0-9]+)" + Regex.Escape(" ") + "in" + Regex.Escape(" ") + "chips" + Regex.Escape(")")); for (int i = 0; i < maxSeatNum; ++i) { MatchCollection matchCol = regex.Matches(hh[++line]); if (matchCol.Count > 0) { result.seats[i] = System.Convert.ToInt32(matchCol[0].Groups[1].Value); result.playerNames[i] = matchCol[0].Groups[2].Value; result.chips[i] = System.Convert.ToInt32(matchCol[0].Groups[3].Value); } else { line -= 1; break; } } }
private bool isBlindUp(TableData tableData) { TimeSpan beforeHandElapsed = tableData.handTime - tableData.startTime; TimeSpan currentHandElapsed = System.DateTime.Now - tableData.startTime; if (currentHandElapsed.Hours < 1) { int beforeBlindLevel = beforeHandElapsed.Minutes / 3; int currentBlindLevel = currentHandElapsed.Minutes / 3; return beforeBlindLevel < currentBlindLevel; } return false; }
private void countAnte(ref TableData result, string[] hh, ref int line) { Regex regex = new Regex("(.+):" + Regex.Escape(" ") + "posts" + Regex.Escape(" ") + "the" + Regex.Escape(" ") + "ante" + Regex.Escape(" ") + "([0-9]+)"); for (int i = 0; i < maxSeatNum; ++i) { MatchCollection matchCol = regex.Matches(hh[++line]); if (matchCol.Count > 0) { result.Ante = Math.Max(result.Ante, System.Convert.ToInt32(matchCol[0].Groups[2].Value)); } else { line -= 1; break; } } }
private int getIndexFromPlayerName(string name, TableData result) { return Enumerable.Range(0, result.MaxSeatNum).First(i => result.playerNames[i] == name); }
private bool calcRaisePayment(ref TableData result, string line) { Regex raises_regex = new Regex("(.+):" + Regex.Escape(" ") + "raises" + Regex.Escape(" ") + "([0-9]+)" + Regex.Escape(" ") + "to" + Regex.Escape(" ") + "([0-9]+)"); MatchCollection matchCol = raises_regex.Matches(line); if (matchCol.Count > 0) { for (int j = 0; j < maxSeatNum; ++j) { if (matchCol[0].Groups[1].Value.Equals(result.playerNames[j])) { result.chips[j] -= System.Convert.ToInt32(matchCol[0].Groups[3].Value) - result.posted[j]; result.pot += System.Convert.ToInt32(matchCol[0].Groups[3].Value) - result.posted[j]; result.posted[j] = System.Convert.ToInt32(matchCol[0].Groups[3].Value); break; } } return true; } return false; }
private bool calcUncalledPayment(ref TableData result, string line) { Regex uncalled_regex = new Regex("Uncalled" + Regex.Escape(" ") + "bet" + Regex.Escape(" (") + "([0-9]+)" + Regex.Escape(") ") + "returned" + Regex.Escape(" ") + "to" + Regex.Escape(" ") + "(.+)"); MatchCollection matchCol = uncalled_regex.Matches(line); if (matchCol.Count > 0) { for (int j = 0; j < maxSeatNum; ++j) { if (matchCol[0].Groups[2].Value.Equals(result.playerNames[j])) { result.chips[j] += System.Convert.ToInt32(matchCol[0].Groups[1].Value); result.pot -= System.Convert.ToInt32(matchCol[0].Groups[1].Value); break; } } return true; } return false; }
private void calcBlindPayment(Blind blind, ref TableData result, string[] hh, ref int line, bool isSkip) { Regex regex = new Regex("(.+)" + Regex.Escape(" posts the ") + blind + Regex.Escape(" blind of ") + "([0-9,]+)"); MatchCollection matchCol = regex.Matches(hh[++line]); if (matchCol.Count > 0) { if (isSkip == false) { for (int j = 0; j < maxSeatNum; ++j) { if (matchCol[0].Groups[1].Value.Equals(result.playerNames[j])) { int value = System.Convert.ToInt32(matchCol[0].Groups[2].Value.Replace(",", string.Empty)); result.posted[j] = value; result.chips[j] -= value; result.pot += value; } } } } else { line -= 1; } }
void setUpResult(TableData result) { currentTableData = result; // 設定 textBoxBB.Text = result.BB.ToString(); currentSB = result.SB.ToString(); textBoxAnte.Text = result.Ante.ToString(); SetHeroSeat(SeatLabels[result.getHeroSeat() - 1]); if (isHyper()) setHyperStructure(); textBoxStructure.Text = textBoxStructure.Text.Trim().Replace('+', ',').Replace(' ', ','); string[] structureStrs = textBoxStructure.Text.Split(','); double[] structures = new double[structureStrs.Length]; for (int i = 0; i < structureStrs.Length; ++i) structures[i] = System.Convert.ToDouble(structureStrs[i]); // チップと名前入力 foreach (TextBox chipTextBox in chipTextBoxes) chipTextBox.Text = ""; foreach (TextBox rangeTextBox in rangeTextBoxes) rangeTextBox.Clear(); for (int i = 0; i < result.MaxSeatNum; ++i) { if (result.chips[i] <= 0 && result.playerNames[i] != string.Empty && result.seats[i] > 0 && checkBoxRebuy.Checked) result.chips[i] = result.StartingChip; if (result.chips[i] > 0) { chipTextBoxes[result.seats[i] - 1].Text = result.chips[i].ToString(); PlayerNameLabels[result.seats[i] - 1].Text = result.playerNames[i]; } } result.calcICMs(structures); for (int i = 0, count = 0; i < result.MaxSeatNum; ++i) { if (result.chips[i] > 0) { ICMLabels[i].Text = result.ICMs[count++].ToString(); } else ICMLabels[i].Text = string.Empty; } // ボタンの位置を決定 int player_num = result.chips.Count(chip => chip > 0); int buttonIndex = Enumerable.Range(0, result.MaxSeatNum).First(i => result.buttonPos == result.seats[i]); if (player_num < 3) { for (int j = 1, count = 0; j < result.MaxSeatNum + 1; ++j) { if (result.chips[(buttonIndex + j) % result.MaxSeatNum] > 0) { if (++count == 1) { positionRadioButtons[result.seats[(buttonIndex + j) % result.MaxSeatNum] - 1].Checked = true; break; } } } // positionRadioButtons[result.buttonPos - 1].Checked = true; } else { for (int j = 1, count = 0; j < result.MaxSeatNum + 1; ++j) { if (result.chips[(buttonIndex + j) % result.MaxSeatNum] > 0) { if (++count == 2) { positionRadioButtons[result.seats[(buttonIndex + j) % result.MaxSeatNum] - 1].Checked = true; break; } } } } if (Properties.Settings.Default.SetBBLast) { while (positionRadioButtons[8].Text != Position[0]) { SeatRotateF(); result.seats[result.getHeroIndex()]++; } if(result.seats[result.getHeroIndex()] > result.MaxSeatNum) result.seats[result.getHeroIndex()] = result.seats[result.getHeroIndex()] % result.MaxSeatNum; SetHeroSeat(SeatLabels[result.getHeroSeat() - 1]); } else if (0 < Properties.Settings.Default.PreferredSeat && Properties.Settings.Default.PreferredSeat < result.MaxSeatNum + 1) { for (int i = 0; i < (Properties.Settings.Default.PreferredSeat - result.seats[result.getHeroIndex()] + result.MaxSeatNum) % result.MaxSeatNum; ++i) SeatRotateF(); SetHeroSeat(SeatLabels[Properties.Settings.Default.PreferredSeat - 1]); } SetPosition(); foreach (CheckBox checkBox in AllinCheckBoxes) checkBox.Checked = false; if (result.chips[result.getHeroIndex()] > 0 && player_num > 1 && checkBoxCalc.Checked) { Calc(); } else { resultXML = null; recent_web_page = String.Empty; setupCurrentTableData(); } }
private void blindUp(ref TableData tableData) { int blindLevel = Array.IndexOf(bbList, tableData.BB) + 1; blindLevel = blindLevel >= bbList.Length ? bbList.Length - 1 : blindLevel; tableData.BB = bbList[blindLevel]; tableData.SB = sbList[blindLevel]; tableData.Ante = anteList[blindLevel]; }
/// <summary>Anteの支払い処理を計算する</summary> /// <param name="result"></param> /// <param name="hh"></param> /// <param name="line"></param> private void calcAntePayment(ref TableData result, string[] hh, ref int line) { Regex regex = new Regex("(.+):" + Regex.Escape(" ") + "posts" + Regex.Escape(" ") + "the" + Regex.Escape(" ") + "ante" + Regex.Escape(" ") + "([0-9]+)"); for (int i = 0; i < maxSeatNum; ++i) { MatchCollection matchCol = regex.Matches(hh[++line]); if (matchCol.Count > 0) { int j = getIndexFromPlayerName(matchCol[0].Groups[1].Value, result); result.Ante = Math.Max(result.Ante, System.Convert.ToInt32(matchCol[0].Groups[2].Value)); result.chips[j] -= System.Convert.ToInt32(matchCol[0].Groups[2].Value); result.pot += System.Convert.ToInt32(matchCol[0].Groups[2].Value); } else { line -= 1; break; } } }
public static string[] Calc(TableData tableData, string chips, List<bool> isForceAllInList) { IntPtr hrc = FindWindow(null, "HoldemResources Calculator"); openBasicHand(hrc); try { newDialog = FindDialog("New"); while (newDialog != IntPtr.Zero) { nextButton = FindWindowEx(newDialog, IntPtr.Zero, "Button", null); EnumChildWindows(newDialog, FindNextButton, 0); SendMessage(newDialog, (uint)WM_ACTIVATE, IntPtr.Zero, IntPtr.Zero); SendMessage(nextButton, (uint)BM_CLICK, IntPtr.Zero, IntPtr.Zero); newDialog = FindWindow(null, "New"); System.Threading.Thread.Sleep(10); } setupDialog = FindDialog("Basic Hand Setup"); createClipBoard(tableData, chips); EnumChildWindows(setupDialog, FindPasteButton, 0); if (pasteButton == null) throw new ApplicationException(); for (int i = 0; i < 5; ++i) { SendMessage(pasteButton, (uint)BM_CLICK, IntPtr.Zero, IntPtr.Zero); System.Threading.Thread.Sleep(10); } EnumChildWindows(setupDialog, FindFinishButton, 0); if (finishButton == null) throw new ApplicationException(); SendMessage(finishButton, (uint)BM_CLICK, IntPtr.Zero, IntPtr.Zero); calculatingDialog = FindDialog("Basic Hand Setup"); while (calculatingDialog != IntPtr.Zero) { System.Threading.Thread.Sleep(100); calculatingDialog = FindWindow(null, "Basic Hand Setup"); } openExportStrategies(hrc); exportStrategiesDialog = FindDialog("Export Strategies"); IntPtr swtWindowTop = FindWindowEx(exportStrategiesDialog, IntPtr.Zero, "SWT_Window0", null); IntPtr swtWindowNext = FindWindowEx(swtWindowTop, IntPtr.Zero, "SWT_Window0", null); selectedSpotComboBox = FindWindowEx(swtWindowNext, IntPtr.Zero, "ComboBox", null); selectedSpotComboBox = FindWindowEx(swtWindowNext, selectedSpotComboBox, "ComboBox", null); PostMessage(selectedSpotComboBox, CB_SETCURSEL, 0, 0); SendMessage(selectedSpotComboBox, (uint)CB_SETCURSEL, IntPtr.Zero, IntPtr.Zero); PostMessage(exportStrategiesDialog, WM_COMMAND, MakeWParam(0, CBN_SELCHANGE), selectedSpotComboBox.ToInt32()); rangeTextBox = FindWindowEx(swtWindowNext, IntPtr.Zero, "Edit", null); PostMessage(rangeTextBox, EM_SETSEL, 0, -1); System.Threading.Thread.Sleep(100); SendMessage(rangeTextBox, WM_COPY, IntPtr.Zero, IntPtr.Zero); rangeText = Clipboard.GetText(); swtWindowNext = FindWindowEx(swtWindowTop, swtWindowNext, "SWT_Window0", null); exportStrategiesDialogOKButton = FindWindowEx(swtWindowNext, IntPtr.Zero, "Button", "OK"); SendMessage(exportStrategiesDialogOKButton, (uint)BM_CLICK, IntPtr.Zero, IntPtr.Zero); return parseRangeText(rangeText, tableData.getHeroNumber(), isForceAllInList); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Cannot Find HRC" + System.Environment.NewLine + ex); return null; } }
static void createClipBoard(TableData tableData, string chips) { StringBuilder handHistory = new StringBuilder(); handHistory.Append("PokerStars Hand #1: Tournament #1, $72.55+$1.45 USD Hold'em No Limit - Level I ("); handHistory.Append(tableData.SB); handHistory.Append("/"); handHistory.Append(tableData.BB); handHistory.AppendLine(") - 2013/01/01 13:00:00 JST [2013/01/01 00:00:00 ET]"); handHistory.AppendLine("Table '1 1' 9-max Seat #" + (tableData.getLivePlayerCount() - 2) + " is the button"); handHistory.AppendLine(chips); for (int i = 0; i < tableData.getLivePlayerCount(); ++i) { handHistory.AppendLine("Player" + (i + 1) + ": posts the ante " + tableData.Ante); } System.Windows.Forms.Clipboard.SetText(handHistory.ToString()); }
bool shouldCloseSituation(TableData result) { return (result.getLivePlayerCount() <= 1 && isMTT() == false) || (result.getLivePlayerCount() == 2 && isHyper()) || (result.getHeroChip() <= 0 && isHyper()); }
/// <summary>BBとSBを取得し、設定する</summary> /// <param name="data"></param> /// <param name="line"></param> private void setBBSB(ref TableData data, string line) { Regex regex = new Regex(Regex.Escape("(") + "([0-9]+)" + Regex.Escape("/") + "([0-9]+)" + Regex.Escape(")")); MatchCollection matchCol = regex.Matches(line); data.SB = System.Convert.ToInt32(matchCol[0].Groups[1].Value); data.BB = System.Convert.ToInt32(matchCol[0].Groups[2].Value); }
private void calcAntePayment(ref TableData result, string[] hh, ref int line, bool isSkip) { Regex regex = new Regex("(.+)" + Regex.Escape(" antes ") + "([0-9,]+)"); for (int i = 0; i < maxSeatNum; ++i) { MatchCollection matchCol = regex.Matches(hh[++line]); if (matchCol.Count > 0) { for (int j = 0; j < maxSeatNum; ++j) { if (matchCol[0].Groups[1].Value.Equals(result.playerNames[j])) { int value = System.Convert.ToInt32(matchCol[0].Groups[2].Value.Replace(",", string.Empty)); result.Ante = Math.Max(value, result.Ante); if (isSkip == false) { result.chips[j] -= value; result.pot += value; } } } } else { line -= 1; break; } } }
/// <summary>指定されたBlindの支払い処理を計算する</summary> /// <param name="blind"></param> /// <param name="result"></param> /// <param name="hh"></param> /// <param name="line"></param> private void calcBlindPayment(Blind blind, ref TableData result, string[] hh, ref int line) { Regex regex = new Regex("(.+):" + Regex.Escape(" ") + "posts" + Regex.Escape(" ") + blind + Regex.Escape(" ") + "blind" + Regex.Escape(" ") + "([0-9]+)"); MatchCollection matchCol = regex.Matches(hh[++line]); if (matchCol.Count > 0) { for (int j = 0; j < maxSeatNum; ++j) { if (matchCol[0].Groups[1].Value.Equals(result.playerNames[j])) { result.posted[j] = System.Convert.ToInt32(matchCol[0].Groups[2].Value); result.chips[j] -= result.posted[j]; result.pot += result.posted[j]; } } } else { line -= 1; } }
private bool calcCollectedPayment(ref TableData result, string line) { Regex collected_regex = new Regex("(.+)" + Regex.Escape(" wins the pot (") + "([0-9,]+)" + Regex.Escape(")")); MatchCollection matchCol = collected_regex.Matches(line); if (matchCol.Count > 0) { for (int j = 0; j < maxSeatNum; ++j) { if (matchCol[0].Groups[1].Value.Equals(result.playerNames[j])) { int value = System.Convert.ToInt32(matchCol[0].Groups[2].Value.Replace(",", string.Empty)); result.chips[j] += value; result.pot -= value; break; } } return true; } return false; }
/// <summary>全Blindの支払い処理を計算する</summary> /// <param name="result"></param> /// <param name="hh"></param> /// <param name="line"></param> private void calcBlindsPayment(ref TableData result, string[] hh, ref int line) { calcBlindPayment(Blind.small, ref result, hh, ref line); calcBlindPayment(Blind.big, ref result, hh, ref line); }
private void setupCurrentTableData() { int allHandCount = 1; if (currentTableData != null) { allHandCount = currentTableData.allHandCount; } currentTableData = new TableData(); currentTableData.allHandCount = allHandCount; currentTableData.Structure = textBoxStructure.Text.Trim(); currentTableData.BB = System.Convert.ToInt32(textBoxBB.Text.Trim()); currentTableData.SB = currentTableData.BB / 2; currentTableData.Ante = System.Convert.ToInt32(textBoxAnte.Text.Trim()); currentTableData.stacks = string.Empty; isForceAllInList = new List<bool>(); int unit = currentTableData.Ante < 10 ? 10 : currentTableData.Ante; for (int i = 1; i < 10; ++i) { if (chipTextBoxes[(bb_pos + i) % 9].Text.Trim() != string.Empty) { currentTableData.seats[(bb_pos + i) % 9] = i; if (currentTableData.stacks.Length > 0) currentTableData.stacks += ","; int chip = System.Convert.ToInt32(chipTextBoxes[(bb_pos + i) % 9].Text.Trim()); currentTableData.chips[(bb_pos + i) % 9] = chip; bool isForceAllIn = false; isForceAllIn = chip <= currentTableData.Ante; if (this.positionRadioButtons[(bb_pos + i) % 9].Text == "SB") isForceAllIn = chip <= currentTableData.Ante + currentTableData.SB; isForceAllInList.Add(isForceAllIn); if (currentTableData.playerNames[(bb_pos + i) % 9] == null || currentTableData.playerNames[(bb_pos + i) % 9] == string.Empty) currentTableData.playerNames[(bb_pos + i) % 9] = "Player" + (bb_pos + i) % 9; chip = (int)(Math.Round((double)chip / (double)unit) * unit); currentTableData.stacks += chip.ToString(); if (SeatLabels[(bb_pos + i) % 9].Text == "H") currentTableData.heroName = currentTableData.playerNames[(bb_pos + i) % 9]; if (this.positionRadioButtons[(bb_pos + i) % 9].Text == "BU") currentTableData.buttonPos = i; } } }