Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import random
- DICE_RANGE = range(2, 11)
- DIFFICULTIES_RANGE = range(3, 10)
- BOOTSTRAP_ITERATIONS = 100000
- CYAN = "\u001b[36m"
- GREEN = "\u001b[32m"
- YELLOW = "\u001b[33m"
- RED = "\u001b[31m"
- MAGNETA = "\u001b[35m"
- RESET = "\u001b[0m"
- def print_distr(botch, zero, one, two, many):
- print("/".join([
- MAGNETA + str(min(99, int(botch*100))).rjust(2, "0"),
- RED + str(min(99, int(zero*100))).rjust(2, "0"),
- YELLOW + str(min(99, int(one*100))).rjust(2, "0"),
- GREEN + str(min(99, int(two*100))).rjust(2, "0"),
- CYAN + str(min(99, int(many*100))).rjust(2, "0")
- ]) + " ", end = RESET)
- dice_pools = []
- print(" " + " ".join([str(x).ljust(14, " ") for x in DIFFICULTIES_RANGE] + ["avg"]))
- for dice_pool in DICE_RANGE:
- difficulties = []
- print(str(dice_pool).ljust(3, " "), end = " ")
- for difficulty in DIFFICULTIES_RANGE:
- botch = 0
- zero = 0
- one = 0
- two = 0
- many = 0
- for i in range(BOOTSTRAP_ITERATIONS):
- dice_rolls = [random.randint(1, 10) for x in range(dice_pool)]
- ones = dice_rolls.count(1)
- successes = sum([1 for x in dice_rolls if x >= difficulty])
- score = successes - ones
- if score < 0:
- if successes > 0:
- zero += 1
- else:
- botch += 1
- elif score == 0:
- zero += 1
- elif score == 1:
- one += 1
- elif score == 2:
- two += 1
- else:
- many += 1
- avg_botch = botch/BOOTSTRAP_ITERATIONS
- avg_zero = zero/BOOTSTRAP_ITERATIONS
- avg_one = one/BOOTSTRAP_ITERATIONS
- avg_two = two/BOOTSTRAP_ITERATIONS
- avg_many = many/BOOTSTRAP_ITERATIONS
- print_distr(avg_botch, avg_zero, avg_one, avg_two, avg_many)
- difficulties.append([avg_botch, avg_zero, avg_one, avg_two, avg_many])
- avg_botch = sum([x[0] for x in difficulties])/len(difficulties)
- avg_zero = sum([x[1] for x in difficulties])/len(difficulties)
- avg_one = sum([x[2] for x in difficulties])/len(difficulties)
- avg_two = sum([x[3] for x in difficulties])/len(difficulties)
- avg_many = sum([x[4] for x in difficulties])/len(difficulties)
- print_distr(avg_botch, avg_zero, avg_one, avg_two, avg_many)
- print()
- dice_pools.append(difficulties)
- avg_botches = [0]*len(DIFFICULTIES_RANGE)
- avg_zeroes = [0]*len(DIFFICULTIES_RANGE)
- avg_ones = [0]*len(DIFFICULTIES_RANGE)
- avg_twos = [0]*len(DIFFICULTIES_RANGE)
- avg_manies = [0]*len(DIFFICULTIES_RANGE)
- for difficulty_distribution in dice_pools:
- for i, difficulty in enumerate(difficulty_distribution):
- avg_botches[i] += difficulty[0]/len(dice_pools)
- avg_zeroes[i] += difficulty[1]/len(dice_pools)
- avg_ones[i] += difficulty[2]/len(dice_pools)
- avg_twos[i] += difficulty[3]/len(dice_pools)
- avg_manies[i] += difficulty[4]/len(dice_pools)
- print("avg", end = " ")
- for avg_botch, avg_zero, avg_one, avg_two, avg_many in zip(avg_botches, avg_zeroes, avg_ones, avg_twos, avg_manies):
- print_distr(avg_botch, avg_zero, avg_one, avg_two, avg_many)
- print()
- """
- 3 4 5 6 7 8 9 avg
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement