Пример #1
0
    def analyzeStat(self, listHand, objStat):

        for oneLine in listHand:
            if oneLine.find(C.deposit) != -1 and oneLine.find(C.me) != -1:
                stack = U.search(r'\$[0-9\.]+', oneLine).strip('$')
                #print(stack)
                objStat.stack -= U.strToNum(stack)
        pass
Пример #2
0
    def getPayout(self, pos):
        m = 0
        for k in self.dictAction:
            for k2, v2 in self.dictAction[k][pos]:
                if C.handresult == k2 or C.uncall == k2:
                    m += U.strToNum(v2)
                else:
                    m -= U.strToNum(v2)

        return m
Пример #3
0
 def getPreflop(self):
     listRes = []
     listRes.append(C.preflop)
     listRes.append('Dealt to ' + self.dictName[self.pos] + ' ' +
                    self.getCard(self.dictCard[self.pos]))
     listRes.append(self.getStreet(C.preflop))
     return U.ret(listRes)
Пример #4
0
    def getStreet(self, strStreet):
        listRes = []
        idx = 2 if strStreet == C.preflop else 0
        rounds = 0
        for i in self.dictAction[strStreet]:
            rounds = max(rounds, len(self.dictAction[strStreet][i]))

        #print(rounds)
        # todo raise val
        for i in list(range(0, rounds)):
            for j in list(range(idx, len(C.pairPos))):
                (k, pos) = C.pairPos[j]
                if i < len(self.dictAction[strStreet][pos]):
                    (act, val) = self.dictAction[strStreet][pos][i]
                    val = self.getChip(val) if len(val) > 0 else ''
                    name = self.dictName[pos]
                    strRes = name + ': ' + act.lower() + ' ' + val
                    if C.raises == act:
                        strRes += ' to ' + val
                    listRes.append(strRes)

            # next round
            idx = 0

        return U.ret(listRes)
Пример #5
0
    def getShowdown(self):
        listRes = []
        bolHasSd = False

        rounds = 0
        for (k, pos) in C.pairPos:
            rounds = max(rounds, len(self.dictAction[C.showdown][pos]))
        #print(rounds)

        for i in list(range(0, rounds)):
            for (k, pos) in C.pairPos:
                if i < len(self.dictAction[C.showdown][pos]):
                    (act, val) = self.dictAction[C.showdown][pos][i]

                    if C.sd == act:
                        if not bolHasSd:
                            listRes.append(C.showdown)
                            bolHasSd = True
                        listRes.append(self.dictName[pos] + ': shows ' +
                                       self.getCard(self.dictCard[pos]))

                    elif C.nsd == act:
                        listRes.append('Uncalled bet (' + self.getChip(0) +
                                       ') returned to ' + self.dictName[pos])

                    elif C.handresult == act:
                        listRes.append(self.dictName[pos] + ' collected ' +
                                       self.getChip(val) + ' from pot')
                        if not bolHasSd:
                            listRes.append(self.dictName[pos] +
                                           ': doesn\'t show hand')

        return U.ret(listRes)
Пример #6
0
    def getTable(self):
        '''
        if not C.co in self.dictSeat or not C.co in self.dictName or not C.co in self.dictStack:
            print(self.handId)
            return []
        '''

        listRes = []
        listRes.append(self.lobby + ' Hand #' + self.handId + ': ' +
                       self.game + ' (' + self.getChip(self.sb) + '/' +
                       self.getChip(self.bb) + ' USD) - ' +
                       str.replace(self.date, '-', '/') + ' ET')
        listRes.append('Table ' + '\'' + self.table + '\'' + ' ' +
                       str(len(self.dictSeat)) + '-max Seat #' +
                       self.dictSeat[C.btn] + ' is the button')

        listTmp = sorted(self.dictSeat.items(), key=lambda x: x[1])
        #print(self.dictStack)
        #print(self.dictName)
        for (pos, seat) in listTmp:
            listRes.append(C.seat + seat + ': ' + self.dictName[pos] + ' (' +
                           self.getChip(self.dictStack[pos]) + ' in chips)')

        listRes.append(self.dictName[C.sb] + ': posts small blind ' +
                       self.getChip(self.sb))
        listRes.append(self.dictName[C.bb] + ': posts big blind ' +
                       self.getChip(self.bb))

        return U.ret(listRes)
Пример #7
0
 def __init__(self, state_dict, save_path, template_file) -> None:
     """
     :param state_dict: 错误码的字典
     :param save_path: 存储的文件路径
     :param template_file: 模板文件的路径
     """
     transform = eval(Util.get_transform_config())
     self._transform_config = transform if isinstance(transform,
                                                      dict) else {}
     append = eval(Util.get_append_config())
     append_config = append if isinstance(append, dict) else {}
     if len(append_config):
         state_dict["other"] = append_config
     self._state_dict = state_dict
     self._path = save_path
     self._template_file_content = Util.parse_template_content_from_path(
         template_file)
     Util.mkdir(path=self._path)
     super().__init__()
Пример #8
0
 def make_file(self,
               root_name=FileMaker._root_name,
               enum_name=FileMaker._root_name,
               state_dict=None):
     Util.rm_file("%s/%s" % (self._path, self.file_name("")))
     template_file_content = self._template_file_content
     # 枚举的头部
     re_header_rule = r"%s(.*)%s" % (FileMaker._root_header_start,
                                     FileMaker._root_header_end)
     h = Util.re_search(re_header_rule, template_file_content)
     header = ""
     if h:
         self._template_file_content = template_file_content.replace(
             h.group(0), "")
         header = h.group(1).strip()
     super().make_file(root_name, enum_name, state_dict)
     with open("%s/%s" % (self._path, self.file_name("")), "r+") as f:
         old = f.read()
         f.seek(0)
         f.write("%s%s" % (header, old))
Пример #9
0
    def getSummary(self):
        #print(self.dictStack)

        listRes = []
        listRes.append(C.summary)
        listRes.append('Total pot ' +
                       self.getChip(self.dictStack[C.showdown]) + ' | Rake ' +
                       self.getChip(self.getRake()))
        for (k, v) in reversed(C.pairStreet):
            if len(self.dictCard[v]) != 0:
                listRes.append('Board ' + self.getCard(self.dictCard[v]))
                break

        listTmp = sorted(self.dictSeat.items(), key=lambda x: x[1])
        for (pos, seat) in listTmp:
            strRes = C.seat + seat + ': ' + self.dictName[pos] + ' '
            if pos == C.sb:
                strRes += '(small blind)' + ' '
            elif pos == C.bb:
                strRes += '(big blind)' + ' '
            elif pos == C.btn:
                strRes += '(button)' + ' '

            if U.ret(self.dictAction[C.preflop][pos]).find(C.fold) != -1:
                strRes += 'folded before Flop (didn\'t bet)' + ' ' + self.getCard(
                    self.dictCard[pos])
            elif U.ret(self.dictAction[C.flop][pos]).find(C.fold) != -1:
                strRes += 'folded on the Flop' + ' ' + self.getCard(
                    self.dictCard[pos])
            elif U.ret(self.dictAction[C.turn][pos]).find(C.fold) != -1:
                strRes += 'folded on the Turn' + ' ' + self.getCard(
                    self.dictCard[pos])
            elif U.ret(self.dictAction[C.river][pos]).find(C.fold) != -1:
                strRes += 'folded on the River' + ' ' + self.getCard(
                    self.dictCard[pos])
            else:
                strRes += 'showed' + ' ' + self.getCard(self.dictCard[pos])

            listRes.append(strRes)

        return U.ret(listRes)
Пример #10
0
 def _make_sub_file(self, sub_state_dict, file_name, enum_name):
     """
     :param sub_state_dict: 错误码的字典
     :param file_name: 存储的文件名
     :param enum_name: 存储文件中的的枚举名
     :return:
     """
     enum_name = self.state_enum_name(enum_name)
     file_path = self._path
     enum_content = ""
     # 枚举的名字
     template_file_content = self._template_file_content.replace(
         self._root_template, enum_name)
     # 枚举的头部
     re_header_rule = r"%s.*%s" % (FileMaker._root_header_start,
                                   FileMaker._root_header_end)
     h = Util.re_search(re_header_rule, template_file_content)
     if h:
         self._template_file_content = template_file_content \
             .replace(FileMaker._root_header_start, "") \
             .replace(FileMaker._root_header_end, "")
     # 枚举的内容体
     re_content_rule = r"%s(.*)%s" % (FileMaker._root_content_start,
                                      FileMaker._root_content_end)
     c = Util.re_search(re_content_rule, template_file_content)
     if c:
         for (k, v) in sub_state_dict.items():
             transform = self._transform_config.get(v)
             if transform:
                 k = transform
             content = c.group(1) \
                 .replace(FileMaker._root_key, self.state_key_name(k)) \
                 .replace(FileMaker._root_value, "%d" % v) \
                 .replace("\n", "", -1)
             enum_content = "%s%s\n" % (enum_content, content)
     template_file_content = Util.re_sub(re_content_rule, enum_content,
                                         template_file_content)
     self._write_to_file(template_file_content,
                         "%s/%s" % (file_path, file_name), "w")
Пример #11
0
def filter(objHand):

    numPfr = 0
    for pos in objHand.dictAction[C.preflop]:
        for act, val in objHand.dictAction[C.preflop][pos]:
            #print(act)
            if act == C.raises or act == C.allin:
                numPfr += 1

    if numPfr >= 2 and U.strToNum(objHand.bb) == 0.5 and not (
            C.fold, '') in objHand.dictAction[C.preflop][objHand.pos]:
        return True

    return False
Пример #12
0
    def read(self, strFile):
        listOut = []
        listOneHand = []
        oneStat = Stat()

        with open(strFile, 'r') as fp:
            for lineNum, strLine in enumerate(fp, 1):
                strLine = strLine.strip()
                #print(strLine)
                if not len(strLine):
                    if len(listOneHand) > 0:
                        oneHand = Hand()
                        r = self.analyzeHand(listOneHand, oneHand)
                        if False == r:
                            #print(lineNum)
                            #print(strFile)
                            return False
                        listOut.append(oneHand)

                        self.analyzeStat(listOneHand, oneStat)

                        # clean for next read
                        listOneHand = []
                else:
                    listOneHand.append(strLine)

        # first hand and last hand hero's stack ,and hand result
        handSt = listOut[0]
        handEd = listOut[-1]
        oneStat.stack += U.strToNum(handEd.dictStack[handEd.pos]) - U.strToNum(
            handSt.dictStack[handSt.pos])
        oneStat.stack += handEd.getPayout(handEd.pos)

        #print(U.strToNum(oneStat.stack))
        #print(listOneHand)
        return {'hand': listOut, 'stat': oneStat}
Пример #13
0
import sys
sys.path.append('/Users/qinmengyao/PythonProjects/python3/git_bodog/')
from main.util import Util as U

dictCmp = {}
for i in range(2, 9):
    dictCmp[i] = i
print(dictCmp)

l = []
l.append(['Ac', 'Kc'])
l.append(['Ac', 'Kh'])
l.append(['Ac', 'As'])
l.append(['8c', '8s'])
l.append(['Tc', 'Ts'])
l.append(['Qc', 'Qs'])
l.append(['5c', '6s'])
l.append(['5s', '6s'])
l.append(['3s', 'As'])
l.append(['2s', 'As'])
l.append(['9s', 'Ks'])
l.append(['Ts', 'Kh'])

for i in l:
    print(U.classifyHand(i))
Пример #14
0
 def state_key_name(self, key_name):
     return Util.text_first_letter_lower(key_name)
Пример #15
0
 def state_enum_name(self, enum_name):
     return Util.text_first_letter_lower(enum_name)
Пример #16
0
 def getRiver(self):
     strRes = self.getStreet(C.river)
     return U.ret([
         C.river + ' ' + self.getCard(self.dictCard[C.river], True), strRes
     ]) if len(strRes) > 0 else ''
Пример #17
0
    def analyzeHand(self, listHand, objHand):

        arrTable = re.split(r'\s+', listHand[0])
        if len(arrTable) < 10:
            return False  #test
            #print(listHand)
            #print(arrTable)
        objHand.lobby = C.ps
        objHand.handId = arrTable[2].strip('#')
        objHand.date = arrTable[8] + ' ' + arrTable[9]
        objHand.game = C.nlh
        objHand.table = C.table

        #print(arrTable)

        curStreet = ''
        curStack = 0.0
        curAct = ''

        for oneLine in listHand:

            # todo analyze 9-max pos
            # read seat
            if oneLine.find(C.seat) != -1 and oneLine.find('$') != -1:
                #print(oneLine)
                stack = U.search(r'\$[0-9\.]+', oneLine).strip('$')

                arr = re.split(r'\s+', oneLine)
                name = arr[2]
                pos = arr[2]

                # todo rm 6-max param filter
                if not (pos, pos) in C.pairPos:
                    return False

                if oneLine.find(C.me) != -1:
                    name += '.' + C.hero
                    objHand.pos = pos

                seat = arr[1].strip(':')

                objHand.dictName[pos] = name
                objHand.dictStack[pos] = stack
                objHand.dictSeat[pos] = seat

            # read hand
            elif oneLine.find(C.dealt) != -1:
                objHand.dictCard[re.split(r'\s+', oneLine)[0]] = self.readCard(
                    U.search(r'\[[2-9TJQKAdchs ]*\]', oneLine))

            # read showdown
            elif oneLine.find(C.sd) != -1:
                pos = re.split(r'\s+', oneLine)[0]
                objHand.dictAction[C.showdown][pos].append((C.sd, 0))
            elif oneLine.find(C.nsd) != -1:
                pos = re.split(r'\s+', oneLine)[0]
                objHand.dictAction[C.showdown][pos].append((C.nsd, 0))
            elif oneLine.find(C.handresult) != -1:
                pos = re.split(r'\s+', oneLine)[0]
                val = U.search(r'\$[0-9\.]+', oneLine).strip('$')
                objHand.dictAction[C.showdown][pos].append((C.handresult, val))
            elif oneLine.find(C.uncall) != -1:
                pos = re.split(r'\s+', oneLine)[0]
                val = U.search(r'\$[0-9\.]+', oneLine).strip('$')
                objHand.dictAction[C.showdown][pos].append((C.uncall, val))
            elif oneLine.find(C.posts) != -1:
                pos = re.split(r'\s+', oneLine)[0]
                val = U.search(r'\$[0-9\.]+', oneLine).strip('$')
                objHand.dictAction[C.showdown][pos].append((C.posts, val))

            else:
                # read sb/bb
                for (k, v) in C.pairBlind:
                    if oneLine.lower().count(k) == 2 or (oneLine.find(
                            C.btn) != -1 and oneLine.lower().find(k) != -1):
                        #print(oneLine)
                        val = U.search(r'[0-9\.]+', oneLine)
                        setattr(objHand, v, val)

                        pos = getattr(C, v)
                        if (oneLine.find(C.btn) != -1
                                and oneLine.lower().find(k) != -1):
                            pos = C.btn
                        objHand.dictAction[C.preflop][pos].append((C.bet, val))
                        curStack = round(curStack + float(val), 2)
                        #print(curStack)

                # read board
                for (k, v) in C.pairStreet:
                    if oneLine.find(k) != -1:
                        curStreet = v
                        objHand.dictCard[v] = self.readCard(
                            U.search(r'\[.*\]', oneLine))
                        objHand.dictStack[v] = curStack

                # read action
                for (k, v) in C.pairAction:
                    if oneLine.find(k) != -1:
                        val = U.search(r'\$[0-9\.]+', oneLine).strip('$')
                        if not val:
                            val = '0'
                        if v == C.bet or v == C.raises or v == C.call or v == C.allin:
                            curStack = U.strToNum(curStack) + U.strToNum(val)
                        objHand.dictAction[curStreet][re.split(
                            r'\s+', oneLine)[0]].append((v, val))

        # set total pot
        objHand.dictStack[C.showdown] = curStack

        #print(curStack)
        #print(objHand.dictAction)
        #print(objHand.dictCard)
        #print(objHand.dictStack)

        pass
Пример #18
0
 def getCard(self, listCard, bolDivide=False):
     if bolDivide:
         return '[' + U.ret(listCard[:-1],
                            ' ') + ']' + ' [' + listCard[-1:][0] + ']'
     else:
         return '[' + U.ret(listCard, ' ') + ']'
Пример #19
0
 def getFlop(self):
     strRes = self.getStreet(C.flop)
     return U.ret([
         C.flop + ' ' + self.getCard(self.dictCard[C.flop]), strRes
     ]) if len(strRes) > 0 else ''
Пример #20
0
 def state_key_name(self, key_name):
     return Util.text_underline_mode(key_name)
Пример #21
0
 def getTurn(self):
     strRes = self.getStreet(C.turn)
     return U.ret([
         C.turn + ' ' + self.getCard(self.dictCard[C.turn], True), strRes
     ]) if len(strRes) > 0 else ''
Пример #22
0
"""
Created on Sun Oct 25 12:18:04 2015

@author: akhilmandala

Install language detection library : pip install langid
"""

import langid

from main.afinn import Afinn
from main.ssc import Ssc
from main.util import Util

if __name__ == '__main__':
    util = Util()

    user_text = util.get_input()
    all_words = util.get_tokens(user_text)
    lc_words = map(str.lower, all_words)
    filtered_words = util.filter_alnum(lc_words)

    print "Number of words: %s" % len(filtered_words)

    freq = util.get_word_frequencies(filtered_words)

    print "Count of unique words: %s" % len(freq)
    print "Word frequencies:"
    for k, v in freq.iteritems():
        print k, v
Пример #23
0
def cli():

    strDir = os.path.abspath('.') + '/input/'
    listAccount = os.listdir(strDir)
    #print(listAccount)
    cntDone = 0

    objWriter = Writer()
    objWriter.clean()

    objReader = Reader()

    objCvtor = Convertor()

    for oneAccount in listAccount:
        for oneFile in os.listdir(strDir + '/' + oneAccount):
            strFile = strDir + '/' + oneAccount + '/' + oneFile
            #print(strFile)
            '''
            if '/Users/qinmengyao/PythonProjects/python3/git_bodog/input//2248820/HH20170103-191742 - 4994888 - RING - $0.10-$0.25 - HOLDEM - NL - TBL No.11256624.txt' != strFile:
                continue
            '''
            outRead = objReader.read(strFile)
            #print(outRead)
            if False == outRead:
                continue

            listHand = outRead['hand']
            one = listHand[3]

            stat = outRead['stat']
            #print(one.dictAction)
            #print(one.pos)
            #break

            sum = 0
            idx = 0

            for one in listHand:
                tmp = (round(one.getPayout(one.pos), 2))
                l = []
                l.append(one.dictStack[one.pos])
                l.append(tmp)

                l.append(one.pos)

                for k, v in C.pairStreet:
                    #print( one.dictAction[k][one.pos])
                    pass
                sum += tmp
                l.append(U.getChip(sum))
                #print(U.ret(l, ' '))

            print(U.getChip(sum))
            print(U.getChip(stat.stack))

            #print(listHand[0].getPayout(listHand[0].pos))
            #print(one.pos)

            #print(U.getChip(stat.stack))
            #break
        break