[PYTHON] Calculated the balance of the PokerStars Grand Tour

What is pokerstars

Poker site where you can play online is the largest player in the area. There are also many related support tools.

why?

As mentioned above, there are many support tools, and basically you can leave the balance calculation to the tool. However, the Grand Tour, which I became able to play the other day, didn't seem to be calculated by Holdem Manager 3 (see the photo below). I think it will be added soon. By the way, the current situation is flat like this (I'm sorry it's hard to understand because I participated in another tournament in the meantime). HM3tp.png

code

Click here for github (https://github.com/na-sudo/pokerstarts_analyze)

git clone https://github.com/na-sudo/pokerstarts_analyze.git

Requires numpy. The test environment is python 3.8.5.

I don't know git! Click here for those who say.

grand_tour.py


import os,glob,sys
import json
import numpy as np

user = 'username'
srcdir = [
    'path to hand history1',
    'path to hand history2'
]

def make_pathlist(list_):
    li = []
    for path in list_:
        li += glob.glob(os.path.join(path, '**', '*Varied.txt'), recursive=True)
    return sorted(li)

def getNearestValue(list, num):
    """
    https://qiita.com/icchi_h/items/fc0df3abb02b51f81657
Overview:A function that returns the value closest to a value from the list
    @param list:Data array
    @param num:Target value
    @return The value closest to the target value
    """
    #Calculate the difference between the list element and the target value and get the index of the minimum value
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

user_prize = user + ' wins $'
user_win = user + ' wins the tournament'
user_lose = user + ' finished the tournament'
pathlist = make_pathlist(srcdir)
game = [0]*6
debug = [0]*6
debug_diff = 0
cost = 0
prize = 0
buyin_list = [1, 2, 5, 12, 25, 60]
completed = 0

for path in pathlist:
    with open(path, 'r', encoding='utf-8')as f:
        txt = f.read().split('\n')
    buyin = 100
    for line in txt[2:6]:
        for word in line.split(' ')[::-1]:
            if '$' in word:
                buyin = min(buyin, float(word.replace('$','')))
                break
    buyin = getNearestValue(buyin_list, buyin/0.9)
    index = buyin_list.index(buyin)
    game[index] += 1
    cost += buyin
    for line in txt:
        if user_prize in line:
            prize += float(line.split(' ')[2].replace('$', ''))
        elif user_win in line:
            if buyin!=len(buyin_list):
                cost -= buyin_list[index+1]
            else:
                completed += 1
        elif user_lose in line:
            pass
        else:
            pass

    #print(game, cost, buyin)
#print(game, cost, prize, completed)
print('net prize :', round(prize - cost, 3))

Please copy and use

How to use

Open grand_tour.py with an editor and enter your path in user or srcdir and execute. Since it searches recursively, it is ok if you specify the parent directory.

user = 'username'← My stars ID
srcdir = [
    'path to hand history1',← Location set in the pokerstars app
    'path to hand history2'← If you are using HM3 etc., please delete it if you are not using that path.
]

It seems to be below on the official page. C:\Users\YourUsername\AppData\Local\PokerStars\HandHistory\

The result looks like this

& python grand_tour.py
net prize : 22.54

I'm like a $ 22.54 plus! I usually lose at 5nlz, so the Grand Tour may be delicious!

By the way, if you comment out the 68th line (second line from the bottom), the details will come out.

& python grand_tour.py
[109, 36, 13, 3, 1, 0] 109 131.54 0
net prize : 22.54

[Challenge stage], cost, prize, completed Is printed. cost is the total buy-in, prize is the total prize money, and completed is the number of finishes. The challenged stage has a buy-in of [$ 1, $ 2, $ 5, $ 12, $ 25, $ 60]. I have tried $ 1 109 times, but I haven't tried it yet because $ 60 is 0. I think that even if you try from $ 5, it will calculate properly.

Finally

It's my first time to use Qiita and github, so I'd be happy if you could point out various things!

Reference (used in the code)

Get the closest value to a value from a Python list element (Qiita)

Recommended Posts

Calculated the balance of the PokerStars Grand Tour
The beginning of cif2cell
The meaning of self
the zen of Python
The story of sys.path.append ()
Revenge of the Types: Revenge of types
AtCoder Grand Contest 046: A --Animation drawing of Takahashikun, The Strider