private void ProcessNoticePlayerAction(NoticePlayerAction noticePlayerAction, HandHistory handHistory) { var actionType = ParseHandActionType(noticePlayerAction); if (actionType == HandActionType.UNKNOWN) { return; } HandAction action; if (actionType == HandActionType.ALL_IN) { var player = GetPlayer(handHistory, noticePlayerAction.LastActionSeatId + 1); var playerPutInPot = Math.Abs(handHistory.HandActions.Where(x => x.PlayerName == player.PlayerName).Sum(x => x.Amount)); var allInAmount = player.StartingStack - playerPutInPot; action = new AllInAction(player.PlayerName, allInAmount, handHistory.CommunityCards.Street, false); } else if (actionType == HandActionType.RAISE || (actionType == HandActionType.BET && handHistory.CommunityCards.Street == Street.Preflop)) { if (actionType == HandActionType.BET) { actionType = HandActionType.RAISE; } var player = GetPlayer(handHistory, noticePlayerAction.LastActionSeatId + 1); var playerPutInPot = Math.Abs(handHistory.HandActions .Where(x => x.Street == handHistory.CommunityCards.Street && x.PlayerName == player.PlayerName && x.HandActionType != HandActionType.ANTE) .Sum(x => x.Amount)); action = new HandAction(GetPlayerName(handHistory, noticePlayerAction.LastActionSeatId + 1), actionType, noticePlayerAction.Amount - playerPutInPot, handHistory.CommunityCards.Street); } else { action = new HandAction(GetPlayerName(handHistory, noticePlayerAction.LastActionSeatId + 1), actionType, noticePlayerAction.Amount, handHistory.CommunityCards.Street); } handHistory.HandActions.Add(action); }
/// <summary> /// Re-raise amounts are handled differently on different sites. Consider the /// situation where: /// Player1 Bets $10 /// Player2 Raises to $30 total (call of $10, raise $20) /// Player1 Raises to $100 total (call of $20, raise $70) /// /// Party will display this as: Bet 10, Raise 30, Raise 70 /// Stars will display this as: Bet 10, Raise to 30, Raise to 100. /// /// In the case for Stars we will need to deduct previous action amounts from the raise to figure out how /// much that raise actuall is i.e Player 1 only wagered $90 more. /// </summary> /// <param name="handActions"></param> protected List <HandAction> AdjustRaiseSizes(List <HandAction> handActions) { var actionsByStreets = handActions.GroupBy(h => h.Street); foreach (var actionsByStreet in actionsByStreets) { Street street = actionsByStreet.Key; List <HandAction> actions = actionsByStreet.ToList(); // loop backward through the actions and subtracting the action prior to each raise // from that raise amount for (int i = actions.Count - 1; i >= 0; i--) { HandAction currentAction = actions[i]; AllInAction allInAction = currentAction as AllInAction; if (currentAction.HandActionType != HandActionType.RAISE && (allInAction == null || allInAction.IsRaiseAllIn == false)) { continue; } for (int j = i - 1; j >= 0; j--) { if (actions[j].PlayerName.Equals(currentAction.PlayerName)) { // Ante's don't get counted in the raise action lines if (actions[j].HandActionType == HandActionType.ANTE) { continue; } // If the player previously called any future raise will be the entire amount if (actions[j].HandActionType == HandActionType.CALL) { currentAction.DecreaseAmount(actions[j].Amount); continue; } currentAction.DecreaseAmount(actions[j].Amount); break; } } } } return(handActions); }
/// <summary> /// Some sites (like IPoker) don't specifically identify All-In calls/raises. In these cases we need to parse the actions /// and reclassify certain actions as all-in /// </summary> protected List <HandAction> IdentifyAllInActions(string[] handLines, List <HandAction> handActions) { PlayerList playerList = ParsePlayers(handLines); Dictionary <string, decimal> playerStackRemaining = new Dictionary <string, decimal>(); foreach (Player player in playerList) { playerStackRemaining.Add(player.PlayerName, player.StartingStack); } List <HandAction> identifiedActions = new List <HandAction>(handActions.Count); foreach (HandAction action in handActions) { //Negative amounts represent putting money into the pot - ignore actions which aren't negative if (action.Amount >= 0) { identifiedActions.Add(action); continue; } //Skip actions which have already been identified if (action is AllInAction) { identifiedActions.Add(action); continue; } //Update the remaining stack with our action's amount playerStackRemaining[action.PlayerName] += action.Amount; if (playerStackRemaining[action.PlayerName] == 0) { //This was a bet/raise/call for our remaining chips - we are all in AllInAction allInAction = new AllInAction(action.PlayerName, action.Amount, action.Street, true); identifiedActions.Add(allInAction); } else { identifiedActions.Add(action); } } return(identifiedActions); }
private void ProcessActionBRC(ActionBRC message, ClientRecord record, HandHistory history) { var playerName = GetPlayerName(history, message.SeatID + 1); if (BlindActionMapping.ContainsKey(message.ActionType)) { history.HandActions.Add(new HandAction( playerName, BlindActionMapping[message.ActionType], message.Chips, Street.Preflop )); } else if (ActionMapping.ContainsKey(message.ActionType)) { HandAction action; var handActionType = ActionMapping[message.ActionType]; if (InvestingHandActionTypes.Contains(handActionType) && message.HandChips == 0) { action = new AllInAction( playerName, message.Chips, history.CommunityCards.Street, false, // TODO: Find out when IsRaiseAllIn should be true ActionMapping[message.ActionType] ); } else { action = new HandAction( playerName, ActionMapping[message.ActionType], message.Chips, history.CommunityCards.Street ); } history.HandActions.Add(action); } }
private void ProcessUserAction(UserAction userAction, HandHistory handHistory) { var street = handHistory.CommunityCards.Street; var playerName = userAction.PlayerId.ToString(); var actionType = GetHandActionType(userAction, handHistory, playerName, street); HandAction action; if (actionType == HandActionType.ALL_IN) { var player = handHistory.Players.FirstOrDefault(x => x.PlayerName == playerName); if (player == null) { throw new HandBuilderException($"Failed to find player {playerName} for allin action."); } var playerPutInPot = Math.Abs(handHistory.HandActions.Where(x => x.PlayerName == player.PlayerName).Sum(x => x.Amount)); var allInAmount = player.StartingStack - playerPutInPot; action = new AllInAction(player.PlayerName, allInAmount, street, false); } else { action = new HandAction(playerName, actionType, userAction.Amount, street); } handHistory.HandActions.Add(action); }
/// <summary> /// Some sites (like IPoker) don't specifically identify All-In calls/raises. In these cases we need to parse the actions /// and reclassify certain actions as all-in /// </summary> internal static List <HandAction> IdentifyAllInActions(PlayerList playerList, List <HandAction> handActions) { Dictionary <string, decimal> playerStackRemaining = new Dictionary <string, decimal>(); foreach (Player player in playerList) { if (!playerStackRemaining.ContainsKey(player.PlayerName)) { playerStackRemaining.Add(player.PlayerName, player.StartingStack); } else { LogProvider.Log.Warn($"Identifying all in actions: Player [{player.PlayerName}] has been added already."); } } List <HandAction> identifiedActions = new List <HandAction>(handActions.Count); foreach (HandAction action in handActions) { // Negative amounts represent putting money into the pot - ignore actions which aren't negative if (action.Amount >= 0) { identifiedActions.Add(action); continue; } // Skip actions which have already been identified if (action is AllInAction) { identifiedActions.Add(action); continue; } // Update the remaining stack with our action's amount playerStackRemaining[action.PlayerName] += action.Amount; if (playerStackRemaining[action.PlayerName] == 0) { if (action.IsBlinds) { action.IsAllIn = true; identifiedActions.Add(action); continue; } // This was a bet/raise/call for our remaining chips - we are all in var allInAction = new AllInAction(action.PlayerName, action.Amount, action.Street, action.HandActionType == HandActionType.RAISE || action.HandActionType == HandActionType.BET, action.HandActionType); identifiedActions.Add(allInAction); } else { identifiedActions.Add(action); } } return(identifiedActions); }