1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| #-*-coding:utf-8-*- # @Author: suhang1596
import sys import cmd import random
def find(grade,playerList,layerNumber): for i in playerList: if( int( ( i - 1 ) / 2 ) == grade ): grade = i if grade >= pow( 2 , layerNumber ) - 1: return 1 else: find( grade , playerList , layerNumber )
def creatCard(layerNumber,cardList): x = 1 for layer in range( layerNumber ): for node in range( pow( 2 , layer + 1) ): for samenode in range( pow( 2 , layerNumber - layer - 1 ) ): cardList.append( x ) cardList.append( x ) x = x + 1
def test(playerNumber,layerNumber,hd): random.shuffle(card[layerNumber]) player = [] for i in range( playerNumber ): player.append(card[layerNumber][hd*i:int(hd*(progress+i))]) player[i].sort()
for j in range( playerNumber ): mark = 0 if ( player[j][0] == 1 ) | ( player[j][0] == 2 ): for y in range( 1 , 3 ): if (( find( y , player[j] , layerNumber ) == 1 )) : mark += 1 if mark > 0: mainSuccessCount[layerNumber][playerNumber] += 1 else: mainFailCount[layerNumber][playerNumber] += 1 else: mainFailCount[layerNumber][playerNumber] += 1
if __name__ == '__main__':
testTimes = 500 rate = 1.0 progress = 0.625 beginHandcard = 4 roundHandcard = 1 testLayerFrom=4 testLayerTo=5 testPlayerFrom=3 testPlayerTo=9
print (u'您的设定是玩到%.2f%%的进度,' % (progress*100)), print (u'起始%2d张牌,每回合抽取%2d张牌!\n' % (beginHandcard,roundHandcard))
card = [] mainSuccessCount = [] mainFailCount = [] handcardNumber = [] for c in range(0,10): card.append([]) handcardNumber.append([]) mainSuccessCount.append([]) mainFailCount.append([]) for m in range(0,10): mainSuccessCount[c].append(0) mainFailCount[c].append(0)
for cardNumber in range(testLayerFrom,testLayerTo): creatCard(cardNumber,card[cardNumber]) print (u'目前的牌组设定下,%d个等级、%4d张牌,' % (cardNumber,len(card[cardNumber]),)), print (u'玩到%.2f%%的进度有%4d张牌' % (progress,len(card[cardNumber])*progress))
for i in range(testTimes): for testLayer in range(testLayerFrom,testLayerTo): for testPlayer in range(testPlayerFrom,testPlayerTo): handcardNumber[testLayer] = len(card[testLayer]) / testPlayer test(testPlayer,testLayer,handcardNumber[testLayer])
print (u'\n经过%d次测试,\n' % (testTimes)) for testLayer in range(testLayerFrom,testLayerTo): for testPlayer in range(testPlayerFrom,testPlayerTo): x = float(mainSuccessCount[testLayer][testPlayer]) y = float(mainFailCount[testLayer][testPlayer]) rate = x / ( x + y ) print (u'在%2d个人中进化成功率%.2f%%,' % (testPlayer,rate*100)), print (u'即成功了%2d个人' % (int(rate*testPlayer))), hui = ( len(card[testLayer]) * progress - beginHandcard * testPlayer ) / roundHandcard quan = hui/testPlayer print (u'需要轮%2d圈%3d个回合' % (quan,hui)) print ('\n')
|