Advertisement
Guest User

Untitled

a guest
Nov 14th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import random
  2.  
  3. colors = ['R', 'U', 'W', 'G']
  4.  
  5. # 35 avg turns
  6. crystalPicks = ['G']*5
  7. cardPicks = ['W']*5
  8.  
  9. # 32 avg turns
  10. #crystalPicks = ['R']*5
  11. #cardPicks = ['R']*5
  12.  
  13. turns = 0
  14. roundTurns = [0]*6
  15. trials = 10000
  16. for test in range(0, trials):
  17.     cards = []
  18.     for l in colors:
  19.         cards.extend([l]*4)
  20.     random.shuffle(cards)
  21.     crystals = ['R', 'R', 'U']
  22.  
  23.     newCrystals = []
  24.     newCards = []
  25.  
  26.     newCrystals.extend(crystalPicks)
  27.     newCards.extend(cardPicks)     
  28.     # fill in rest randomly
  29.     for i in range(len(newCrystals),5):
  30.         newCrystals.append(random.choice(colors))
  31.     for i in range(len(newCards),5):
  32.         newCards.append(random.choice(colors))
  33.        
  34.     discard = []
  35.  
  36.     for round in range(0, 6):
  37.  
  38.         while len(cards):
  39.             roundTurns[round] += 1
  40.             turns += 1
  41.             c = None
  42.            
  43.             # draw 3
  44.             for i in range(0,3):
  45.                 if not len(cards):
  46.                     break
  47.                 c = cards.pop()
  48.                 discard.append(c)
  49.                
  50.             # draw more if color matches
  51.             for cry in crystals:
  52.                 if c and c == cry and len(cards):
  53.                     discard.append(cards.pop())
  54.         turns += 1 # player's last turn
  55.         roundTurns[round] += 1
  56.        
  57.         if round == 5: # last round
  58.             break
  59.        
  60.         # give dummy a card&crystal and shuffle
  61.         crystals.append(newCrystals.pop(0))
  62.         discard.append(newCards.pop(0))
  63.         cards = discard
  64.         random.shuffle(cards)
  65.         discard = []
  66.  
  67. print turns/float(trials), 'avg turns per game'
  68. for r in range(0,6):
  69.     print r, roundTurns[r]/float(trials)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement