Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from sys import stdout
- from random import randint, choice
- from statistics import median
- def next_1roll(last_piece):
- index = randint(0, len(tet)-1)
- return tet[index]
- def next_reroll(last_piece):
- index = randint(0, len(tet)-1)
- next_piece = tet[index]
- if next_piece == last_piece:
- index = randint(0,len(tet)-1)
- next_piece = tet[index]
- return next_piece
- # https://github.com/babeheim/tetristools/blob/master/R/rtetris.R
- tet = ["T", "J", "Z", "O", "S", "L", "I"]
- rev = dict((tet[n], n) for n in range(len(tet)))
- orientationID = [2, 7, 8, 10, 11, 14, 18] # numeric address for each piece
- def next_nes(last_piece):
- lastID = orientationID[rev[last_piece]]
- index = randint(0, len(tet))
- if index > 0:
- next_piece = tet[index-1]
- if index == 0 or next_piece == last_piece:
- index = randint(0,len(tet))
- index += lastID # introduces small biases
- index %= len(tet)
- next_piece = tet[index]
- return next_piece
- num = 1000000
- print(f"probas de sélection sur {num} tirs")
- print("1roll")
- hist = dict((p, 0) for p in tet)
- p = choice(tet)
- for i in range(num):
- if i % 10000 == 0:
- print(f"{100*i//num}%", end="\r")
- p = next_1roll(p)
- hist[p] += 1
- for k in hist:
- print(f"{k}: {100*hist[k]/num}%")
- print("reroll")
- hist = dict((p, 0) for p in tet)
- p = choice(tet)
- for i in range(num):
- if i % 10000 == 0:
- print(f"{100*i//num}%", end="\r")
- p = next_reroll(p)
- hist[p] += 1
- for k in hist:
- print(f"{k}: {100*hist[k]/num}%")
- print("nes")
- hist = dict((p, 0) for p in tet)
- p = choice(tet)
- for i in range(num):
- if i % 10000 == 0:
- print(f"{100*i//num}%", end="\r")
- p = next_nes(p)
- hist[p] += 1
- for k in hist:
- print(f"{k}: {100*hist[k]/num}%")
- print()
- nbparties = 3000
- centiles = [0,25,50,75,90,95,99]
- def droughtsim(f):
- print("I-piece max drought length centiles")
- print("pieces", end=" ")
- for centile in centiles:
- print(f"{100-centile:3}%≥", end="")
- print()
- for nbpieces in [100, 300, 500, 700, 900]:
- print(f"{nbpieces:6}", end=" ")
- longestdroughts = []
- for _ in range(nbparties):
- longestdrought = 0
- p = choice(tet)
- curdrought = 0 if p == "I" else 1
- for i in range(nbpieces):
- p = f(p)
- if p == "I":
- curdrought = 0
- else:
- curdrought += 1
- if curdrought > longestdrought:
- longestdrought = curdrought
- longestdroughts.append(longestdrought)
- longestdroughts.sort()
- for centile in centiles:
- print(f"{longestdroughts[nbparties*centile//100]:4}", end=" ")
- print()
- print()
- print("1roll ", end="")
- droughtsim(next_1roll)
- print("reroll ", end="")
- droughtsim(next_reroll)
- print("nes ", end="")
- droughtsim(next_nes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement