コード例 #1
0
 def FreePlay(self, handCards, curRank):
     print("Free play handCards:", handCards)
     handValue, handActions = CountValue().HandCardsValue(
         handCards, 0, curRank)
     #print(handActions)
     #Strategy.SetBeginning(0)
     Strategy.SetRole(handValue, handActions, curRank)
     Strategy.makeReviseValues()
     #print(Strategy.actionValueRevise)
     #print(Strategy.recordPlayerActions)
     bestPlay = {}
     minValue = 100
     for action in handActions:
         actionValue = CountValue().ActionValue(action, action['type'], action['rank'], curRank) - Strategy.freeActionRV[action['type']] \
                       - Strategy.freeActionRV[(action['type'],action['rank'])]
         #print(action, actionValue)
         if actionValue < minValue:
             minValue = actionValue
             bestPlay = action
     #print(Strategy.freeActionRV[('Pair','Q')])
     '''
     maxValue = -100
     actionList = CreateActionList().CreateList(handCards)
     for i in range(0, len(config.cardTypes)):
         type = config.cardTypes[i]
         if (type == 'StraightFlush'): continue
         for rank in actionList[type]:
             for card in actionList[type][rank]:
                 print("Free play trying type, rank, card:", type, rank, card)
                 action = CreateActionList().GetAction(type, rank, card, handCards)
                 restCards = CreateActionList().GetRestCards(action, handCards)
                 #thisHandValue = CountValue().ActionValue(action, type, rank)
                 restValue, restActions = CountValue().HandCardsValue(restCards, 1, curRank)
                 if (restValue > maxValue):
                     maxValue = restValue
                     bestPlay = {"action": action, "type": type, "rank": rank}
                     #print(bestPlay, maxValue)'''
     #print("bestplay:",bestPlay, "handValue", handValue)
     return bestPlay
コード例 #2
0
    def RestrictedPlay(self, handCards, formerAction, curRank):
        print("Restricted Play handCards:", handCards)
        actionList = CreateActionList().CreateList(handCards)

        bestPlay = []
        maxValue, restActions = CountValue().HandCardsValue(
            handCards, 0, curRank)
        Strategy.SetRole(maxValue, restActions, curRank)
        Strategy.makeReviseValues()
        maxValue += Strategy.restrictedActionRV["PASS"]

        #print(maxValue)
        toc = time.time()
        #print(toc - tic)

        for i in range(0, len(config.cardTypes)):
            type = config.cardTypes[i]
            #print(type, formerAction["type"])
            #if (type == 'StraightFlush'): continue
            if (type != 'Bomb' and type != 'StraightFlush'
                    and type != formerAction["type"]):
                continue
            for rank1 in actionList[type]:
                for card in actionList[type][rank1]:
                    color = None
                    rank = rank1  # to distinguish StraightFlush from others
                    if (type == 'StraightFlush'):
                        rank = rank1[1]
                        color = rank1[0]
                    #print("Restricted play trying rank, card:", type, rank, card)
                    if (CompareRank().Larger(type, rank, card, formerAction,
                                             curRank)):
                        action = CreateActionList().GetAction(
                            type, rank, card, handCards, color)
                        restCards = CreateActionList().GetRestCards(
                            action, handCards)
                        restValue, restActions = CountValue().HandCardsValue(
                            restCards, 0, curRank)
                        restValue += Strategy.handRV[type]
                        thisHandValue = CountValue().ActionValue(
                            action, type, rank, curRank)
                        thisHandValue += Strategy.restrictedActionRV[type]
                        if (type, rank) in Strategy.restrictedActionRV.keys():
                            thisHandValue += Strategy.restrictedActionRV[(
                                type, rank)]
                        #print(Strategy.actionValueRevise)
                        #print(rank, card, thisHandValue, restValue)
                        if (thisHandValue < 0): thisHandValue = 0
                        if (thisHandValue + restValue > maxValue or (thisHandValue + restValue == maxValue and \
                        (bestPlay==[] or CompareRank().Smaller(type, rank, card, bestPlay, curRank)))):
                            maxValue = thisHandValue + restValue
                            bestPlay = {
                                "action": action,
                                "type": type,
                                "rank": rank
                            }
                            print(maxValue, bestPlay)

        if (bestPlay == []):
            bestPlay = {'action': 'PASS', 'type': 'PASS', 'rank': 'PASS'}
        #print("bestplay:", bestPlay, "maxvalue", maxValue)
        return bestPlay