private HoleCards parseHoleCards(string handLine) { int openSquareIndex = handLine.IndexOf('['); string cards = handLine.Substring(openSquareIndex + 2, handLine.Length - openSquareIndex - 2 - 2); return(HoleCards.FromCards(cards.Replace(",", "").Replace(" ", ""))); }
/// <summary> /// Parses Hero from the specified HH lines /// </summary> /// <param name="handlines">Lines to parse</param> /// <param name="playerList">List of players</param> /// <returns>Name of hero</returns> protected override string ParseHeroName(string[] handlines, PlayerList playerList) { for (var i = 2; i < handlines.Length; i++) { if (handlines[i].StartsWith("Dealt to", StringComparison.OrdinalIgnoreCase)) { var heroName = handlines[i].TakeBetween("Dealt to ", " [", false, true); var hero = playerList.FirstOrDefault(p => p.PlayerName == heroName); if (hero != null) { var cardsText = handlines[i].TakeBetween("[", "]", true); if (!string.IsNullOrEmpty(cardsText)) { hero.HoleCards = HoleCards.FromCards(heroName, cardsText); } } return(heroName); } ; if (handlines[i].StartsWith("***", StringComparison.Ordinal)) { break; } } return(string.Empty); }
protected override PlayerList ParsePlayers(string[] handLines) { // line 3 onward has all seated player // Seat 1: ovechkin08 (2000€) // Seat 4: R.BAGGIO (2000€) // *** ANTE/BLINDS *** var playerList = new PlayerList(); for (int i = 2; i < handLines.Length; i++) { // when the line starts with stars, we already have all players if (handLines[i].StartsWith("***")) { break; } int colonIndex = handLines[i].IndexOf(':'); int parenIndex = handLines[i].IndexOf('('); string name = handLines[i].Substring(colonIndex + 2, parenIndex - 2 - colonIndex - 1); int seatNumber = Int32.Parse(handLines[i].Substring(5, colonIndex - 5)); string amount = (handLines[i].Substring(parenIndex + 1, handLines[i].Length - parenIndex - 2)); playerList.Add(new Player(name, decimal.Parse(amount, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo), seatNumber)); } for (int i = handLines.Length - 1; i >= 0; i--) { // Loop backward looking for lines like: // Seat 3: xGras (button) won 6.07€ // Seat 4: KryptonII (button) showed [Qd Ah] and won 42.32€ with One pair : Aces // Seat 1: Hitchhiker won 0.90€ // Seat 3: le parano (big blind) mucked string handLine = handLines[i]; if (!handLine.StartsWith("Seat")) { break; } string name = GetPlayerNameFromHandLine(handLine); int openSquareIndex = handLine.LastIndexOf('['); int closeSquareIndex = handLine.LastIndexOf(']'); string holeCards = ""; if (openSquareIndex > -1 && closeSquareIndex > -1) { holeCards = handLine.Substring(openSquareIndex + 1, closeSquareIndex - openSquareIndex - 1); } Player player = playerList.First(p => p.PlayerName.Equals(name)); player.HoleCards = HoleCards.FromCards(holeCards.Replace(" ", "").Replace(",", "")); } return(playerList); }
private IEnumerable <PlayerList> GetPlayerLists() { var playerLists = new List <PlayerList>(); var p1 = new PlayerList() { new Player("KrookedTyrant", 133.90m, 6), new Player("LOLYOU FOLD", 423.45m, 3) { HoleCards = HoleCards.FromCards("6c Ad") }, new Player("Moose4Life", 551.33m, 4), new Player("PotatoGun", 559.66m, 2) { HoleCards = HoleCards.FromCards("Qc Ac") }, new Player("WhatDayIsIt", 410.67m, 5), }; var p2 = new PlayerList() { new Player("dimatlt633", 2.06m, 3), new Player("ragga22", 17.60m, 1), }; playerLists.Add(p1); playerLists.Add(p2); return(playerLists); }
protected override string ParseHeroName(string[] handlines, PlayerList playerList) { const string DealText = "Dealt to "; for (int i = 0; i < handlines.Length; i++) { if (handlines[i][0] == 'D' && handlines[i].StartsWith(DealText)) { string line = handlines[i]; int startIndex = line.IndexOf('['); var heroName = line.Substring(9, startIndex - 10); if (playerList != null && playerList[heroName] != null && playerList[heroName].HoleCards == null) { var cards = line.Substring(startIndex + 1, line.Length - startIndex - 2) .Replace("[", string.Empty).Replace("]", string.Empty).Replace(",", " "); playerList[heroName].HoleCards = HoleCards.FromCards(CardNormalization(handlines, cards)); } return(heroName); } } return(null); }
private static HoleCards GetPlayerCardsFromHandLines(string[] handLines, int playerSeat, string playerName) { string seatString = "seat=\"" + playerSeat + "\""; for (int i = 8; i < handLines.Length; i++) { string line = handLines[i]; if (line[1] != 'C') { continue; } string showLine = handLines[i - 1]; if (showLine[1] != 'A') { continue; } int showCardsIndex = showLine.IndexOfFast("type=\"ShowCards\"", 15); if (showCardsIndex == -1) { showCardsIndex = showLine.IndexOfFast("type=\"MuckCards\"", 15); } // if the cards are shown for this player if (showCardsIndex != -1 && showLine.LastIndexOfFast(seatString) != -1) { var cards = ParseCardsFromLines(handLines, ref i); return(HoleCards.FromCards(playerName, cards.ToArray())); } } return(null); }
private Player AddOrUpdatePlayer(UserGameInfoNet userGameInfo, int seat, HandHistory handHistory, long heroId) { var player = handHistory.Players[userGameInfo.UserInfo.ShowID]; if (player == null) { player = new Player(userGameInfo.UserInfo.ShowID, 0, seat) { PlayerNick = userGameInfo.UserInfo.Nick }; handHistory.Players.Add(player); if (heroId == userGameInfo.UserInfo.Uuid) { handHistory.Hero = player; } } if (userGameInfo.CurrentHands == null || player.hasHoleCards) { return(player); } handHistory.Players[userGameInfo.UserInfo.ShowID].HoleCards = HoleCards.FromCards(userGameInfo.UserInfo.ShowID, userGameInfo.CurrentHands.Select(c => Card.GetPMCardFromIntValue(c)).ToArray()); return(player); }
public void ParsePlayers_WaitingForBB() { var expected = new PlayerList(new List <Player>() { new Player("Player1", 2000m, 1), new Player("Player2", 2017m, 2) { HoleCards = HoleCards.FromCards("8h3hJcTc") }, new Player("Player3", 0m, 3) { IsSittingOut = true }, new Player("HERO", 1970m, 4) { HoleCards = HoleCards.FromCards("AcAd9d3d") }, new Player("Player5", 2000m, 5) { IsSittingOut = true }, new Player("Player6", 2000m, 6), }); TestParsePlayers_FullHand("WaitingForBB", expected); }
protected override PlayerList ParsePlayers(string[] handLines) { // Line 5 onward is: // Players in round: 3 // Seat 8: Max Power s ($8.96) // Seat 9: EvilJihnny99 ($24.73) // Seat 10: huda22 ($21.50) int numPlayers = ParseNumberOfPlayers(handLines); PlayerList playerList = new PlayerList(); int StartLine = isHeroHandhistory(handLines) ? 6 : 5; for (int i = 0; i < numPlayers; i++) { string handLine = handLines[StartLine + i]; int colonIndex = handLine.IndexOf(':'); int parenIndex = handLine.IndexOf('('); string name = handLine.Substring(colonIndex + 2, parenIndex - 2 - colonIndex - 1); int seatNumber = Int32.Parse(handLine.Substring(5, colonIndex - 5)); string amount = (handLine.Substring(parenIndex + 1, handLine.Length - parenIndex - 2)); playerList.Add(new Player(name, decimal.Parse(amount, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo), seatNumber)); } // Parse the player showdown hole-cards for (int i = handLines.Length - 2; i >= 0; i--) { // Loop backward looking for lines like: // Seat 4: mr dark hor ($37.87), net: -$15.25, [Ts, 3s] string handLine = handLines[i]; if (handLine.StartsWith("Seat") == false) { break; } if (handLine.EndsWith("]") == false) { continue; } int colonIndex = handLine.IndexOf(':'); int parenIndex = handLine.IndexOf('('); string name = handLine.Substring(colonIndex + 2, parenIndex - 2 - colonIndex - 1); int openSquareIdex = handLine.LastIndexOf('['); string holeCards = handLine.Substring(openSquareIdex + 1, handLine.Length - openSquareIdex - 2); Player player = playerList.First(p => p.PlayerName.Equals(name)); player.HoleCards = HoleCards.FromCards(holeCards.Replace(" ", "").Replace(",", "")); } return(playerList); }
protected override PlayerList ParsePlayers(string[] handLines) { // Line 5 onward is: // Players in round: 3 // Seat 8: Max Power s ($8.96) // Seat 9: EvilJihnny99 ($24.73) // Seat 10: huda22 ($21.50) int firstColon = handLines[4].LastIndexOf(':'); int numPlayers = Int32.Parse(handLines[4].Substring(firstColon + 1, handLines[4].Length - firstColon - 1)); PlayerList playerList = new PlayerList(); for (int i = 0; i < numPlayers; i++) { string handLine = handLines[5 + i]; int colonIndex = handLine.IndexOf(':'); int parenIndex = handLine.IndexOf('('); string name = handLine.Substring(colonIndex + 2, parenIndex - 2 - colonIndex - 1); int seatNumber = Int32.Parse(handLine.Substring(5, colonIndex - 5)); string amount = (handLine.Substring(parenIndex + 2, handLine.Length - parenIndex - 2 - 1)); playerList.Add(new Player(name, decimal.Parse(amount, System.Globalization.CultureInfo.InvariantCulture), seatNumber)); } // Parse the player showdown hole-cards for (int i = handLines.Length - 2; i >= 0; i--) { // Loop backward looking for lines like: // Seat 4: mr dark hor ($37.87), net: -$15.25, [Ts, 3s] string handLine = handLines[i]; if (handLine.StartsWith("Seat") == false) { break; } if (handLine.EndsWith("]") == false) { continue; } int colonIndex = handLine.IndexOf(':'); int parenIndex = handLine.IndexOf('('); string name = handLine.Substring(colonIndex + 2, parenIndex - 2 - colonIndex - 1); int openSquareIdex = handLine.LastIndexOf('['); string holeCards = handLine.Substring(openSquareIdex + 1, handLine.Length - openSquareIdex - 2); Player player = playerList.First(p => p.PlayerName.Equals(name)); player.HoleCards = HoleCards.FromCards(holeCards.Replace(" ", "").Replace(",", "")); } return(playerList); }
protected override PlayerList ParsePlayers(string[] handLines) { int seatCount = Int32.Parse(NumPlayersRegex.Match(handLines[5]).Value); PlayerList playerList = new PlayerList(); for (int i = 0; i < seatCount; i++) { string handLine = handLines[6 + i]; // Expected format: // Seat 1: Velmonio ( $1.05 ) int colonIndex = handLine.IndexOf(':'); int openParenIndex = handLine.IndexOf('('); int seat = int.Parse(handLine.Substring(5, colonIndex - 5)); string playerName = handLine.Substring(colonIndex + 2, openParenIndex - colonIndex - 3); decimal amount = ParseAmount(handLine.Substring(openParenIndex + 3, handLine.Length - openParenIndex - 3 - 2)); playerList.Add(new Player(playerName, amount, seat)); } // Add hole-card info for (int i = handLines.Length - 2; i >= 0; i--) { string handLine = handLines[i]; if (handLine[0] == '*') { break; } if (handLine.EndsWith("]") && char.IsDigit(handLine[handLine.Length - 3]) == false) { // lines such as: // slyguyone2 shows [ Jd, As ] int openSquareIndex = handLine.IndexOf('['); string cards = handLine.Substring(openSquareIndex + 2, handLine.Length - openSquareIndex - 2 - 2); HoleCards holeCards = HoleCards.FromCards(cards.Replace(",", "").Replace(" ", "")); string playerName = handLine.Substring(0, openSquareIndex - 7); Player player = playerList.First(p => p.PlayerName.Equals(playerName)); player.HoleCards = holeCards; } } return(playerList); }
private void ReadPlayers(HandHistory hand, List <JSON_player> players) { hand.Players = new PlayerList(); foreach (var player in players) { hand.Players.Add(new Player(player.player, player.startingStack, player.seat) { IsSittingOut = player.sitout, HoleCards = HoleCards.FromCards(player.cards), }); } }
public void ParsePlayers_Hero() { var expected = new PlayerList(new List <Player>() { new Player("WM_Hero", 400m, 1) { HoleCards = HoleCards.FromCards("4c5s") }, new Player("Opponent1", 400m, 2), new Player("Opponent2", 400m, 3), }); TestParsePlayers("Hero", expected); }
static PlayerList ParsePlayers(string[] handLines, bool GetHoleCards) { var playerList = new PlayerList(); List <string> playerLines = GetPlayerLinesFromHandLines(handLines); for (int i = 0; i < playerLines.Count; i++) { string line = playerLines[i]; string playerName = GetEncodedAttribute(line, " alias=\""); decimal stack = decimal.Parse(GetAttribute(line, " balance=\""), provider); int seat = GetPlayerSeatNumber(line); bool sittingOut = GetSittingOutFromPlayerLine(playerLines[i]); playerList.Add(new Player(playerName, stack, seat) { IsSittingOut = sittingOut }); } if (!GetHoleCards) { return(playerList); } int heroSeat = GetHeroSeatNumber(handLines); int heroCardsIndex = GetHeroCardsFirstLineIndex(handLines, heroSeat, playerLines.Count + 1); if (heroCardsIndex != -1) { heroCardsIndex++; var cards = ParseCardsFromLines(handLines, ref heroCardsIndex); var player = playerList.FirstOrDefault(p => p.SeatNumber == heroSeat); player.HoleCards = HoleCards.FromCards(player.PlayerName, cards.ToArray()); } foreach (Player player in playerList) { // try to obtain the holecards for the player var holeCards = GetPlayerCardsFromHandLines(handLines, player.SeatNumber, player.PlayerName); if (holeCards != null) { player.HoleCards = holeCards; } } return(playerList); }
static HoleCards ParseHoleCards(string line) { int openSquareIndex = line.LastIndexOf('[') + 1; int closeSquareIndex = line.LastIndexOf(']'); if (openSquareIndex == -1 || closeSquareIndex == -1) { return(null); } string holeCards = line.Substring(openSquareIndex, closeSquareIndex - openSquareIndex); return(HoleCards.FromCards(holeCards.Replace(" ", ""))); }
private void AddShowCardsAction(HandHistory history, Player player, Card[] cards) { history.HandActions.Add(new HandAction( player.PlayerName, HandActionType.SHOW, 0, Street.Showdown )); if (player.hasHoleCards) { return; } player.HoleCards = HoleCards.FromCards(player.PlayerName, cards); }
public void ParsePlayers_FiveCardOmaha() { var expected = new PlayerList(new List <Player>() { new Player("madmax84", 600m, 3) { HoleCards = HoleCards.FromCards("As5h4sAdJd") }, new Player("manics16", 250m, 4) { HoleCards = HoleCards.FromCards("9s7cTcAc3h") }, }); TestParsePlayers("FiveCardOmaha", expected); }
protected override PlayerList ParsePlayers(string[] handLines) { int seatCount = Int32.Parse(NumPlayersRegex.Match(handLines[5]).Value); PlayerList playerList = new PlayerList(); for (int i = 0; i < seatCount; i++) { string handLine = handLines[6 + i]; int colonIndex = handLine.IndexOf(':'); int openParenIndex = handLine.IndexOf('('); int seat = int.Parse(handLine.Substring(5, colonIndex - 5)); string playerName = handLine.Substring(colonIndex + 2, openParenIndex - colonIndex - 3); decimal amount = ParseAmount(handLine.Substring(openParenIndex + 2, handLine.Length - openParenIndex - 3 - 1).Trim()); playerList.Add(new Player(playerName, amount, seat)); } // Add hole-card info for (int i = handLines.Length - 2; i >= 0; i--) { string handLine = handLines[i]; if (handLine[0] == '*') { break; } if (handLine.EndsWith("]") && char.IsDigit(handLine[handLine.Length - 3]) == false) { int openSquareIndex = handLine.IndexOf('['); string cards = handLine.Substring(openSquareIndex + 2, handLine.Length - openSquareIndex - 2 - 2); HoleCards holeCards = HoleCards.FromCards(CardNormalization(handLines, cards.Replace(",", string.Empty).RemoveWhitespace())); string playerName = handLine.Substring(0, openSquareIndex - 7); Player player = playerList.First(p => p.PlayerName.Equals(playerName)); player.HoleCards = holeCards; } } return(playerList); }
public void ParsePlayers_Hero() { var expected = new PlayerList(new List <Player>() { new Player("Player1", 128.80m, 1), new Player("Player2", 532.00m, 2), new Player("Hero", 266.40m, 3) { HoleCards = HoleCards.FromCards("Qd8hAh6c") }, new Player("Player6", 426.00m, 6) { IsSittingOut = true }, }); TestParsePlayers("Hero", expected); }
public void ParsePlayers_MuckKnownHolecards() { var expected = new PlayerList(new List <Player>() { new Player("Player 1", 18.38m, 1), new Player("MuckPlayer", 54.39m, 2) { HoleCards = HoleCards.FromCards("7sKsKhQc") }, new Player("Player 3", 23.02m, 3), new Player("Player 4", 20.99m, 4), new Player("HERO", 50m, 5) { HoleCards = HoleCards.FromCards("8c7c9s6d") }, }); TestParsePlayers("MucksHandKnownHolecards", expected); }
public void ParsePlayers_StrangePlayerName() { var expected = new PlayerList(new List <Player>() { new Player("&&££ÖÖ", 400m, 1), new Player("L'POOL", 60m, 2) { HoleCards = HoleCards.FromCards("9s9hQhJs") }, new Player("Player3", 200m, 3) { HoleCards = HoleCards.FromCards("JdJhKc7h") }, new Player("Player4", 470m, 4), new Player("Player5", 90m, 5), }); TestParsePlayers("StrangePlayerNames", expected); }
public void ParsePlayers_HoleCards_Omaha() { PlayerList players = new PlayerList() { new Player("Player1", 1158.75m, 1), new Player("Player2", 751m, 2), new Player("Player4", 985.66m, 4), new Player("Player5", 817.34m, 5) { HoleCards = HoleCards.FromCards("9dJsKd5d") }, new Player("Player6", 698m, 6) { HoleCards = HoleCards.FromCards("QcTd3s4d") } }; TestParsePlayers("OmahaHoleCards", players); }
private void ProcessHoleCard(HoleCard holeCard, HandHistory handHistory) { var holeCards = string.Join(string.Empty, holeCard.HoleCardsInfo.HoleCards.Where(x => x != null).Select(x => x.ToString())); if (string.IsNullOrEmpty(holeCards)) { return; } var hero = handHistory.Players.FirstOrDefault(x => x.PlayerName == heroName); if (hero == null) { LogProvider.Log.Warn(this, $"Hero {heroName} wasn't found in hand. [{loggerName}]"); return; } hero.HoleCards = HoleCards.FromCards(holeCards); handHistory.Hero = hero; }
private void ProcessNoticeGameHoleCard(NoticeGameHoleCard noticeGameHoleCard, HandHistory handHistory, uint userId) { if (noticeGameHoleCard.HoldCards == null) { return; } var cards = noticeGameHoleCard.HoldCards.Select(c => ConvertCardItem(c)).ToArray(); var hero = handHistory.Players.FirstOrDefault(x => x.PlayerName == userId.ToString()); if (hero == null) { LogProvider.Log.Warn($"Hero not found for hand {handHistory.HandId}, room {noticeGameHoleCard.RoomId}, user {userId}"); return; } handHistory.Hero = hero; hero.HoleCards = HoleCards.FromCards(hero.PlayerName, cards); }
private HoleCards ParseHoleCards(string handText, string playerName) { try { string regexString = GetHoleCardsRegex(playerName); var regex = Regex.Match(handText, regexString); if (regex.Success) { return(HoleCards.FromCards(playerName, CardGroup.Parse(regex.Value))); } else { return(HoleCards.NoHolecards(playerName)); } } catch (Exception ex) { throw new CardException(handText, "ParseHoleCards: Exception " + ex.Message); } }
public void ParsePlayers_STATE_RESERVED() { var expected = new PlayerList(new List <Player>() { new Player("Player1", 0m, 1) { IsSittingOut = true, }, new Player("HERO", 175.44m, 2) { HoleCards = HoleCards.FromCards("7c2dKd4s") }, new Player("Player4", 466.18m, 4) { IsSittingOut = true, }, new Player("Player5", 202.34m, 5), }); TestParsePlayers("STATE_RESERVED", expected); }
private static HoleCards GetPlayerCardsFromHandLines(string[] handLines, int playerSeat, string playerName) { for (int i = 0; i < handLines.Count(); i++) { // if the cards are shown for this player if (handLines[i].ToLower().Contains("showcards") && handLines[i].Contains(@"seat=""" + playerSeat + @"""")) { // add all cards the player has ( 2 for hold'em / 4 for omaha ) var cards = ""; do { i++; handLines[i] = handLines[i].Replace("value=\"10\"", "value=\"T\""); cards += handLines[i][13].ToString() + handLines[i][22].ToString(); } while (!handLines[i + 1].Contains("</Action")); return(HoleCards.FromCards(cards)); } } return(null); }
private void ProcessHandCardRSP(HandCardRSP message, ClientRecord record, HandHistory history) { var roomHero = record.Players.Values.FirstOrDefault(p => p.ID == record.HeroUid); if (roomHero == null) { LogProvider.Log.Warn($"Hero is not seated in hand {history.HandId}, room {record.RoomID}, user {record.HeroUid}"); return; } var hero = history.Players.FirstOrDefault(p => p.PlayerName == roomHero.ID.ToString()); if (hero == null) { LogProvider.Log.Warn($"Hero not found for hand {history.HandId}, room {record.RoomID}, user {record.HeroUid}"); return; } history.Hero = hero; hero.HoleCards = HoleCards.FromCards(hero.PlayerName, GetCards(message)); }
private void ProcessNoticeGameShowDown(NoticeGameShowDown noticeGameShowDown, HandHistory handHistory) { if (noticeGameShowDown.Shows == null) { return; } foreach (var show in noticeGameShowDown.Shows) { var player = GetPlayer(handHistory, show.SeatId + 1); if (handHistory.HandActions.Any(x => x.PlayerName == player.PlayerName && x.HandActionType == HandActionType.SHOW)) { continue; } var showAction = new HandAction(player.PlayerName, HandActionType.SHOW, 0, Street.Showdown); handHistory.HandActions.Add(showAction); if (player.hasHoleCards) { continue; } if (show.Cards == null) { LogProvider.Log.Warn(CustomModulesNames.PKCatcher, $"NoticeGameShowDown.Show.Cards must be not null."); continue; } var cards = show.Cards.Select(c => ConvertCardItem(c)).ToArray(); player.HoleCards = HoleCards.FromCards(player.PlayerName, cards); } }
public void ParsePlayers_WithShowdown2() { var expected = new PlayerList(new List <Player>() { new Player("Player1", 1000, 1), new Player("Player3", 573.100m, 3) { HoleCards = HoleCards.FromCards("6s4d9d8s") }, new Player("Player5", 1000m, 5), new Player("Player6", 1000m, 6), new Player("Player8", 1275.70m, 8) { HoleCards = HoleCards.FromCards("QsAsKcKs") }, new Player("Player10", 667m, 10) { HoleCards = HoleCards.FromCards("3dAhAcQh") }, }); TestParsePlayers("WithShowdown2", expected); }