Example #1
0
def caculcateWinRateBy(deck, players, totalNum=2500, toDealNum=None):
    showList = deck.showList.copy()
    cardList = deck.inDeck.copy()
    winNum = [0 for i in players]

    totalResult = []

    if toDealNum != None:
        totalResult = _generateRandomGroupResult(cardList, totalNum, toDealNum)
    elif len(showList) >= 3:
        totalResult = _generateProbabilityGroupResult(cardList)
    else:
        dealNum = 5 - len(showList)
        totalResult = _generateRandomGroupResult(cardList, totalNum, dealNum)

    for cards in totalResult:
        cards.extend(showList)
        pv = [0 for i in players]
        for index, player in enumerate(players):
            temp = SevenCard.fromHands(cards, player.hands)
            temp.caculateAll()
            if temp.value > pv[index]:
                pv[index] = temp.value

        m = max(pv)
        for index, val in enumerate(pv):
            if val == m:
                winNum[index] += 1

    totalPv = 0
    for index, num in enumerate(winNum):
        totalPv += num
    for index, num in enumerate(winNum):
        players[index].winRate = num / totalPv
    return winNum
Example #2
0
 def generateFakeResultList(self, dealToNum=5):
     valueMap = []
     showList = self.deck.showList
     toDeal = dealToNum - len(showList)
     fakeDealList = random.sample(self.deck.inDeck, toDeal)
     for hands in self.handsList:
         sev = SevenCard.fromHands(hands, fakeDealList)
         sev.caculateAll()
         valueMap.append(sev)
     return valueMap
Example #3
0
 def generateWinNum(self, totalNum, toDealNum=5):
     winNum = [0 for i in self.handsList]
     for n in range(0, totalNum):
         showList = random.sample(self.inDeck, toDealNum)
         pv = [0 for i in self.handsList]
         for index, hands in enumerate(self.handsList):
             temp = SevenCard.fromHands(hands,
                                        showList=showList).caculateAll()
             if temp.value > pv[index]:
                 pv[index] = temp.value
         m = max(pv)
         for index, val in enumerate(pv):
             if val == m:
                 winNum[index] += 1
     return winNum
Example #4
0
 def generateFakeResultMap(self, dealToNum=5):
     valueMap = {}
     showList = self.deck.showList
     toDeal = dealToNum - len(showList)
     fakeDealList = random.sample(self.deck.inDeck, toDeal)
     mvalue = 0
     for hands in self.handsList:
         sev = SevenCard.fromHands(hands, fakeDealList)
         sev.caculateAll()
         valueMap[hands] = sev
         if sev.value > mvalue:
             mvalue = sev.value
     for hands in self.handsList:
         if valueMap[hands].value == mvalue:
             valueMap[hands].win = True
     return valueMap
Example #5
0
 def makePlayersHandsValue(self):
     for p in self.livingPlayers:
         seven = SevenCard.fromCardArray(self.deck.showList, p.hands)
         seven.caculateAll()
         p.handsValue = seven.value
Example #6
0
 def generateResultForRandomNumber(self, randomNum):
     for toDealNum in [3, 4, 5]:
         self.showList = random.sample(self.inDeck, toDealNum)
         for index, hands in enumerate(self.handsList):
             temp = SevenCard.fromHands(hands, self.showList).caculateAll()
             self.handsValues[hands].append(temp.value)