private PokerHandHistory.Action convertActionToXml(Action a) { PokerHandHistory.Action result = new PokerHandHistory.Action(); result.Player = a.Name; result.Amount = (decimal)a.Amount; result.AllIn = a.AllIn; switch (a.ActionType) { case Action.ActionTypes.Bet: result.Type = PokerHandHistory.ActionType.Bet; break; case Action.ActionTypes.Raise: result.Type = PokerHandHistory.ActionType.Raise; break; case Action.ActionTypes.Check: result.Type = PokerHandHistory.ActionType.Check; break; case Action.ActionTypes.Call: result.Type = PokerHandHistory.ActionType.Call; break; case Action.ActionTypes.Fold: result.Type = PokerHandHistory.ActionType.Fold; break; default: throw new Exception("unknown post-blinds action type: " + a.ToString()); } return(result); }
// Gets the number of total bets put in by the highest raisor. private int getBetLevel(Action[] actions, int aIdx) { if(actions == null) return 0; int level = 0; for (int i = 0; i < actions.Length && i < aIdx; i++) if (actions[i].Type == ActionType.Bet || actions[i].Type == ActionType.Raise) level++; return level; }
// Determines if the hero was the last person to bet in a round private bool getAggressor(Action[] actions, string hero) { bool agg = false; foreach (var action in actions) if (action.Type == ActionType.Bet || action.Type == ActionType.Raise) agg = action.Player == hero; return agg; }
private Action[] getRoundActions(List<string> lines, ref int curLine) { List<Action> actions = new List<Action>(); for (; !lines[curLine].StartsWith("*** "); curLine++) { if (potsExp.Match(lines[curLine]).Success) break; Match m = actionExp.Match(lines[curLine]); if (m.Success) { GroupCollection gc = m.Groups; Action a = new Action(); a.Player = gc[1].Value; switch (gc[2].Value) { case "folds": a.Type = ActionType.Fold; break; case "checks": a.Type = ActionType.Check; break; case "calls": a.Type = ActionType.Call; a.Amount = Decimal.Parse(gc[4].Value); a.AllIn = gc[12].Value.Contains("all-in"); break; case "bets": a.Type = ActionType.Bet; a.Amount = Decimal.Parse(gc[4].Value); a.AllIn = gc[12].Value.Contains("all-in"); break; case "raises": a.Type = ActionType.Raise; a.Amount = Decimal.Parse(gc[9].Value); a.AllIn = gc[12].Value.Contains("all-in"); break; default: throw new Exception("Unknown action type: " + lines[curLine]); } actions.Add(a); continue; } m = uncalledExp.Match(lines[curLine]); if (m.Success) { GroupCollection gc = m.Groups; Action a = new Action(); a.Player = gc[5].Value; a.Amount = Decimal.Parse(gc[2].Value); a.Type = ActionType.Returned; actions.Add(a); } } return actions.ToArray(); }
private Action[] getRoundActions(List <string> lines, ref int curLine) { List <Action> actions = new List <Action>(); for (; !lines[curLine].StartsWith("*** "); curLine++) { if (potsExp.Match(lines[curLine]).Success) { break; } Match m = actionExp.Match(lines[curLine]); if (m.Success) { GroupCollection gc = m.Groups; Action a = new Action(); a.Player = gc[1].Value; switch (gc[2].Value) { case "folds": a.Type = ActionType.Fold; break; case "checks": a.Type = ActionType.Check; break; case "calls": a.Type = ActionType.Call; a.Amount = Decimal.Parse(gc[4].Value); a.AllIn = gc[12].Value.Contains("all-in"); break; case "bets": a.Type = ActionType.Bet; a.Amount = Decimal.Parse(gc[4].Value); a.AllIn = gc[12].Value.Contains("all-in"); break; case "raises": a.Type = ActionType.Raise; a.Amount = Decimal.Parse(gc[9].Value); a.AllIn = gc[12].Value.Contains("all-in"); break; default: throw new Exception("Unknown action type: " + lines[curLine]); } actions.Add(a); continue; } m = uncalledExp.Match(lines[curLine]); if (m.Success) { GroupCollection gc = m.Groups; Action a = new Action(); a.Player = gc[5].Value; a.Amount = Decimal.Parse(gc[2].Value); a.Type = ActionType.Returned; actions.Add(a); } } return(actions.ToArray()); }
private Action[] getRoundActions(PokerHand hand, List <Round> rounds, List <string> lines, ref int curLine) { List <Action> actions = new List <Action>(); for (; !lines[curLine].StartsWith("** Dealing"); curLine++) { if (potsExp.Match(lines[curLine]).Success) { break; } Match m = actionExp.Match(lines[curLine]); if (m.Success) { GroupCollection gc = m.Groups; if (hand.Players.FirstOrDefault(p => p.Name == gc[1].Value) == null) { continue; } Action a = new Action(); a.Player = gc[1].Value; //is all-In|folds|checks|bets|calls|raises switch (gc[2].Value) { case "folds": a.Type = ActionType.Fold; break; case "checks": a.Type = ActionType.Check; break; case "calls": a.Type = ActionType.Call; a.Amount = Decimal.Parse(gc[4].Value); break; case "bets": a.Type = ActionType.Bet; a.Amount = Decimal.Parse(gc[4].Value); break; case "raises": a.Type = ActionType.Raise; a.Amount = Decimal.Parse(gc[4].Value); break; case "is all-In": { a.AllIn = true; a.Amount = hand.Players.FirstOrDefault(p => p.Name == a.Player).Stack - rounds.Sum(r => r.Actions == null ? 0 : r.Actions.Sum(act => act.Player == a.Player ? act.Amount : 0)) - actions.Sum(act => act.Player == a.Player ? act.Amount : 0); var lastRaise = actions.LastOrDefault(act => act.Type == ActionType.Raise); if (lastRaise == null) { if (rounds.Count == 1) { if (a.Amount <= hand.Blinds.First(b => b.Type == BlindType.BigBlind).Amount) { a.Type = ActionType.Call; } else { a.Type = ActionType.Raise; } } else { a.Type = ActionType.Bet; } } else if (lastRaise.Amount < a.Amount) { a.Type = ActionType.Raise; } else { a.Type = ActionType.Call; } } break; default: throw new Exception("Unknown action type: " + lines[curLine]); } actions.Add(a); continue; } // TODO: Handle returned money. Note that pp does not make this obvious. } return(actions.ToArray()); }