Advertisement
Guest User

awoo!

a guest
Apr 8th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.62 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import random
  4.  
  5. DICE_RANGE = range(2, 11)
  6. DIFFICULTIES_RANGE = range(3, 10)
  7. BOOTSTRAP_ITERATIONS = 100000
  8.  
  9. CYAN = "\u001b[36m"
  10. GREEN = "\u001b[32m"
  11. YELLOW = "\u001b[33m"
  12. RED = "\u001b[31m"
  13. MAGNETA = "\u001b[35m"
  14. RESET = "\u001b[0m"
  15.  
  16. def print_distr(botch, zero, one, two, many):
  17.     print("/".join([
  18.         MAGNETA + str(min(99, int(botch*100))).rjust(2, "0"),
  19.         RED + str(min(99, int(zero*100))).rjust(2, "0"),
  20.         YELLOW + str(min(99, int(one*100))).rjust(2, "0"),
  21.         GREEN + str(min(99, int(two*100))).rjust(2, "0"),
  22.         CYAN + str(min(99, int(many*100))).rjust(2, "0")
  23.     ]) + " ", end = RESET)
  24.  
  25. dice_pools = []
  26. print("    " + " ".join([str(x).ljust(14, " ") for x in DIFFICULTIES_RANGE] + ["avg"]))
  27. for dice_pool in DICE_RANGE:
  28.     difficulties = []
  29.     print(str(dice_pool).ljust(3, " "), end = " ")
  30.    
  31.     for difficulty in DIFFICULTIES_RANGE:
  32.         botch = 0
  33.         zero = 0
  34.         one = 0
  35.         two = 0
  36.         many = 0
  37.         for i in range(BOOTSTRAP_ITERATIONS):
  38.             dice_rolls = [random.randint(1, 10) for x in range(dice_pool)]
  39.            
  40.             ones = dice_rolls.count(1)
  41.             successes = sum([1 for x in dice_rolls if x >= difficulty])
  42.             score = successes - ones
  43.             if score < 0:
  44.                 if successes > 0:
  45.                     zero += 1
  46.                 else:
  47.                     botch += 1
  48.             elif score == 0:
  49.                 zero += 1
  50.             elif score == 1:
  51.                 one += 1
  52.             elif score == 2:
  53.                 two += 1
  54.             else:
  55.                 many += 1
  56.        
  57.         avg_botch = botch/BOOTSTRAP_ITERATIONS
  58.         avg_zero = zero/BOOTSTRAP_ITERATIONS
  59.         avg_one = one/BOOTSTRAP_ITERATIONS
  60.         avg_two = two/BOOTSTRAP_ITERATIONS
  61.         avg_many = many/BOOTSTRAP_ITERATIONS
  62.        
  63.         print_distr(avg_botch, avg_zero, avg_one, avg_two, avg_many)
  64.         difficulties.append([avg_botch, avg_zero, avg_one, avg_two, avg_many])
  65.    
  66.     avg_botch = sum([x[0] for x in difficulties])/len(difficulties)
  67.     avg_zero = sum([x[1] for x in difficulties])/len(difficulties)
  68.     avg_one = sum([x[2] for x in difficulties])/len(difficulties)
  69.     avg_two = sum([x[3] for x in difficulties])/len(difficulties)
  70.     avg_many = sum([x[4] for x in difficulties])/len(difficulties)
  71.    
  72.     print_distr(avg_botch, avg_zero, avg_one, avg_two, avg_many)
  73.     print()
  74.     dice_pools.append(difficulties)
  75.    
  76. avg_botches = [0]*len(DIFFICULTIES_RANGE)
  77. avg_zeroes = [0]*len(DIFFICULTIES_RANGE)
  78. avg_ones = [0]*len(DIFFICULTIES_RANGE)
  79. avg_twos = [0]*len(DIFFICULTIES_RANGE)
  80. avg_manies = [0]*len(DIFFICULTIES_RANGE)
  81. for difficulty_distribution in dice_pools:
  82.     for i, difficulty in enumerate(difficulty_distribution):        
  83.         avg_botches[i] += difficulty[0]/len(dice_pools)
  84.         avg_zeroes[i] += difficulty[1]/len(dice_pools)
  85.         avg_ones[i] += difficulty[2]/len(dice_pools)
  86.         avg_twos[i] += difficulty[3]/len(dice_pools)
  87.         avg_manies[i] += difficulty[4]/len(dice_pools)
  88.  
  89. print("avg", end = " ")
  90. for avg_botch, avg_zero, avg_one, avg_two, avg_many in zip(avg_botches, avg_zeroes, avg_ones, avg_twos, avg_manies):
  91.     print_distr(avg_botch, avg_zero, avg_one, avg_two, avg_many)
  92. print()
  93.  
  94. """
  95.    3              4              5              6              7              8              9              avg
  96. 2   03/16/15/64/00 05/17/27/49/00 07/20/35/36/00 08/26/39/25/00 11/33/39/15/00 12/41/36/09/00 15/53/27/04/00 09/30/31/29/00
  97. 3   00/07/21/19/51 01/11/23/29/34 03/15/26/32/21 06/19/31/29/12 09/25/34/23/06 12/33/35/16/02 16/43/30/08/00 07/22/29/22/18
  98. 4   00/06/07/24/61 00/08/13/25/51 01/12/19/27/38 03/16/24/28/26 06/21/29/26/15 11/28/32/20/07 16/37/30/12/02 05/18/22/23/28
  99. 5   00/03/07/10/78 00/05/09/17/66 00/09/14/22/53 02/13/19/25/38 04/18/25/26/24 09/26/29/22/12 16/34/29/14/04 04/15/19/20/39
  100. 6   00/02/03/09/85 00/04/06/12/76 00/06/10/18/64 01/11/15/22/49 03/16/21/25/33 07/24/26/23/18 14/32/28/16/07 03/14/16/18/47
  101. 7   00/01/02/05/91 00/02/04/09/83 00/05/07/14/72 00/09/12/19/58 02/14/18/22/41 05/22/24/23/24 12/31/27/18/09 03/12/13/15/54
  102. 8   00/00/01/03/93 00/01/03/06/88 00/03/05/11/79 00/07/10/16/65 01/13/15/20/48 04/21/22/22/29 11/31/26/18/12 02/11/12/14/59
  103. 9   00/00/01/02/96 00/01/02/04/91 00/03/04/08/84 00/06/08/13/71 00/11/13/18/55 02/20/20/21/34 09/30/25/19/15 01/10/10/12/64
  104. 10  00/00/00/01/97 00/00/01/03/94 00/02/03/06/87 00/05/06/11/76 00/10/11/17/60 02/18/18/20/39 07/30/23/19/18 01/09/09/11/67
  105. avg 00/04/06/15/72 00/06/10/17/65 01/08/14/19/55 02/12/18/21/44 04/18/23/21/31 07/26/27/20/18 13/36/27/14/07
  106. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement