Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.84 KB | None | 0 0
  1. # PETE ROOLZ
  2. #
  3. # you can get a quick sequence out with
  4. # python -c 'import tgm; r = tgm.TiRandomizer(); print "".join([r.next() for i in range(70)])'
  5. #
  6. # sample 1000-piece sequence:
  7. #
  8. # jlosiztjsozlijsotilsjtzoijtzlojsiztoljstiltzosjtzoiljzoslitjslizjsotlziosjlztsj
  9. # itlojztisozlitosjlizojtlzsotjislotjzlitsjoziljsoztlijsotilzstojzziiljsztljiotsj
  10. # iolszjotszjiloztisojlsztoiszljitzosltjijzosilzjtioszltjisotjilzostlzjoistjzilos
  11. # jtliozstjolstziljlsotslzjisozjitoilstzolitzjsioljztoljsztoisjltiszloijztolszito
  12. # jzilsjztisjltozsijoltzsoijlztijsotliszjloitzjoltsizjlsioojtzsloijszoitjzsltoijz
  13. # ltisoltjzsilitosjizoltjzosltjoisztljsitlzjosiltozijltosiztjsilojztlsjiozstjizsl
  14. # oitjslotzjliozjstlziosljtoszijtlziojlzstilozjstiljsziojtsloitzsosizjtolzjsoizjt
  15. # sliotzjlstiolstzojloizjtsiljzsoijzstoljsitzoslijoztsijoztllsitzlosjzijtlsojtilz
  16. # osijtzlsotzisojtilozjtisllozsjlotijsolztijlsozjtsizjositljsztijlzoitsjozltjsilo
  17. # zjstiolzstjlosiztlojlsitzosjizltojsilzjsilztsoijozltjsolzitsljioszjitolzsitljsz
  18. # toljsitzolijszotjlsizjoltisojtzslztislzoiojztilsjtolsjztiosljziotjzisotzisjtlzs
  19. # oiljtzoijtszloostijoslzitjoolszijosztloijtsziljositjzsltjoilzzositzosjtzoijlzsi
  20. # tlojstzliotslzjozisltjisztljizotjisolzjistljoisltozo
  21.  
  22.  
  23. import random
  24. import collections
  25.  
  26. # On a Ti randomizer bug:
  27. #
  28. # > When these 3 conditions are met:
  29. # >
  30. # >     1. The randomizer has just chosen the most droughted piece
  31. # >     2. A reroll happened during the choice of that piece.
  32. # >     3. Excluding the first piece of the game, and including this chosen piece, you have received at least one of each of the 7 piece types.
  33. # >
  34. # > Then the roll that chose that most droughted piece will not update the bag of 35 pieces.
  35. #
  36. # -- colour_thief, http://tetrisconcept.net/threads/randomizer-theory.512/page-7
  37.  
  38. def TiRandomizer():
  39.     bag = ['j', 'i', 'z', 'l', 'o', 't', 's'] * 5
  40.     history = collections.deque(['s', 'z', 's', 'z'])
  41.     drought_order = ['j', 'i', 'z', 'l', 'o', 't', 's']
  42.     count = { 'j' : 0, 'i' : 0, 'z' : 0, 'l' : 0, 'o' : 0, 't' : 0, 's' : 0 }
  43.     n = 1
  44.  
  45.     # first piece is special
  46.     first = random.choice(['j','i','l','t'])
  47.     history.popleft()
  48.     history.append(first)
  49.     yield first
  50.  
  51.     while True:
  52.         for roll in range(6):
  53.             i = random.randint(0, 34)
  54.             piece = bag[i]
  55.             if piece not in history:
  56.                 break
  57.             if roll < 5:
  58.                 bag[i] = drought_order[0]
  59.         count[piece] += 1
  60.         emulate_bug = all ([
  61.             piece == drought_order[0],
  62.             roll > 0,
  63.             0 not in count.values()
  64.             ])
  65.         if not emulate_bug:
  66.             bag[i] = drought_order[0]
  67.         drought_order.remove(piece)
  68.         drought_order.append(piece)
  69.         history.popleft()
  70.         history.append(piece)
  71.         yield piece
  72.  
  73. if __name__ == '__main__':
  74.     r = TiRandomizer()
  75.     print "".join([r.next() for i in range(70)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement