I have made a simulator using Python for a game called Final Fantasy XII. The purpose of this simulator is to see how much "gil" (in-game currency) you can get from one particular enemy.
This should output around 23000 from our experiance, but what happens with this is, it outputs 24000 usually, but sometimes 29000. Considering it takes 1000 samples, it is impossible for that to be coincident. I think this code has problems with random generator, but I have no idea.
How can I fix this simulator? Or are there reasons python simulator sometimes goes wrong?
import random
l = 0 # chain level
m = 0 # 1 if it is in Chance mode, otherwise 0
c = -1 # chain counter (=/= chains)
b = 0 # books in a loot
s = 0 # staves in a loot
book = 0 # total drops
staff = 0 # total drops
booksum = 0 # to be devided by sample size
staffsum = 0 # to be devided by sample size
def levelup():
global l, c
l = l + 1
c = 0
def pickup():
global book, staff, b, s
book = book + b
staff= staff + s
bdrop = { 0: 0.35, 1: 0.4, 2: 0.45, 3: 0.5 }
sdrop = { 0: 0.03, 1: 0.06, 2: 0.08, 3: 0.12 }
# input area
wait = 1 # level you start picking up from
dustia = 47 # number of dustia you farm
test = 1000 # sample size
for t in range (1, test + 1):
for n in range (1, dustia + 1):
c = c + 1 # first, increase the chain counter
# chain level
r = random.random()
if l == 0:
if c == 6 and r < 0.4:
levelup()
elif c == 7 and r < 0.6:
levelup()
elif c == 8 and r < 0.8:
levelup()
elif c == 9 and r < 0.9:
levelup()
elif c == 10 or n >= 31:
levelup()
elif l == 1:
if c == 6 and r < 0.2:
levelup()
elif c == 7 and r < 0.3:
levelup()
elif c == 8 and r < 0.5:
levelup()
elif c == 9 and r < 0.6:
levelup()
elif c == 10 or n >= 51:
levelup()
elif l == 2:
if c == 6 and r < 0.1:
levelup()
elif c == 7 and r < 0.2:
levelup()
elif c == 8 and r < 0.3:
levelup()
elif c == 9 and r < 0.4:
levelup()
elif c == 10 or n >= 81:
levelup()
# chance mode
r = random.random()
if m == 1 and r < 0.4:
m = 0
elif m == 0 and r < 0.05:
m = 1
#drops
r1 = random.random() # RNG for book
r2 = random.random() # RNG for staff
rr1 = random.random() # amount of books
rr2 = random.random() # amount of staff
if r1 < bdrop[l]:
if n <= 10:
b = 1
elif n <= 18:
if rr1 < 0.35:
b = 2
else: b = 1
elif n <= 26:
if rr1 < 0.7:
b = 2
else: b = 1
else:
if rr1 < 0.1:
b = 4
elif rr1 < 0.4:
b = 3
else: b = 2
if r2 < sdrop[l]:
if n <= 18:
s = 1
elif n <= 26:
if rr2 < 0.2:
s = 2
else: s = 1
elif n >= 27:
if rr2 < 0.05:
s = 4
elif rr2 < 0.15:
s = 3
elif rr2 < 0.4:
s = 2
else: s = 1
#will you pick up
if b > 0 or s > 0:
if l == 3:
pickup()
elif l == 2 and wait <= 2:
pickup()
if m == 0:
c = c - 3
elif l == 1 and wait <= 1:
pickup()
if m == 0:
c = c - 2
elif l == 0 and wait <= 0:
pickup()
if m == 0:
c = c - 1
#print(n, 'th dustia, chain level', l)
#print(b, 'book ', s, 'staff')
#print(c, 'chain number')
#print()
b = 0
s = 0
booksum = booksum + book
staffsum = staffsum + staff
print(book, staff)
book = 0
staff = 0
avgbook = booksum / test
avgstaff = staffsum / test
#print (avgbook)
#print (avgstaff)
print (avgbook*532+(avgstaff-2)*1200)
Aucun commentaire:
Enregistrer un commentaire