Advertisement
Guest User

IdleHeroesEaster

a guest
Apr 11th, 2020
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.47 KB | None | 0 0
  1. import numpy
  2. import random
  3. import math
  4.  
  5. numSims = 100000
  6. onePercent = numSims / 100
  7. results = []
  8. random.seed()
  9.  
  10. for i in range(numSims):
  11.     # reset for new run
  12.     board = [0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0]
  13.     numDice = 78
  14.     numLucky = 0
  15.     runStars = 0
  16.     doubler = False
  17.     backwards = False
  18.     doubleStar = False
  19.     rollTwice = False
  20.     currentPos = -1
  21.    
  22.     while numDice > 0 or numLucky > 0:
  23.         # decide which dice to use
  24.         if numLucky > 0 and currentPos == 9 and doubler == True:
  25.             # get to lucky hut
  26.             numLucky -= 1
  27.             roll = 5
  28.         elif numLucky > 0 and currentPos == 9 and rollTwice == True:
  29.             # get to lucky hut
  30.             numLucky -= 1
  31.             roll = 10
  32.             rollTwice = False
  33.         elif numLucky > 0 and currentPos != 14 and currentPos < 19 and currentPos >= 13:
  34.             # get to lucky hut
  35.             numLucky -= 1
  36.             roll = 19 - currentPos
  37.         elif numDice <= 0 and numLucky > 0:
  38.             # no ordinary dice left, try to get a free one
  39.             numLucky -= 1
  40.             if currentPos == 14:
  41.                 roll = 4
  42.             elif currentPos == 9 and backwards == True:
  43.                 roll = 1
  44.             elif currentPos == 19:
  45.                 roll = 5
  46.             elif currentPos < 3:
  47.                 roll = 3 - currentPos
  48.             else:
  49.                 roll = 6
  50.         else:
  51.             # use an ordinary dice
  52.             numDice -= 1
  53.             roll = random.randint(1,6)
  54.             if rollTwice == True:
  55.                 roll += random.randint(1,6)
  56.                 rollTwice = False
  57.        
  58.         if doubler == True:
  59.             # double next roll tarot active
  60.             roll *= 2
  61.             doubler = False
  62.        
  63.         if currentPos == 14 and roll % 2 == 1:
  64.             # rolled odd number on karma
  65.             currentPos -= roll
  66.         elif backwards == True:
  67.             # move backwards tarot active
  68.             backwards = False
  69.             currentPos -= roll
  70.         else:
  71.             # check starry mushrooms
  72.             if (roll >= (6 - currentPos + 17) and currentPos >= 17) or (currentPos + roll >= 3 and currentPos < 3):
  73.                 runStars += board[3]
  74.            
  75.             if currentPos + roll >= 10 and currentPos < 10:
  76.                 runStars += board[10]
  77.                 if doubleStar == True:
  78.                     runStars += board[10]
  79.                     doubleStar = False
  80.                    
  81.             if currentPos + roll >= 17 and currentPos < 17:
  82.                 runStars += board[17]
  83.                
  84.             currentPos = (currentPos + roll) % 20
  85.                
  86.             if currentPos == 4:
  87.                 # free ordinary dice
  88.                 numDice += 1
  89.             elif currentPos == 19:
  90.                 # free lucky dice
  91.                 numLucky += 1
  92.             elif currentPos == 9:
  93.                 tarot = random.randint(1,9)
  94.                 if tarot == 1:
  95.                     # upgrade mushroom if possible
  96.                     if board[3] < 5:
  97.                         board[3] += 1
  98.                     elif board[10] < 5:
  99.                         board[10] += 1
  100.                     elif board[17] < 5:
  101.                         board[17] += 1
  102.                 elif tarot == 2:
  103.                     #degrade mushroom if possible
  104.                     if board[3] > 3:
  105.                         board[3] -= 1
  106.                     elif board[10] > 3:
  107.                         board[10] -= 1
  108.                     elif board[17] > 3:
  109.                         board[17] -= 1
  110.                 elif tarot == 3:
  111.                     # move backwards
  112.                     backwards = True
  113.                 elif tarot == 5:
  114.                     # get double stars
  115.                     doubleStar = True
  116.                 elif tarot == 6:
  117.                     # double next roll
  118.                     doubler = True
  119.                 elif tarot == 7:
  120.                     # return to start
  121.                     currentPos = -1
  122.                 elif tarot == 9:
  123.                     # roll twice
  124.                     rollTwice = True
  125.             elif currentPos in [3, 10, 17]:
  126.                 # landed on stars, upgrade if possible
  127.                 if board[currentPos] < 5:
  128.                     board[currentPos] += 1
  129.    
  130.     if (i % onePercent) == 0:
  131.         print(str(i/onePercent))
  132.        
  133.     results.append(runStars)
  134.    
  135. print("Number of simulations run: " + str(numSims))
  136. print("Average stars: " + str(numpy.average(results)))
  137. print("Standard deviation: " + str(numpy.std(results)))
  138. print("Max run: " + str(numpy.max(results)))
  139. print("Min run: " + str(numpy.min(results)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement