def beidongPut(upCard, handCard): allPossiblePut = pokerUtils.getCanBeatPokers(upCard, handCard) #直接打光手牌 if handCard in allPossiblePut: return handCard if 'L' in handCard and 'B' in handCard: tempHandCard = copy.deepcopy(handCard) tempHandCard = pokerUtils.delPoker(tempHandCard, 'L') tempHandCard = pokerUtils.delPoker(tempHandCard, 'B') if tempHandCard in dataToType.allPokers: return 'LB' sameType = [] bombType = [] #同类型牌压制 upCardType = dataToType.typeDic[upCard][0]['type'] for i in allPossiblePut: if dataToType.typeDic[i][0]['type'] == upCardType: sameType.append(i) if dataToType.typeDic[i][0]['type'] in [9, 10]: #9表示炸弹,10表示王炸 bombType.append(i) #如果不出牌 noPutvalue = getPokerValue(handCard, 1) ## dic = {} maxKey = '' sameType = sorted(sameType, key=lambda x: x[0]) for i in sameType: tempHandCard = copy.deepcopy(handCard) tempHandCard = pokerUtils.delPoker(tempHandCard, i) value = getPokerValue(tempHandCard, 0) if maxKey == '' or dic[maxKey] < value: maxKey = i if i not in dic.keys(): dic[i] = value else: if dic[i] < value: dic[i] = value if maxKey in dic.keys() and dic[maxKey] > (noPutvalue - 5): return maxKey #炸弹王炸压制 dicBomb = {} maxKey = '' bombType = sorted(bombType, key=lambda x: x[0]) for i in bombType: tempHandCard = copy.deepcopy(handCard) tempHandCard = pokerUtils.delPoker(tempHandCard, i) value = getPokerValue(tempHandCard, 0) if maxKey == '' or dicBomb[maxKey] < value: maxKey = i if i not in dicBomb.keys(): dicBomb[i] = value else: if dicBomb[i] < value: dicBomb[i] = value if maxKey in dicBomb.keys() and dicBomb[maxKey] > (noPutvalue - 5): return maxKey #不出 return '0'
def recruimet(allRulePoker, pokerString, startIndex, possibleLst, allPossibleLst, maxType, level): length = len(allRulePoker) if startIndex >= length: return if len(pokerString) == 0: allPossibleLst.append(possibleLst) return for i in range(startIndex, length): currentPokerCount = Counter(pokerString) rulePokerCount = Counter(allRulePoker[i]) isRight = True for key, value in rulePokerCount.items(): if currentPokerCount[key] < value: isRight = False break if isRight == True: tmpPoker = pokerUtils.delPoker(pokerString, allRulePoker[i]) tmpPossibleLst = copy.deepcopy(possibleLst) tmpPossibleLst.append(allRulePoker[i]) recruimet(allRulePoker, tmpPoker, i, tmpPossibleLst, allPossibleLst, maxType, level + 1)
def zhudongPut(handCard): allCards = dataToType.allPokers if handCard in allCards: return handCard if 'L' in handCard and 'B' in handCard: tempHandCard = copy.deepcopy(handCard) tempHandCard = pokerUtils.delPoker(tempHandCard, 'L') tempHandCard = pokerUtils.delPoker(tempHandCard, 'B') if tempHandCard in dataToType.allPokers: return 'LB' possiblePutCard = [] handCardCounter = Counter(handCard) handCardCounterKeys = handCardCounter.keys() for card in allCards: isExist = True tempCounter = Counter(card) for key, value in tempCounter.items(): if key not in handCardCounterKeys or value > handCardCounter[key]: isExist = False break if isExist: possiblePutCard.append(card) TRIO_ONE = [] TRIO_TWO = [] for putcard in possiblePutCard: if dataToType.typeDic[putcard][0]['type'] == COMB_TYPE.TRIO_ONE: TRIO_ONE.append(putcard) elif dataToType.typeDic[putcard][0]['type'] == COMB_TYPE.TRIO_TWO: TRIO_TWO.append(putcard) if len(TRIO_ONE) != 0: dictTrioOne = {} maxKey = '' for tr_one in TRIO_ONE: tempCard = copy.deepcopy(handCard) #print("tempCard --:",tempCard) tempCard = pokerUtils.delPoker(tempCard, tr_one) #print("tempCard --:", tempCard) value = getPokerValue(tempCard, 0) #print("value --:", value) if maxKey == '': maxKey = tr_one dictTrioOne[tr_one] = value elif tr_one in dictTrioOne.keys(): if dictTrioOne[tr_one] < value: dictTrioOne[tr_one] = value else: dictTrioOne[tr_one] = value if dictTrioOne[maxKey] < value: maxKey = tr_one return maxKey if len(TRIO_TWO) != 0: dictTrioTwo = {} maxKey = '' for tr_two in TRIO_TWO: tempCard = copy.deepcopy(handCard) tempCard = pokerUtils.delPoker(tempCard, tr_two) value = getPokerValue(tempCard, 0) if maxKey == '': maxKey = tr_two dictTrioTwo[tr_two] = value elif tr_two in dictTrioTwo.keys(): if dictTrioTwo[tr_two] < value: dictTrioTwo[tr_two] = value else: dictTrioTwo[tr_two] = value if dictTrioTwo[maxKey] < value: maxKey = tr_two return maxKey #出单牌 single = [] for i in possiblePutCard: if len(i) == 1 and handCard.count(i) != 4: single.append(i) single = sorted(single, key=custom_key) if len(single) != 0: return single[0] # 出对牌 pair = [] for i in possiblePutCard: if len(i) == 2 and handCard.count(i) != 4: pair.append(i) pair = sorted(pair, key=custom_key) if len(pair) != 0: return pair[0] # 出单顺 sequence = [] for i in possiblePutCard: if dataToType.typeDic[i]['type'] == COMB_TYPE.SEQUENCE: sequence.append(i) sequence = sorted(sequence, key=custom_key) if len(sequence) != 0: return sequence[0] # 出三牌 TRIO = [] for i in possiblePutCard: if dataToType.typeDic[i]['type'] == COMB_TYPE.TRIO: TRIO.append(i) TRIO = sorted(TRIO, key=custom_key) if len(TRIO) != 0: return TRIO[0] # 出双顺 sequence_two = [] for i in possiblePutCard: if dataToType.typeDic[i]['type'] == COMB_TYPE.SEQUENCE_TWO: sequence_two.append(i) sequence_two = sorted(sequence_two, key=custom_key) if len(sequence_two) != 0: return sequence_two[0] # 出三顺 sequence_TH = [] for i in possiblePutCard: if dataToType.typeDic[i]['type'] == COMB_TYPE.SEQUENCE_THREE: sequence_TH.append(i) sequence_TH = sorted(sequence_TH, key=custom_key) if len(sequence_TH) != 0: return sequence_TH[0] # 出三顺 bomb = [] for i in possiblePutCard: if dataToType.typeDic[i]['type'] == COMB_TYPE.BOMB: bomb.append(i) bomb = sorted(bomb, key=custom_key) if len(bomb) != 0: return bomb[0] return possiblePutCard[0]