Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- import random
- import math
- numSims = 100000
- onePercent = numSims / 100
- results = []
- random.seed()
- for i in range(numSims):
- # reset for new run
- board = [0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0]
- numDice = 78
- numLucky = 0
- runStars = 0
- doubler = False
- backwards = False
- doubleStar = False
- rollTwice = False
- currentPos = -1
- while numDice > 0 or numLucky > 0:
- # decide which dice to use
- if numLucky > 0 and currentPos == 9 and doubler == True:
- # get to lucky hut
- numLucky -= 1
- roll = 5
- elif numLucky > 0 and currentPos == 9 and rollTwice == True:
- # get to lucky hut
- numLucky -= 1
- roll = 10
- rollTwice = False
- elif numLucky > 0 and currentPos != 14 and currentPos < 19 and currentPos >= 13:
- # get to lucky hut
- numLucky -= 1
- roll = 19 - currentPos
- elif numDice <= 0 and numLucky > 0:
- # no ordinary dice left, try to get a free one
- numLucky -= 1
- if currentPos == 14:
- roll = 4
- elif currentPos == 9 and backwards == True:
- roll = 1
- elif currentPos == 19:
- roll = 5
- elif currentPos < 3:
- roll = 3 - currentPos
- else:
- roll = 6
- else:
- # use an ordinary dice
- numDice -= 1
- roll = random.randint(1,6)
- if rollTwice == True:
- roll += random.randint(1,6)
- rollTwice = False
- if doubler == True:
- # double next roll tarot active
- roll *= 2
- doubler = False
- if currentPos == 14 and roll % 2 == 1:
- # rolled odd number on karma
- currentPos -= roll
- elif backwards == True:
- # move backwards tarot active
- backwards = False
- currentPos -= roll
- else:
- # check starry mushrooms
- if (roll >= (6 - currentPos + 17) and currentPos >= 17) or (currentPos + roll >= 3 and currentPos < 3):
- runStars += board[3]
- if currentPos + roll >= 10 and currentPos < 10:
- runStars += board[10]
- if doubleStar == True:
- runStars += board[10]
- doubleStar = False
- if currentPos + roll >= 17 and currentPos < 17:
- runStars += board[17]
- currentPos = (currentPos + roll) % 20
- if currentPos == 4:
- # free ordinary dice
- numDice += 1
- elif currentPos == 19:
- # free lucky dice
- numLucky += 1
- elif currentPos == 9:
- tarot = random.randint(1,9)
- if tarot == 1:
- # upgrade mushroom if possible
- if board[3] < 5:
- board[3] += 1
- elif board[10] < 5:
- board[10] += 1
- elif board[17] < 5:
- board[17] += 1
- elif tarot == 2:
- #degrade mushroom if possible
- if board[3] > 3:
- board[3] -= 1
- elif board[10] > 3:
- board[10] -= 1
- elif board[17] > 3:
- board[17] -= 1
- elif tarot == 3:
- # move backwards
- backwards = True
- elif tarot == 5:
- # get double stars
- doubleStar = True
- elif tarot == 6:
- # double next roll
- doubler = True
- elif tarot == 7:
- # return to start
- currentPos = -1
- elif tarot == 9:
- # roll twice
- rollTwice = True
- elif currentPos in [3, 10, 17]:
- # landed on stars, upgrade if possible
- if board[currentPos] < 5:
- board[currentPos] += 1
- if (i % onePercent) == 0:
- print(str(i/onePercent))
- results.append(runStars)
- print("Number of simulations run: " + str(numSims))
- print("Average stars: " + str(numpy.average(results)))
- print("Standard deviation: " + str(numpy.std(results)))
- print("Max run: " + str(numpy.max(results)))
- print("Min run: " + str(numpy.min(results)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement