private void GeneratePlayers() { // le human player est ajouté en premier Player hPlayer = playersBank.GetFirstHumanPlayer(); if (hPlayer != null) { players.Add(hPlayer); Debug.Log("Add human Player " + hPlayer.name); } foreach (Player p in playersBank.Items) { // A voir si on les ajoute aléatoirement pour la suite ... if (players.Count >= nPlayer.Value) { break; } if (!players.Items.Contains(p)) { players.Add(p); Debug.Log("Add cpu Player " + p.name); } } }
private void btnPlayers_Click(object sender, EventArgs e) { playerList.Clear(); lbMain.Items.Clear(); playerAmount = Convert.ToInt32(nudPlayers.Value); Player user = new Player("Player", 50000); playerList.Add(user); List <int> AI = new List <int>(playerAmount); for (int i = 0; i < 3; i++) { AI.Add(i); } for (int i = 0; i < 4 - playerAmount; i++) { AI.Remove(rand.Next(AI.Count)); } AI = shuffle(AI); for (int i = 1; i < playerAmount; i++) { playerList.Add(new AIPlayer(50000, 1, AI[i - 1])); } pokerTable = new Table(playerList); foreach (Player player in pokerTable) { lbMain.Items.Add(player.Name); } lbMain.SelectedIndex = rand.Next(lbMain.Items.Count - 1) + 1; }
private void InitialisePlayers() { players.Add(new Player("You")); if (DataManager.currentGameMode == GameMode.MultiPlayer) { string[] nameList = multiplayerList.text.Split('\n'); for (int i = 1; i <= no_Of_CPU_Players; i++) { while (true) { int index = UnityEngine.Random.Range(0, nameList.Length); string name = nameList[index].Trim(); if (name.Length == 0) { continue; } players.Add(new AIPlayer(name)); break; } } } else { for (int i = 1; i <= no_Of_CPU_Players; i++) { players.Add(new AIPlayer("Bot " + (i))); } } mainPlayer = players[0]; }
void RequestRegistration(string clientName) { if (playerList.Add(clientName)) { MessageSender.instance.SendMessageToAll("AcceptPlayer", clientName); RefreshPlayerList(); RaiseRefreshPlayerList(); } else { MessageSender.instance.SendMessageToAll("RejectPlayer", clientName); } }
//the all important constructors public FormPoker() { InitializeComponent(); this.Icon = new Icon("Poker.ico"); timerCount = 0; screenWidth = Screen.PrimaryScreen.Bounds.Width; screenHeight = Screen.PrimaryScreen.Bounds.Height; width_ratio = (screenWidth / this.Width); height_ratio = (screenHeight / this.Height); SizeF scale = new SizeF(width_ratio, height_ratio); pbMain.Scale(scale); this.Size = pbMain.Size; foreach (Control control in this.Controls) { control.Font = new Font(control.Font.Name, control.Font.SizeInPoints * height_ratio * width_ratio, control.Font.Style); } cardWidth = Convert.ToInt32(71f * width_ratio); cardHeight = Convert.ToInt32(96f * height_ratio); user = new UserAccount(); Random rand = new Random(); Player me = new Player(playerName, BuyInAmount); playerList = new PlayerList(); playerList.Add(me); lblName.Text = me.Name; List <int> AI = new List <int>(playerAmount); for (int i = 0; i < 3; i++) { AI.Add(i); } for (int i = 0; i < 4 - playerAmount; i++) { AI.Remove(rand.Next(AI.Count)); } AI = shuffle(AI); for (int i = 1; i < playerAmount; i++) { playerList.Add(new AIPlayer(BuyInAmount, difficulty, AI[i - 1])); //labelListName[i].Text = playerList[i].Name; } FormInformation Information = new FormInformation(playerList); Information.StartPosition = FormStartPosition.CenterScreen; Information.ShowDialog(); Information.Dispose(); pokerTable = new Table(playerList); SoundPlayer sound = new SoundPlayer(); }
protected override PlayerList ParsePlayers(string[] handLines) { var playerList = new PlayerList(); string[] playerLines = GetPlayerLinesFromHandLines(handLines); for (int i = 0; i < playerLines.Length; i++) { string playerName = GetNameFromPlayerLine(playerLines[i]); decimal stack = GetStackFromPlayerLine(playerLines[i]); int seat = GetSeatNumberFromPlayerLine(playerLines[i]); bool sittingOut = GetSittingOutFromPlayerLine(playerLines[i]); playerList.Add(new Player(playerName, stack, seat) { IsSittingOut = sittingOut }); } 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); }
public void Remove_Player_Test() { //arrange string name = "TestName"; string surname = "Testsurname"; int id = 98; //act Player testPlayer = new Player() { Name = name, Surname = surname, ID = id }; PlayerList testplayerList = new PlayerList(); testplayerList.Add(testPlayer); testplayerList.Remove(id); //assert var check = testplayerList.FindByID(id); Assert.AreEqual(null, check, "Incompatibility in Remove Player from list"); }
public void Add_Player_Test() { //arrange string name = "TestName"; string surname = "Testsurname"; int id = 98; //act Player testPlayer = new Player() { Name = name, Surname = surname, ID = id }; PlayerList testplayerList = new PlayerList(); testplayerList.Add(testPlayer); //assert Player lookingPlayer = testplayerList.FindByID(id); Assert.AreEqual(name, lookingPlayer.Name, "Incompatibility in Add Player to List"); Assert.AreEqual(surname, lookingPlayer.Surname, "Incompatibility in Add Player to List"); Assert.AreEqual(id, lookingPlayer.ID, "Incompatibility in Add Player to List"); }
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) { var playerList = new PlayerList(); string[] playerLines = GetPlayerLinesFromHandLines(handLines); for (int i = 0; i < playerLines.Length; i++) { string line = playerLines[i]; string playerName = GetAttribute(line, " alias=\""); decimal stack = decimal.Parse(GetAttribute(line, " balance=\""), provider); int seat = int.Parse(GetAttribute(line, " num=\"")); bool sittingOut = GetSittingOutFromPlayerLine(playerLines[i]); playerList.Add(new Player(playerName, stack, seat) { IsSittingOut = sittingOut }); } 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); }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); for (int i = 1; i < 12; i++) { string handLine = handLines[i]; if (handLine.StartsWith("Seat ") == false) { return(playerList); } if (handLine.EndsWith(")") == false) { // handline is like Seat 6: ffbigfoot ($0.90), is sitting out handLine = handLine.Substring(0, handLine.Length - 16); } //Seat 1: CardBluff ($109.65) int colonIndex = handLine.IndexOf(':', 5); int parenIndex = handLine.IndexOf('(', colonIndex + 2); int seat = Int32.Parse(handLine.Substring(colonIndex - 2, 2)); string name = handLine.Substring(colonIndex + 2, parenIndex - 1 - colonIndex - 2); string stackSizeString = handLine.Substring(parenIndex + 2, handLine.Length - 1 - parenIndex - 2); decimal amount = decimal.Parse(stackSizeString, System.Globalization.CultureInfo.InvariantCulture); playerList.Add(new Player(name, amount, seat)); } return(playerList); }
private void ComparePlayerNickname() { List <Player> listOfPlayers = Repository.GetDbPlayers().ToList(); for (int i = 0; i < listOfPlayers.Count; i++) { for (int j = 0; j < SearchNickname.Count(); j++) { if (listOfPlayers[i].Nickname.ToLower()[j] == SearchNickname.ToLower()[j]) { if (j == SearchNickname.Count() - 1) { PlayerList.Add(listOfPlayers[i]); } } else { break; } } } if (PlayerList.Count == 0) { SearchIfContainsNickname(listOfPlayers); } }
public void LinqTest() { Player p = new NFLPlayer("Fred", "QB", "Patriots", "6", new Yards(10, 5, 6, 10), new TDS(10, 5, 6, 10), 2); PlayerList.Add(p); TestDisplay.Text = PlayerList[0].ToString(); }
public void AddPlayerToGroup(string playerID) { if (!PlayerList.Contains(playerID)) { InformPlayersInGroup(MySockets.Server.GetAUser(playerID).Player.FullName + " has joined the group."); PlayerList.Add(playerID); MySockets.Server.GetAUser(playerID).GroupName = GroupName; if (PendingInvitations.Contains(playerID)) { PendingInvitations.Remove(playerID); } if (PendingRequests.Contains(playerID)) { PendingRequests.Remove(playerID); } InformPlayerInGroup("You have joined '" + GroupName + "'.", playerID); } if (GroupRuleForLooting == GroupLootRule.Master_Looter && string.IsNullOrEmpty(MasterLooter)) { MySockets.Server.GetAUser(LeaderID).MessageHandler("You have not yet assigned someone in the group as the master looter."); } }
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); }
/// <summary> /// Use me isntead /// </summary> /// <param name="data"></param> internal GameInfoScreen(GameInfo data) { gamedata = data; InitializeComponent(); //Gogogo GameSection.Title = data.GameType.Name; this.Title = data.GameType.Name + $" ({data.GameUniqueId.ToString()})"; GameIdCell.Detail = data.GameUniqueId.ToString(); EntryCell.Detail = "£" + data.Entry.ToString("F2"); PotCell.Detail = "£" + (data.Entry * data.Players.Count).ToString("F2"); Timestamp.Detail = data.GameCompleted.ToString(); //Finished Status if (data.Finished) { CompletedCell.Detail = "Yes"; FinishButton.IsVisible = false; } else { CompletedCell.Detail = "No (press below to finish)"; FinishButton.IsVisible = true; } //Players foreach (Player player in data.Players) { var newcell = new TextCell() { Text = player.Name, Detail = "Currently " + player.CurrentMargin.ToString() }; PlayerList.Add(newcell); } }
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); }
public void Init(List <int> uIdList) { foreach (int uid in uIdList) { PlayerDto dto = new PlayerDto(uid); PlayerList.Add(dto); } }
public void AddPlayer(string name, double bankRoll) { var newPlayer = new Player(1); newPlayer.Name = name; newPlayer.PlayerbankRoll = bankRoll; PlayerList.Add(newPlayer); }
public void Join(Player pPlayer) { if (Game == null) { PlayerList.Add(pPlayer); } BroadcastGame(); }
protected override PlayerList ParsePlayers(JObject JSON) { var handJSON = JSON["history"][0]; var playersJSON = handJSON["player"]; var playerlist = new PlayerList(); foreach (var playerJSON in playersJSON) { var name = playerJSON["name"].ToString(); if (name == "UNKNOWN") { continue; } var stack = playerJSON["amount"].Value <decimal>(); var seat = playerJSON["seat"].Value <int>(); var state = playerJSON["state"].ToString(); playerlist.Add(new Player(name, stack, seat) { IsSittingOut = state != "STATE_PLAYING" }); } var actionsJSON = handJSON["action"]; foreach (var action in actionsJSON) { string type = action["type"].ToString(); if (type.StartsWithFast("ACTION")) { break; } else if (type == "HAND_DEAL") { if (isDealtCards(action)) { var playerName = action["player"].ToString(); playerlist[playerName].HoleCards = ParseHoleCards(action["card"]); break; } } } var resultJSON = handJSON["showDown"]["result"]; foreach (var result in resultJSON) { var cardsJSON = result["card"]; if (cardsJSON != null && cardsJSON.Count() > 0) { var name = result["player"].ToString(); playerlist[name].HoleCards = ParseHoleCards(cardsJSON); } } return(playerlist); }
//Colocar no playersList todos os players salvos no bakcup para poder reiniciar o jogo, chamado pelos scripts EndlessTricksManager e ChallengerTricksManager public void RefillPlayerList() { foreach (PlayersInfo player in backUpList) { PlayerList.Add(player); } PlayersCount = backUpList.Count; }
//add a player to the game public bool AddPlayer(Player player) { if (!PlayersList.Add(player)) { return(false); } return(true); }
private void OnPlay(object obj) { // IEnumerable<PlayerInfo> temp = (IEnumerable<PlayerInfo>)PlayerList.GetEnumerator(); List <PlayerInfo> p = PlayerList.ToList(); CommonUtils.Utilities.Shuffle(ref p); int numPlayers = p.Count; PlayerList.Clear(); int i = 0; ////Create Mafia List for (i = 0; i < NumMafias && i < numPlayers; ++i) { p[i].Role = "mafia"; Mafias.Add(p[i]); PlayerList.Add(p[i]); } //Create SpecialChar List if (HasDoctor && i < numPlayers) { p[i].Role = "doctor"; Specialists.Add(p[i]); PlayerList.Add(p[i]); i++; } if (HasDetective && i < numPlayers) { p[i].Role = "detective"; Specialists.Add(p[i]); PlayerList.Add(p[i]); i++; } if (HasJoker && i < numPlayers) { p[i].Role = "joker"; Specialists.Add(p[i]); PlayerList.Add(p[i]); i++; } //Create Villager List for (; i < numPlayers; ++i) { p[i].Role = "villager"; PlayerList.Add(p[i]); } //notify roles to the players foreach (var x in PlayerList) { _serverModel.SendMessage(x.ConnectionInfo.Connection, "Role", x.Role); } }
private void SearchIfContainsNickname(List <Player> listOfPlayers) { foreach (Player c in listOfPlayers) { if (c.Nickname.ToLower().Contains(SearchNickname.ToLower())) { PlayerList.Add(c); } } }
private void AddPlayerEntry(int playerId, string playerName, string team) { ExecuteOnUIThread.Invoke(() => PlayerList.Add(new PlayerData { RealPlayerId = playerId, PlayerName = playerName, Team = team, IsServerMaster = false, })); }
/// <summary> /// プレイヤー追加 /// </summary> private void AddPlayer() { if (!CanAddPlayer()) { return; } PlayerList.Add(AddPlayerName); AddPlayerName = string.Empty; }
public void AddingPlayersToPlayerListRaisesPlayerJoinedEvent() { bool eventRaised = false; IPlayerList playerList = new PlayerList(); IPlayer player = MockRepository.GenerateStub<IPlayer>(); playerList.PlayerAdded += (newPlayer) => { if (newPlayer == player) eventRaised = true; }; playerList.Add(player); Assert.IsTrue(eventRaised); }
public void AddEnemyPlayers(params PlayerInfo[] enemies) { foreach (PlayerInfo enemy in enemies) { EnemyPlayer newEnemy = new EnemyPlayer(enemy.id, enemy.name, enemy.avatarType); newEnemy.CreateResources(); PlayerList.Add(newEnemy); UnityEngine.Debug.Log("Added player " + enemy.name + ", now at count: " + PlayerList.Count); } NotifyObservers(PlayerList.Count); }
internal bool AddPlayer(Player player, IClient client) { if (PlayerList.Count >= MaxPlayers || HasStarted) { return(false); } PlayerList.Add(player); Clients.Add(client); return(true); }
/* These methods add an item to all relevant lists */ public void Add(Player item) { Debug.Assert(item != null, "item is null."); if (PlayerList.Count <= MaxPlayers) { item.PlayerIndex = (PlayerIndex)PlayerList.Count; PlayerList.Add(item); EntityList.Add(item); PhysicalObjectList.Add(item); } }
/// <summary> /// Returns a set of players with best draw including player /// cards and cards on table /// </summary> public PlayerList GetBestDrawPlayers(PlayerList players) { PlayerList currentBestDrawPlayers = new PlayerList(); Draw bestDrawSoFar = null; // Get best draw types by comparing all players draws. foreach (Player player in players) { if (!player.HasCards()) continue; Draw currentDraw = GetDraw(player.GetAllCards()); try { // save the current draw if it is better than the previuosly best found draw if (!GetBestDraw(currentDraw, bestDrawSoFar).Equals(bestDrawSoFar)){ currentBestDrawPlayers.Clear(); currentBestDrawPlayers.Add(player); bestDrawSoFar = currentDraw; } } catch (TieDrawException) { currentBestDrawPlayers.Add(player); } } return currentBestDrawPlayers; }
//the all important constructors public FormPoker() { InitializeComponent(); this.Icon = new Icon("Poker.ico"); timerCount = 0; screenWidth = Screen.PrimaryScreen.Bounds.Width; screenHeight = Screen.PrimaryScreen.Bounds.Height; width_ratio = (screenWidth / this.Width); height_ratio = (screenHeight / this.Height); SizeF scale = new SizeF(width_ratio, height_ratio); pbMain.Scale(scale); this.Size = pbMain.Size; foreach (Control control in this.Controls) { control.Font = new Font(control.Font.Name, control.Font.SizeInPoints * height_ratio * width_ratio, control.Font.Style); } cardWidth = Convert.ToInt32(71f * width_ratio); cardHeight = Convert.ToInt32(96f * height_ratio); user = new UserAccount(); Random rand = new Random(); Player me = new Player(playerName, BuyInAmount); playerList = new PlayerList(); playerList.Add(me); lblName.Text = me.Name; List<int> AI = new List<int>(playerAmount); for (int i = 0; i < 3; i++) { AI.Add(i); } for (int i = 0; i < 4 - playerAmount; i++) { AI.Remove(rand.Next(AI.Count)); } AI = shuffle(AI); for (int i = 1; i < playerAmount; i++) { playerList.Add(new AIPlayer(BuyInAmount, difficulty, AI[i - 1])); //labelListName[i].Text = playerList[i].Name; } FormInformation Information = new FormInformation(playerList); Information.StartPosition = FormStartPosition.CenterScreen; Information.ShowDialog(); Information.Dispose(); pokerTable = new Table(playerList); SoundPlayer sound = new SoundPlayer(); }
private void button10_Click(object sender, EventArgs e) { pokerTable.getPlayers().Clear(); numberOFPlayers = Convert.ToInt32(nudAmount.Value); PlayerList players = new PlayerList(); Random rand = new Random(); for (int i = 0; i < numberOFPlayers; i++) { players.Add(new Player("Player " + (i + 1), 10000)); } players[0].ChipStack = 10000; players[1].ChipStack = 9000; players[2].ChipStack = 9500; players[3].ChipStack = 9500; pokerTable = new Table(players); Print(); }
//showdown code! public void ShowDown() { //creating sidepots if (CreateSidePots()) { mainPot.getPlayersInPot().Sort(); for (int i = 0; i < mainPot.getPlayersInPot().Count - 1; i++) { if (mainPot.getPlayersInPot()[i].AmountInPot != mainPot.getPlayersInPot()[i + 1].AmountInPot) { PlayerList tempPlayers = new PlayerList(); for (int j = mainPot.getPlayersInPot().Count - 1; j > i; j--) { tempPlayers.Add(mainPot.getPlayersInPot()[j]); } int potSize = (mainPot.getPlayersInPot()[i + 1].AmountInPot - mainPot.getPlayersInPot()[i].AmountInPot) * tempPlayers.Count; mainPot.Amount -= potSize; sidePots.Add(new Pot(potSize, tempPlayers)); } } } //awarding mainpot PlayerList bestHandList = new PlayerList(); List<int> Winners = new List<int>(); bestHandList = QuickSortBestHand(new PlayerList(mainPot.getPlayersInPot())); for (int i = 0; i < bestHandList.Count; i++) { for (int j = 0; j < this.getPlayers().Count; j++) if (players[j] == bestHandList[i]) { Winners.Add(j); } if (HandCombination.getBestHand(new Hand(bestHandList[i].getHand())) != HandCombination.getBestHand(new Hand(bestHandList[i + 1].getHand()))) break; } mainPot.Amount /= Winners.Count; if (Winners.Count > 1) { for (int i = 0; i < this.getPlayers().Count; i++) { if (Winners.Contains(i)) { currentIndex = i; players[i].CollectMoney(mainPot); winnermessage += players[i].Name + ", "; } } winnermessage +=Environment.NewLine+ " split the pot."; } else { currentIndex = Winners[0]; players[currentIndex].CollectMoney(mainPot); winnermessage = players[currentIndex].Message; } //awarding sidepots for (int i = 0; i < sidePots.Count; i++) { List<int> sidePotWinners = new List<int>(); for (int x = 0; x < bestHandList.Count; x++) { for (int j = 0; j < this.getPlayers().Count; j++) if (players[j] == bestHandList[x]&&sidePots[i].getPlayersInPot().Contains(bestHandList[x])) { sidePotWinners.Add(j); } if (HandCombination.getBestHand(new Hand(bestHandList[x].getHand())) != HandCombination.getBestHand(new Hand(bestHandList[x + 1].getHand()))&&sidePotWinners.Count!=0) break; } sidePots[i].Amount /= sidePotWinners.Count; for (int j = 0; j < this.getPlayers().Count; j++) { if (sidePotWinners.Contains(j)) { currentIndex = j; players[j].CollectMoney(sidePots[i]); } } } }
//using the monte carlo method, calculate a hand value for the AI's current hand //this can be very hard on the computer's memory and processor and can result in lag time public void CalculateHandValue(int count) { double score = 0; PlayerList playerList = new PlayerList(); for (int i = 0; i < count - 1; i++) { playerList.Add(new Player()); } Hand bestHand = new Hand(); int bestHandCount = 1; Deck deck = new Deck(); Hand knownCommunityCards = new Hand(); Hand remainingCommunityCards = new Hand(); Hand myHoleCards = new Hand(); //remove known cards from deck for (int i = 0; i < myHand.Count(); i++) { deck.Remove(myHand[i]); } //add known community cards for (int i = 2; i < myHand.Count(); i++) { knownCommunityCards.Add(myHand[i]); } myHoleCards.Add(this.getHand()[0]); myHoleCards.Add(this.getHand()[1]); //loop 100 times for (int i = 0; i < 100; i++) { //reset players and shuffle deck for (int j = 0; j < playerList.Count; j++) { playerList[j].isbusted = false; playerList[j].getHand().Clear(); } myHand.Clear(); remainingCommunityCards.Clear(); deck.Shuffle(); //generate remaining community cards if (knownCommunityCards.Count() < 5) { remainingCommunityCards.Add(deck.Deal()); if (knownCommunityCards.Count() < 4) { remainingCommunityCards.Add(deck.Deal()); if (knownCommunityCards.Count() < 3) { remainingCommunityCards.Add(deck.Deal()); remainingCommunityCards.Add(deck.Deal()); remainingCommunityCards.Add(deck.Deal()); } } } //add hole/community cards to the AI this.AddToHand(knownCommunityCards); this.AddToHand(remainingCommunityCards); this.AddToHand(myHoleCards); //add hole/community cards to other players for (int j = 0; j < playerList.Count; j++) { playerList[j].AddToHand(knownCommunityCards); if (remainingCommunityCards.Count() != 0) playerList[j].AddToHand(remainingCommunityCards); playerList[j].AddToHand(deck.Deal()); playerList[j].AddToHand(deck.Deal()); //if player is dealt hole cards of less than 5-5, and no pocket pairs the player drops out if (playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() + playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank() <= 10 && playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() != playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank()) { playerList[j].isbusted = true; } } //add cards back to deck for (int j = 0; j < remainingCommunityCards.Count(); j++) { deck.Add(remainingCommunityCards[j]); } for (int j = 0; j < playerList.Count; j++) { deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 1]); deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 2]); } //compare hands bestHandCount = 1; playerList.Add(this); bestHand = playerList[0].getHand(); for (int j = 0; j <playerList.Count-1; j++) { if (playerList[j].isbusted) continue; if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) > HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand()))) { bestHandCount = 1; bestHand = playerList[j+1].getHand(); } else if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) == HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand()))) bestHandCount++; } playerList.Remove(this); //if my hand is the best, increment score if (myHand.isEqual(bestHand)) score = score + (1 / bestHandCount); } //reconstruct original hand myHand.Clear(); this.AddToHand(myHoleCards); this.AddToHand(knownCommunityCards); //calculate hand value as a percentage of wins handValue = score / 100; }
protected override PlayerList ParsePlayers(string[] handLines) { int linenumber = handLines[3].Contains("User:"******"^Players in round: (?<numPlayers>\d).?"); string numPlayersStr = handLineMatch.Groups["numPlayers"].Value; int numPlayers = Int32.Parse(numPlayersStr); // 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) //OLD CODE //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[linenumber + 1 + 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, DecimalSeperator), 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] // Seat 4: mohunter007 ($2,875.60), net: -$2,075, [Qd, 6s] (PAIR QUEEN) 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(",", "")); if (handLine.Contains("[") && handLine.Contains("]")) { int colonIndex = handLine.IndexOf(':'); int parenIndex = handLine.IndexOf('('); string name = handLine.Substring(colonIndex + 2, parenIndex - 2 - colonIndex - 1); int openSquareIdex = handLine.LastIndexOf('['); int endSquareIdex = handLine.LastIndexOf(']') + 1; string holeCards = handLine.Substring(openSquareIdex + 1, endSquareIdex - openSquareIdex - 2); Player player = playerList.First(p => p.PlayerName.Equals(name)); player.HoleCards = HoleCards.FromCards(holeCards.Replace(" ", "").Replace(",", "")); } } // Dealing to thanasunn88: [Qs, 6c] for (int i = linenumber; i < handLines.Length; i++) { string handLine = handLines[i]; if (handLine.Contains("Dealing to")) { var DealingMatch = Regex.Match(handLine, @"^Dealing to (?<name>.+): \[(?<Dealing>.+)\]"); string Dealing = DealingMatch.Groups["Dealing"].Value; string name = DealingMatch.Groups["name"].Value; Player player = playerList.First(p => p.PlayerName.Equals(name)); player.HoleCards = HoleCards.FromCards(Dealing.Replace(" ", "").Replace(",", "")); break; } } return playerList; }
public static PlayerList GetPlayerInfos(List<string> steamids, bool force) { PlayerList res = new PlayerList(); List<string> toDownload = new List<string>(); if (force) { AllLoadedPlayers.RemoveAll((p) => steamids.Contains(p.SteamID64)); toDownload.AddRange(steamids); } else { foreach (string id in steamids) { if (AllLoadedPlayers.Contains(id)) { res.Add(AllLoadedPlayers.GetFriendBySteamID(id)); } else { toDownload.Add(id); } } } VersatileIO.Debug("Requesting player data for {0} players...", toDownload.Count); string url = GetPlayerInfoUrl(toDownload); string data = Util.DownloadString(url, Settings.Instance.DownloadTimeout); if (data == null) { return res; } PlayerSummariesJson json = JsonConvert.DeserializeObject<PlayerSummariesJson>(data); if (json == null || json.response == null) { VersatileIO.Error(" Error parsing player data: JSON data was null"); return res; } foreach (PlayerSummaryJson psj in json.response.players) { Player p = new Player(psj); AllLoadedPlayers.Add(p); res.Add(p); } return res; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); for (int i = 1; i < 12; i++) { string handLine = handLines[i]; var sittingOut = false; if (handLine.StartsWith("Seat ") == false) { break; } if (handLine.EndsWith(")") == false) { // handline is like Seat 6: ffbigfoot ($0.90), is sitting out handLine = handLine.Substring(0, handLine.Length - 16); sittingOut = true; } //Seat 1: CardBluff ($109.65) int colonIndex = handLine.IndexOf(':', 5); int parenIndex = handLine.IndexOf('(', colonIndex + 2); int seat = Int32.Parse(handLine.Substring(colonIndex - 2, 2)); string name = handLine.Substring(colonIndex + 2, parenIndex - 1 - colonIndex - 2); string stackSizeString = handLine.Substring(parenIndex + 1, handLine.Length - 1 - parenIndex - 1); decimal amount = decimal.Parse(stackSizeString, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, NumberFormatInfo); playerList.Add(new Player(name, amount, seat) { IsSittingOut = sittingOut }); } // OmahaHiLo has a different way of storing the hands at showdown, so we need to separate bool isOmahaHiLo = ParseGameType(handLines).Equals(GameType.PotLimitOmahaHiLo); int ShowStartIndex = -1; const int FirstPossibleShowActionIndex = 13; for (int i = FirstPossibleShowActionIndex; i < handLines.Length; i++) { string line = handLines[i]; if (line[line.Length - 1] == ']' && line.Contains(" shows [")) { ShowStartIndex = i; break; } if (line.StartsWith(@"*** SUM", StringComparison.Ordinal) && isOmahaHiLo) { ShowStartIndex = i; break; } else if (line.StartsWith(@"*** SH", StringComparison.Ordinal) && !isOmahaHiLo) { ShowStartIndex = i; break; } } if (ShowStartIndex != -1) { for (int lineNumber = ShowStartIndex; lineNumber < handLines.Length; lineNumber++) { string line = handLines[lineNumber]; int firstSquareBracket = line.LastIndexOf('['); if (firstSquareBracket == -1) { continue; } // can show single cards if (line[firstSquareBracket + 3] == ']') { continue; } int lastSquareBracket = line.LastIndexLoopsBackward(']', line.Length - 1); int colonIndex = line.LastIndexLoopsBackward(':', lastSquareBracket); string playerName; //if (isOmahaHiLo) //{ // seat = line.Substring(5, colonIndex - 5); // playerName = playerList.First(p => p.SeatNumber.Equals(Convert.ToInt32(seat))).PlayerName; //} //else //{ int playerNameEndIndex = line.IndexOf(" shows", StringComparison.Ordinal); if (playerNameEndIndex == -1) break; playerName = line.Substring(0, playerNameEndIndex); //} string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); int lastLineRead = -1; // We start on line index 2 as first 2 lines are table and limit info. for (int lineNumber = 2; lineNumber < handLines.Length - 1; lineNumber++) { string line = handLines[lineNumber]; char startChar = line[0]; char endChar = line[line.Length - 1]; //Seat 1: thaiJhonny ($16.08 in chips) if (endChar != ')') { lastLineRead = lineNumber; break; } // seat info expected in format: //Seat 1: thaiJhonny ($16.08 in chips) const int seatNumberStartIndex = 4; int spaceIndex = line.IndexOf(' ', seatNumberStartIndex); int colonIndex = line.IndexOf(':', spaceIndex + 1); int seatNumber = FastInt.Parse(line, spaceIndex + 1); // we need to find the ( before the number. players can have ( in their name so we need to go backwards and skip the last one int openParenIndex = line.LastIndexOf('('); int spaceAfterOpenParen = line.IndexOf(' ', openParenIndex); // add 2 so we skip the $ and first # always string playerName = line.Substring(colonIndex + 2, (openParenIndex - 1) - (colonIndex + 2)); string stackString = line.Substring(openParenIndex + 2, spaceAfterOpenParen - (openParenIndex + 2)); decimal stack = decimal.Parse(stackString, System.Globalization.CultureInfo.InvariantCulture); playerList.Add(new Player(playerName, stack, seatNumber)); } if (lastLineRead == -1) { throw new PlayersException(string.Empty, "Didn't break out of the seat reading block."); } // Looking for the showdown info which looks like this //*** SHOW DOWN *** //JokerTKD: shows [2s 3s Ah Kh] (HI: a pair of Sixes) //DOT19: shows [As 8h Ac Kd] (HI: two pair, Aces and Sixes) //DOT19 collected $24.45 from pot //No low hand qualified //*** SUMMARY *** int summaryIndex = GetSummaryStartIndex(handLines, lastLineRead); int showDownIndex = GetShowDownStartIndex(handLines, lastLineRead, summaryIndex); //Starting from the bottom to parse faster if (showDownIndex != -1) { for (int lineNumber = showDownIndex + 1; lineNumber < summaryIndex; lineNumber++) { //jimmyhoo: shows [7h 6h] (a full house, Sevens full of Jacks) //EASSA: mucks hand //jimmyhoo collected $562 from pot string line = handLines[lineNumber]; //Skip when player mucks and collects //EASSA: mucks hand char lastChar = line[line.Length - 1]; if (lastChar == 'd' || lastChar == 't') { continue; } int lastSquareBracket = line.LastIndexLoopsBackward(']', line.Length - 1); if (lastSquareBracket == -1) { continue; } int firstSquareBracket = line.LastIndexOf('[', lastSquareBracket); // can show single cards: // Zaza5573: shows [Qc] if (line[firstSquareBracket + 3] == ']') { continue; } int colonIndex = line.LastIndexOf(':', firstSquareBracket); if (colonIndex == -1) { // players with [ in their name // [PS_UA]Tarik collected $18.57 from pot continue; } string playerName = line.Substring(0, colonIndex); string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { int currentLine = 1; PlayerList plist = new PlayerList(); //Parsing playerlist for (int i = 0; i < 10; i++) { //<PLAYER NAME="fatima1975" SEAT="6" AMOUNT="4.27"></PLAYER> string Line = handLines[i + 1]; if (Line[1] != 'P') { currentLine = i + 1; break; } const int playerNameStartIndex = 14; int playerNameEndIndex = Line.IndexOf('\"', playerNameStartIndex); string playerName = Line.Substring(playerNameStartIndex, playerNameEndIndex - playerNameStartIndex); if (playerName == "UNKNOWN") { continue; } int seatStartIndex = playerNameEndIndex + 8; int seatEndIndex = Line.IndexOf('\"', seatStartIndex); int seatNumber = int.Parse(Line.Substring(seatStartIndex, seatEndIndex - seatStartIndex)); int stackStartIndex = seatEndIndex + 10; int stackEndIndex = Line.IndexOf('\"', stackStartIndex); decimal stack = decimal.Parse(Line.Substring(stackStartIndex, stackEndIndex - stackStartIndex), provider); plist.Add(new Player(playerName, stack, seatNumber)); } //Parsing dealt cards for (int i = currentLine; i < handLines.Length; i++) { string Line = handLines[i]; char firstChar = Line[1]; if (firstChar == 'A') { //<ACTION TYPE="HAND_BLINDS" PLAYER="ItalyToast" KIND="HAND_BB" VALUE="200.00"></ACTION> //<ACTION TYPE="HAND_DEAL" PLAYER="AllinAnna"> const int actionTypeCharIndex = 19; char actionTypeChar = Line[actionTypeCharIndex]; if (actionTypeChar == 'D') { string playerName = GetXMLAttributeValue(Line, "PLAYER"); ParseDealtHand(handLines, i, plist[playerName]); } } if (firstChar == 'S') { currentLine = i + 1; break; } } //Parse Showdown cards for (int i = handLines.Length - 1; i > currentLine; i--) { string Line = handLines[i]; char firstChar = Line[1]; if (firstChar == 'C') { continue; } //<RESULT PLAYER="ItalyToast" WIN="10.00" HAND="$(STR_BY_DEFAULT)" WINCARDS="14 1 50 5 14 "> if (firstChar == 'R') { const int playerNameStartIndex = 16; int playerNameEndIndex = Line.IndexOf('\"', playerNameStartIndex); string playerName = Line.Substring(playerNameStartIndex, playerNameEndIndex - playerNameStartIndex); Player player = plist[playerName]; if (!player.hasHoleCards) { for (int cardIndex = i + 1; cardIndex <= i + 4 && cardIndex < handLines.Length; cardIndex++) { string cardLine = handLines[cardIndex]; if (cardLine[1] != 'C') { break; } Card parsedCard = ParseCard(cardLine); if (!parsedCard.isEmpty) { if (player.HoleCards == null) { player.HoleCards = HoleCards.NoHolecards(); } player.HoleCards.AddCard(parsedCard); } } } } if (firstChar == 'S') { break; } } return plist; }
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) { XDocument document = GetXDocumentFromLines(handLines); XElement gameElement = GetGameElementFromXDocument(document); XElement players = gameElement.Element("players"); PlayerList playerList = new PlayerList(); //Build a query for all cards elements which are "SHOWN" or "MUCKED" rather than "COMMUNITY" IEnumerable<XElement> cardElements = gameElement.Elements("round").Elements("cards").Where(element => !element.Attribute("type").Value.StartsWith("C")).ToList(); foreach (XElement playerElement in players.Elements()) { //Player Element looks like: //<player seat="0" nickname="GODEXISTSJK" balance="$269.96" dealtin="true" /> decimal stack = decimal.Parse(playerElement.Attribute("balance").Value.Substring(1), DecimalSeperator); string playerName = playerElement.Attribute("nickname").Value; int seat = Int32.Parse(playerElement.Attribute("seat").Value); Player player = new Player(playerName, stack, seat); bool dealtIn = bool.Parse(playerElement.Attribute("dealtin").Value); player.IsSittingOut = !dealtIn; //<cards type="SHOWN" cards="Ac,4c" player="7"/> XElement playerCardElement = cardElements.FirstOrDefault(card => Int32.Parse(card.Attribute("player").Value) == seat); if (playerCardElement != null) { string cardString = playerCardElement.Attribute("cards").Value; player.HoleCards.AddCards(BoardCards.Parse(cardString)); } playerList.Add(player); } return playerList; }
protected PlayerList ParsePlayers(string handText, out List<HandAction> handActions) { try { var seat = Regex.Match(handText, SeatInfoRegex); if (!seat.Success) { throw new PlayersException( handText, "ParsePlayerNames: Couldn't find any seating info!"); } PlayerList players = new PlayerList(); do { decimal startingStack = decimal.Parse(Regex.Match(seat.Value, SeatInfoStartingStackRegex).Value); int position = Int32.Parse(Regex.Match(seat.Value, SeatInfoSeatNumberRegex).Value); string screenName = Regex.Match(seat.Value, SeatInfoPlayerNameRegex).Value; players.Add(new Player(screenName, startingStack, position)); } while ((seat = seat.NextMatch()).Success); foreach (var player in players) { player.HoleCards = ParseHoleCards(handText, player.PlayerName); } handActions = ParseHandActions(handText, players); SetSittingOutPlayers(players, handActions); return players; } catch (Exception ex) { throw; } }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); int lastLineRead = -1; // We start on line index 5 as first 5 lines are table and limit info. const int playerListStart = 5; for (int lineNumber = playerListStart; lineNumber < handLines.Length; lineNumber++) { string line = handLines[lineNumber]; char lastChar = line[line.Length - 1]; // leave the loop if we spot a summary/hand start of line if (line.StartsWith("** ")) { break; } // players can also seat at the table after the seat info, post a big blind and be immediately involved in the hand const int seatNumberStartIndex = 5; int playerNameStartIndex = line.IndexOf(':', seatNumberStartIndex) + 2; // seat info expected in format: // Seat 4: thaiJhonny ( $1,404 USD ) if (playerNameStartIndex > 1 && lastChar == ')' && line.StartsWith("Seat ")) { int seatNumber = FastInt.Parse(line, seatNumberStartIndex); // we need to find the ( before the number. players can have ( in their name so we need to go backwards and skip the last one int openParenIndex = line.LastIndexOf('('); string playerName = line.Substring(playerNameStartIndex, openParenIndex - playerNameStartIndex - 1); decimal stack = ParseDecimal(line, openParenIndex + 3); playerList.Add(new Player(playerName, stack, seatNumber)); } // post blind // kpark1996 posts big blind [$1 USD]. else if (lastChar == '.') { // they don't have a known seatNumber int seatNumber = -1; decimal stack = 999999.00m; // we make the stacksize very high so bettings can never result in a "negative stack" int nameEndIndex = line.IndexOf(" posts ", StringComparison.Ordinal); if (nameEndIndex == -1) { continue; } string playerName = line.Substring(0, nameEndIndex); // only add if the player is unknown if (!playerList.Any(p => p.PlayerName.Equals(playerName))) { playerList.Add(new Player(playerName, stack, seatNumber)); } } } // Looking for the showdown info which looks like this // Player1 checks // Player2 shows [ 8h, 5h, Ad, 3d ]high card Ace. // Player1 shows [ 9h, Qd, Qs, 6d ]three of a kind, Queens. // Player1 wins $72 USD from the main pot with three of a kind, Queens. for (int lineNumber = handLines.Length - 1; lineNumber > 0; lineNumber--) { //jimmyhoo: shows [7h 6h] (a full house, Sevens full of Jacks) //EASSA: mucks hand //jimmyhoo collected $562 from pot string line = handLines[lineNumber]; //Skip when player mucks and collects //EASSA: mucks hand char lastChar = line[line.Length - 1]; if (lastChar != '.') { break; } if (!line.Contains(" show")) { continue; } int lastSquareBracket = line.LastIndexOf(']'); if (lastSquareBracket == -1) { continue; } int firstSquareBracket = line.LastIndexOf('[', lastSquareBracket); // can show single cards: // Zaza5573: shows [Qc] if (line[firstSquareBracket + 3] == ']') { continue; } int nameEndIndex = GetNameEndIndex(line);// line.IndexOf(' '); string playerName = line.Remove(nameEndIndex); string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { //Expected Start //Game started at: 2014/2/28 15:59:51 //Game ID: 258592968 2/4 Gabilite (JP) - CAP - Max - 2 (Hold'em) //Seat 4 is the button //Seat 1: xx59704 (159.21). //Seat 4: Xavier2500 (110.40). //... PlayerList playerList = new PlayerList(); int CurrentLineIndex = 3; //The first line after the player list always starts with "Player " while (handLines[CurrentLineIndex][0] == 'S') { string playerLine = handLines[CurrentLineIndex++]; const int seatNumberStart = 5; int colonIndex = playerLine.IndexOf(':', seatNumberStart + 1); int SeatNumber = int.Parse(playerLine.Substring(seatNumberStart, colonIndex - seatNumberStart)); //Parsing playerName //PlayerName can contain '(' & ')' int NameStartIndex = colonIndex + 2; int NameEndIndex = playerLine.LastIndexOf(" ("); string playerName = playerLine.Substring(NameStartIndex, NameEndIndex - NameStartIndex); int stackSizeStartIndex = NameEndIndex + 2; int stackSizeEndIndex = playerLine.Length - 2; string stack = playerLine.Substring(stackSizeStartIndex, stackSizeEndIndex - stackSizeStartIndex); //string playerName = playerLine.Substring(NameStartIndex, stackSizeStartIndex - NameStartIndex - 2); playerList.Add(new Player(playerName, decimal.Parse(stack, System.Globalization.CultureInfo.InvariantCulture), SeatNumber)); } //... //Player NoahSDsDad has small blind (2) //Player xx45809 sitting out //Player megadouche sitting out //Player xx59704 wait BB CurrentLineIndex++; for (int i = 0; i < handLines.Length; i++) { const int NameStartIndex = 7; string sitOutLine = handLines[CurrentLineIndex + i]; bool receivingCards = false; int NameEndIndex; string playerName; //Uncalled bet (20) returned to zz7 if (sitOutLine[0] == 'U') { break; } switch (sitOutLine[sitOutLine.Length - 1]) { //Player bubblebubble received card: [2h] case ']': //TODO: Parse cards here break; case '.': //Player bubblebubble is timed out. if (sitOutLine[sitOutLine.Length - 2] == 't') { continue; } receivingCards = true; break; case ')': continue; case 'B': //Player bubblebubble wait BB NameEndIndex = sitOutLine.Length - 8;//" wait BB".Length playerName = sitOutLine.Substring(NameStartIndex, NameEndIndex - NameStartIndex); playerList[playerName].IsSittingOut = true; break; case 't': //Player xx45809 sitting out if (sitOutLine[sitOutLine.Length - 2] == 'u') { NameEndIndex = sitOutLine.Length - 12;//" sitting out".Length playerName = sitOutLine.Substring(NameStartIndex, NameEndIndex - NameStartIndex); if (playerName == "")//"Player sitting out" { continue; } playerList[playerName].IsSittingOut = true; break; } //Player TheKunttzz posts (0.25) as a dead bet else continue; default: throw new ArgumentException("Unhandled Line: " + sitOutLine); } if (receivingCards) { break; } } //Expected End //*Player xx59704 shows: Straight to 8 [7s 4h]. Bets: 110.40. Collects: 220.30. Wins: 109.90. //Player Xavier2500 shows: Two pairs. Js and 8s [10h 8c]. Bets: 110.40. Collects: 0. Loses: 110.40. //Game ended at: for (int i = handLines.Length - playerList.Count - 1; i < handLines.Length - 1; i++) { const int WinningStartOffset = 1; const int PlayerMinLength = 7; // = "Player ".Length string summaryLine = handLines[i]; int playerNameStartIndex = PlayerMinLength + (summaryLine[0] == '*' ? WinningStartOffset : 0); int playerNameEndIndex = summaryLine.IndexOf(' ', playerNameStartIndex); int ShowIndex = summaryLine.IndexOf(" shows: "); if (ShowIndex != -1) { string playerName = summaryLine.Substring(playerNameStartIndex, ShowIndex - playerNameStartIndex); int pocketStartIndex = summaryLine.IndexOf('[', playerNameEndIndex) + 1; int pocketEndIndex = summaryLine.IndexOf(']', pocketStartIndex); Player showdownPlayer = playerList[playerName]; if (!showdownPlayer.hasHoleCards) { string cards = summaryLine.Substring(pocketStartIndex, pocketEndIndex - pocketStartIndex); cards = cards.Replace("10", "T"); showdownPlayer.HoleCards = HoleCards.FromCards(cards); } } } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); int lastLineRead = -1; // We start on line index 2 as first 2 lines are table and limit info. for (int lineNumber = 2; lineNumber < handLines.Length - 1; lineNumber++) { string line = handLines[lineNumber]; if (line.StartsWith(@"Seat ") == false) { lastLineRead = lineNumber; break; } // seat info expected in format: // Seat 1: thaiJhonny ($16.08 in chips) int spaceIndex = line.IndexOf(' '); int colonIndex = line.IndexOf(':', spaceIndex + 1); // we need to find the ( before the number. players can have ( in their name so we need to go backwards and skip the last one int openParenIndex = line.LastIndexOf('('); int spaceAfterOpenParen = line.IndexOf(' ', openParenIndex + 2); // add 2 so we skip the $ and first # always int seatNumber = int.Parse(line.Substring(spaceIndex + 1, colonIndex - (spaceIndex + 1) )); string playerName = line.Substring(colonIndex + 2, (openParenIndex - 1) - (colonIndex + 2)); string stackString = line.Substring(openParenIndex + 2, spaceAfterOpenParen - (openParenIndex + 2)); decimal stack = decimal.Parse(stackString, DecimalSeperator); playerList.Add(new Player(playerName, stack, seatNumber)); } if (lastLineRead == -1) { throw new PlayersException(string.Empty, "Didn't break out of the seat reading block."); } // Looking for the showdown info which looks like this //*** SHOW DOWN *** //JokerTKD: shows [2s 3s Ah Kh] (HI: a pair of Sixes) //DOT19: shows [As 8h Ac Kd] (HI: two pair, Aces and Sixes) //DOT19 collected $24.45 from pot //No low hand qualified //*** SUMMARY *** bool inShowdownBlock = false; for (int lineNumber = lastLineRead + 1; lineNumber < handLines.Length - 1; lineNumber++) { string line = handLines[lineNumber]; if (line.StartsWith(@"*** SUM")) { break; } if (line.StartsWith(@"*** SH")) { inShowdownBlock = true; } if (inShowdownBlock == false) { continue; } int firstSquareBracket = line.IndexOf('[', 6); if (firstSquareBracket == -1) { continue; } int lastSquareBracket = line.IndexOf(']', firstSquareBracket + 5); string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); string playerName = line.Substring(0, line.LastIndexLoopsBackward(':', lastSquareBracket)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); int lastLineRead = -1; bool foundSeats = false; // We start on line index 2 as first 2 lines are table and limit info. for (int lineNumber = 2; lineNumber < handLines.Length - 1; lineNumber++) { string line = handLines[lineNumber]; // in tournaments the lines 3 to x can include addons/rebuys, skip these if (!foundSeats && !line.StartsWith("Seat ") && line[6] != ':') { continue; } else if (foundSeats && !line.StartsWith("Seat ")) { lastLineRead = lineNumber; break; } foundSeats = true; char endChar = line[line.Length - 1]; //Seat 1: thaiJhonny ($16.08 in chips) //Seat 1: thaiJhonny ($16.08 in chips) is sitting out if (endChar != ')' && endChar != 't') { lastLineRead = lineNumber; break; } // seat info expected in format: //Seat 1: thaiJhonny ($16.08 in chips) const int seatNumberStartIndex = 4; int spaceIndex = line.IndexOf(' ', seatNumberStartIndex); int colonIndex = line.IndexOf(':', spaceIndex + 1); int seatNumber = FastInt.Parse(line, spaceIndex + 1); // we need to find the ( before the number. players can have ( in their name so we need to go backwards and skip the last one int openParenIndex = line.LastIndexOf('('); //Seat 2: ZamaskaStars (1660 in chips) out of hand (moved from another table into small blind) if (line[openParenIndex + 1] == 'm') { line = line.Remove(openParenIndex); openParenIndex = line.LastIndexOf('('); } int spaceAfterOpenParen = line.IndexOf(' ', openParenIndex); string playerName = line.Substring(colonIndex + 2, (openParenIndex - 1) - (colonIndex + 2)); string stackString = line.Substring(openParenIndex + 1, spaceAfterOpenParen - (openParenIndex + 1)); decimal stack = decimal.Parse(stackString, NumberStyles.AllowCurrencySymbol | NumberStyles.Number, _numberFormatInfo); playerList.Add(new Player(playerName, stack, seatNumber)); } if (lastLineRead == -1) { throw new PlayersException(string.Empty, "Didn't break out of the seat reading block."); } // Looking for the showdown info which looks like this //*** SHOW DOWN *** //JokerTKD: shows [2s 3s Ah Kh] (HI: a pair of Sixes) //DOT19: shows [As 8h Ac Kd] (HI: two pair, Aces and Sixes) //DOT19 collected $24.45 from pot //No low hand qualified //*** SUMMARY *** //or //*** FIRST SHOW DOWN *** int summaryIndex = GetSummaryStartIndex(handLines, lastLineRead); int showDownIndex = GetShowDownStartIndex(handLines, lastLineRead, summaryIndex); //Starting from the bottom to parse faster if (showDownIndex != -1) { for (int lineNumber = showDownIndex + 1; lineNumber < summaryIndex; lineNumber++) { //jimmyhoo: shows [7h 6h] (a full house, Sevens full of Jacks) //EASSA: mucks hand //jimmyhoo collected $562 from pot string line = handLines[lineNumber]; //Skip when player mucks, collects or says sth. //EASSA: mucks hand char lastChar = line[line.Length - 1]; if (lastChar == '*') { break; } if (lastChar == 'd' || lastChar == 't' || lastChar == '"') { continue; } int lastSquareBracket = line.LastIndexLoopsBackward(']', line.Length - 1); if (lastSquareBracket == -1) { continue; } int firstSquareBracket = line.LastIndexOf('[', lastSquareBracket); // can show single cards: // Zaza5573: shows [Qc] if (line[firstSquareBracket + 3] == ']') { continue; } int colonIndex = line.LastIndexOf(':', firstSquareBracket); if (colonIndex == -1) { // players with [ in their name // [PS_UA]Tarik collected $18.57 from pot continue; } string playerName = line.Substring(0, colonIndex); string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } } else { //Check for player shows for (int i = summaryIndex - 1; i > 0; i--) { string line = handLines[i]; if (line.EndsWith(")") && line.Contains(": shows [")) { int nameEndIndex = line.IndexOf(": shows [", StringComparison.Ordinal); string playerName = line.Remove(nameEndIndex); int cardsStartIndex = nameEndIndex + 9; int cardsEndIndex = line.IndexOf(']', cardsStartIndex); string cards = line.Substring(cardsStartIndex, cardsEndIndex - cardsStartIndex); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } else { break; } } } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { var playerList = new PlayerList(); string[] playerLines = GetPlayerLinesFromHandLines(handLines); for (int i = 0; i < playerLines.Length; i++) { string playerName = GetNameFromPlayerLine(playerLines[i]); decimal stack = GetStackFromPlayerLine(playerLines[i]); int seat = GetSeatNumberFromPlayerLine(playerLines[i]); bool sittingOut = GetSittingOutFromPlayerLine(playerLines[i]); playerList.Add(new Player(playerName, stack, seat) { IsSittingOut = sittingOut }); } 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; }
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; }
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; }
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]; //NEW CODE // Seat 1: zamouzar ( 6,001 ) 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); var handLineMatch = Regex.Match(handLine, @"\( (?<currency>\D?)(?<amount>[0-9]+(,[0-9]{3})*(\.[0-9]{2})?) \)"); decimal amount = decimal.Parse(handLineMatch.Groups["amount"].Value, DecimalSeperator); playerList.Add(new Player(playerName, amount, seat)); // 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 = decimal.Parse(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; } } //NEW CODE // Dealt to thanasunn [ As, 6h ] for (int i = 6; i < handLines.Length; i++) { string handLine = handLines[i]; if (handLine.Contains("Dealt to")) { var DealingMatch = Regex.Match(handLine, @"^Dealt to (?<name>.+) \[(?<Dealing>.+)\]"); string Dealing = DealingMatch.Groups["Dealing"].Value; string name = DealingMatch.Groups["name"].Value; Player player = playerList.First(p => p.PlayerName.Equals(name)); player.HoleCards = HoleCards.FromCards(Dealing.Replace(" ", "").Replace(",", "")); break; } } return playerList; }
// Uses a slightly different structure, as it downloads from two sources, and stores its data differently. public static void LoadMyFriendsList(bool forceOffline) { bool offline = forceOffline; DateTime lastAccess = new DateTime(Settings.Instance.FriendsListLastAccess); if (DateTime.Now.Subtract(lastAccess).TotalMinutes < 2) { offline = true; } if (!File.Exists(Path.Combine(CacheLocation, MyFriendsListFilename))) { offline = false; } bool failed = false; string friendsListCache = null; if (!offline) { VersatileIO.Debug("Downloading friends list data for '{0}'...", Settings.Instance.SteamPersonaName); try { friendsListCache = Util.DownloadString(MyFriendsListUrl, Settings.Instance.DownloadTimeout); } catch (WebException) { VersatileIO.Error(" Download failed."); failed = true; } } if (friendsListCache != null) { FriendsListJson listjson; try { listjson = JsonConvert.DeserializeObject<FriendsListJson>(friendsListCache); } catch (Exception e) { VersatileIO.Fatal(" Friends list conversion failed: " + e.Message); throw new RetrievalFailedException(RetrievalType.FriendsList); } if (listjson == null) { VersatileIO.Fatal(" Friends list conversion faile: FriendsListJson converted is null"); throw new RetrievalFailedException(RetrievalType.FriendsList); } List<string> friendids = new List<string>(); foreach (FriendJson f in listjson.friendslist.friends) { friendids.Add(f.steamid); } VersatileIO.Verbose(" Downloading player data for friends..."); try { string url = GetPlayerInfoUrl(friendids); MyFriendsListCache = Util.DownloadString(url, Settings.Instance.DownloadTimeout); } catch (WebException) { VersatileIO.Error(" Download failed."); failed = true; } } if (friendsListCache == null || MyFriendsListCache == null) // offline, load full friends data from cache { VersatileIO.Debug("Retrieving friends list cache..."); try { MyFriendsListCache = File.ReadAllText(Path.Combine(CacheLocation, MyFriendsListFilename), Encoding.UTF8); VersatileIO.Verbose(" Retrieval complete."); } catch (Exception e) { VersatileIO.Fatal(" Friends list retrieval failed: " + e.Message); throw new RetrievalFailedException(RetrievalType.FriendsList); } } VersatileIO.Verbose("Parsing friend info data..."); MyFriendsListRaw = JsonConvert.DeserializeObject<PlayerSummariesJson>(MyFriendsListCache); VersatileIO.Verbose(" Parse complete."); MyFriendsList = new PlayerList(); LoadPlayerInfo(Settings.Instance.HomeSteamID64); foreach (var fj in MyFriendsListRaw.response.players) { Player p = new Player(fj); AllLoadedPlayers.Add(p); MyFriendsList.Add(p); } if (!failed && !offline) { File.WriteAllText(Path.Combine(CacheLocation, MyFriendsListFilename), MyFriendsListCache, Encoding.UTF8); Settings.Instance.FriendsListLastAccess = lastAccess.Ticks; Settings.Instance.Save(); } }
protected override PlayerList ParsePlayers(string[] handLines) { var playerList = new PlayerList(); string[] playerLines = GetPlayerLinesFromHandLines(handLines); for (int i = 0; i < playerLines.Length; i++) { string line = playerLines[i]; string playerName = GetAttribute(line, " alias=\""); decimal stack = decimal.Parse(GetAttribute(line, " balance=\""), provider); int seat = int.Parse(GetAttribute(line, " num=\"")); bool sittingOut = GetSittingOutFromPlayerLine(playerLines[i]); playerList.Add(new Player(playerName, stack, seat) { IsSittingOut = sittingOut }); } 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; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); for (int i = 1; i < 12; i++) { string handLine = handLines[i]; var sittingOut = false; if (handLine.StartsWith("Seat ") == false) { break; } if (handLine.EndsWith(")") == false) { // handline is like Seat 6: ffbigfoot ($0.90), is sitting out handLine = handLine.Substring(0, handLine.Length - 16); sittingOut = true; } //Seat 1: CardBluff ($109.65) int colonIndex = handLine.IndexOf(':', 5); int parenIndex = handLine.IndexOf('(', colonIndex + 2); int seat = Int32.Parse(handLine.Substring(colonIndex - 2, 2)); string name = handLine.Substring(colonIndex + 2, parenIndex - 1 - colonIndex - 2); string stackSizeString = handLine.Substring(parenIndex + 2, handLine.Length - 1 - parenIndex - 2); decimal amount = decimal.Parse(stackSizeString, System.Globalization.CultureInfo.InvariantCulture); playerList.Add(new Player(name, amount, seat) { IsSittingOut = sittingOut }); } // OmahaHiLo has a different way of storing the hands at showdown, so we need to separate bool inCorrectBlock = false; bool isOmahaHiLo = ParseGameType(handLines).Equals(GameType.PotLimitOmahaHiLo); for (int lineNumber = 13; lineNumber < handLines.Length; lineNumber++) { string line = handLines[lineNumber]; if (line.StartsWith(@"*** SUM") && isOmahaHiLo) { lineNumber = lineNumber + 2; inCorrectBlock = true; } else if(line.StartsWith(@"*** SH") && !isOmahaHiLo) { inCorrectBlock = true; } if (inCorrectBlock == false) { continue; } int firstSquareBracket = line.LastIndexOf('['); if (firstSquareBracket == -1) { continue; } // can show single cards if (line[firstSquareBracket + 3] == ']') { continue; } int lastSquareBracket = line.LastIndexLoopsBackward(']', line.Length - 1); int colonIndex = line.LastIndexLoopsBackward(':', lastSquareBracket); string seat; string playerName; if (isOmahaHiLo) { seat = line.Substring(5, colonIndex-5); playerName = playerList.First(p => p.SeatNumber.Equals(Convert.ToInt32(seat))).PlayerName; } else { int playerNameEndIndex = line.IndexOf(" shows", StringComparison.Ordinal); if (playerNameEndIndex == -1) break; playerName = line.Substring(0, playerNameEndIndex); } string cards = line.Substring(firstSquareBracket + 1, lastSquareBracket - (firstSquareBracket + 1)); playerList[playerName].HoleCards = HoleCards.FromCards(cards); } return playerList; }
protected override PlayerList ParsePlayers(string[] handLines) { /* <player seat="3" name="RodriDiaz3" chips="$2.25" dealer="0" win="$0" bet="$0.08" rebuy="0" addon="0" /> <player seat="8" name="Kristi48ru" chips="$6.43" dealer="1" win="$0.23" bet="$0.16" rebuy="0" addon="0" /> */ string[] playerLines = GetPlayerLinesFromHandLines(handLines); PlayerList playerList = new PlayerList(); for (int i = 0; i < playerLines.Length; i++) { string playerName = GetNameFromPlayerLine(playerLines[i]); decimal stack = GetStackFromPlayerLine(playerLines[i]); int seat = GetSeatNumberFromPlayerLine(playerLines[i]); playerList.Add(new Player(playerName, stack, seat) { IsSittingOut = true }); } XDocument xDocument = GetXDocumentFromLines(handLines); List<XElement> actionElements = xDocument.Element("root").Element("session").Element("game").Elements("round").Elements("action"). ToList(); foreach (Player player in playerList) { List<XElement> playerActions = actionElements.Where(action => action.Attribute("player").Value.Equals(player.PlayerName)).ToList(); if (playerActions.Count == 0) { //Players are marked as sitting out by default, we don't need to update continue; } //Sometimes the first and only action for a player is to sit out - we should still treat them as sitting out bool playerSitsOutAsAction = playerActions[0].Attribute("type").Value == "8"; if (playerSitsOutAsAction) { continue; } player.IsSittingOut = false; } /* * Grab known hole cards for players and add them to the player * <cards type="Pocket" player="pepealas5">CA CK</cards> */ string[] cardLines = GetCardLinesFromHandLines(handLines); for (int i = 0; i < cardLines.Length; i++) { string handLine = cardLines[i]; handLine = handLine.TrimStart(); //To make sure we know the exact character location of each card, turn 10s into Ts (these are recognized by our parser) //Had to change this to specific cases so we didn't accidentally change player names handLine = handLine.Replace("10 ", "T "); handLine = handLine.Replace("10<", "T<"); //We only care about Pocket Cards if (handLine[13] != 'P') { continue; } //When players fold, we see a line: <cards type="Pocket" player="pepealas5">X X</cards>, we should skip these lines if (handLine[handLine.Length - 9] == 'X') { continue; } int playerNameStartIndex = 29; int playerNameEndIndex = handLine.IndexOf('"', playerNameStartIndex) - 1; string playerName = handLine.Substring(playerNameStartIndex, playerNameEndIndex - playerNameStartIndex + 1); Player player = playerList.First(p => p.PlayerName.Equals(playerName)); int playerCardsStartIndex = playerNameEndIndex + 3; int playerCardsEndIndex = handLine.Length - 9; string playerCardString = handLine.Substring(playerCardsStartIndex, playerCardsEndIndex - playerCardsStartIndex + 1); string[] cards = playerCardString.Split(' '); foreach (string card in cards) { //Suit and rank are reversed in these strings, so we flip them around before adding player.HoleCards.AddCard(new Card(card[1], card[0])); } } return playerList; }
public FormPoker(string playerName, int BuyInAmount, int playerAmount, int difficulty, UserAccount user) { InitializeComponent(); this.Icon = new Icon("Poker.ico"); this.playerName = playerName; if (playerName == null) throw new ArgumentOutOfRangeException(); if (playerAmount < 2) throw new ArgumentOutOfRangeException(); this.difficulty = difficulty; if (difficulty > 2) throw new ArgumentOutOfRangeException(); this.BuyInAmount = BuyInAmount; this.playerAmount = playerAmount; timerCount = 0; //code to resize screen screenWidth = Screen.PrimaryScreen.Bounds.Width; screenHeight = Screen.PrimaryScreen.Bounds.Height; width_ratio = (screenWidth / 1366f); height_ratio = (screenHeight / 768f); SizeF scale = new SizeF(width_ratio, height_ratio); this.Scale(scale); foreach (Control control in this.Controls) { control.Font = new Font(control.Font.Name, control.Font.SizeInPoints * height_ratio * width_ratio, control.Font.Style); } cardWidth = Convert.ToInt32(71f * width_ratio); cardHeight = Convert.ToInt32(96f * height_ratio); this.user = new UserAccount(user); //add 3 archetytes randomly to list Random rand = new Random(); Player me = new Player(playerName, BuyInAmount); playerList = new PlayerList(); playerList.Add(me); lblName.Text = me.Name; List<int> AI = new List<int>(playerAmount); for (int i = 0; i < 3; i++) { AI.Add(i); } for (int i = 0; i < 4 - playerAmount; i++) { AI.Remove(rand.Next(AI.Count)); } AI = shuffle(AI); for (int i = 1; i < playerAmount; i++) { playerList.Add(new AIPlayer(BuyInAmount, difficulty, AI[i - 1])); //labelListName[i].Text = playerList[i].Name; } FormInformation Information = new FormInformation(playerList); Information.StartPosition = FormStartPosition.CenterScreen; Information.ShowDialog(); Information.Dispose(); pokerTable = new Table(playerList); }
PlayerList QuickSortBestHand(PlayerList myPlayers) { Player pivot; Random ran = new Random(); if (myPlayers.Count() <= 1) return myPlayers; pivot = myPlayers[ran.Next(myPlayers.Count())]; myPlayers.Remove(pivot); var less = new PlayerList(); var greater = new PlayerList(); // Assign values to less or greater list foreach (Player player in myPlayers) { if (HandCombination.getBestHand(new Hand(player.getHand())) > HandCombination.getBestHand(new Hand(pivot.getHand()))) { greater.Add(player); } else if (HandCombination.getBestHand(new Hand(player.getHand())) <= HandCombination.getBestHand(new Hand(pivot.getHand()))) { less.Add(player); } } // Recurse for less and greaterlists var list = new PlayerList(); list.AddRange(QuickSortBestHand(greater)); list.Add(pivot); list.AddRange(QuickSortBestHand(less)); return list; }
protected override PlayerList ParsePlayers(string[] handLines) { PlayerList playerList = new PlayerList(); for (int i = 2; i <= handLines.Length - 1; i++) { string handLine = handLines[i]; if (string.IsNullOrWhiteSpace(handLine) || handLine.StartsWith("Dealer:")) { break; } int firstSpaceIndex = handLine.IndexOf(' '); int openParenIndex = handLine.LastIndexOf('('); string seatInfo = handLine.Substring(openParenIndex + 1, handLine.Length - openParenIndex - 2); string[] seatData = seatInfo.Split(' '); int seatNumber = int.Parse(seatData[seatData.Length - 1]); decimal amount = decimal.Parse(seatData[1], System.Globalization.CultureInfo.InvariantCulture); string playerName = handLine.Substring(0, firstSpaceIndex); playerList.Add(new Player(playerName, amount, seatNumber)); } // Get the hole cards for (int i = handLines.Length - 1; i >= 0; i--) { string handLine = handLines[i]; if (string.IsNullOrWhiteSpace(handLine)) { continue; } if (handLine.StartsWith("Dealer:")) { break; } //IFeelFree shows: Kh - Tc if (handLine.Contains("shows:")) { int colonIndex = handLine.IndexOf(':'); string holeCards = handLine.Substring(colonIndex + 1, handLine.Length - colonIndex - 1); string playerName = handLine.Substring(0, handLine.IndexOf(' ')); Player player = playerList.First(p => p.PlayerName.Equals(playerName)); player.HoleCards = HoleCards.FromCards(holeCards.Replace(" ", "").Replace("-", "")); } //hellowkit didn't show hand (3h - Ad) else if (handLine[handLine.Length - 1] == ')' && handLine.Contains("didn't show hand")) { int openParenIndex = handLine.LastIndexOf('('); string holeCards = handLine.Substring(openParenIndex + 1, handLine.Length - openParenIndex - 2); string playerName = handLine.Substring(0, handLine.IndexOf(' ')); Player player = playerList.First(p => p.PlayerName.Equals(playerName)); 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 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; }