Skip to content

Instantly share code, notes, and snippets.

@Whalien3520
Last active November 10, 2023 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Whalien3520/3c1a2abc2125a3193a863603a9127455 to your computer and use it in GitHub Desktop.
Save Whalien3520/3c1a2abc2125a3193a863603a9127455 to your computer and use it in GitHub Desktop.
Final python code for comparing crafting strategies
import matplotlib.pyplot as plt
# strategy is to craft with 25% refund (e.g. xq) till 3n, then craft with 10% duplicate (e.g. layla)
# probList[i] stores {outcomes : probability} at the end of the 25% phase for i mats
# outcomes is stored as tuple([number of low mats, number of high mats])
NUM_ITERATIONS = 1000
# initialize probList with base cases
probList = []
probList.append( {tuple([0, 0]) : 1} )
probList.append( {tuple([1, 0]) : 1} )
probList.append( {tuple([2, 0]) : 1} )
for iteration in range(3, NUM_ITERATIONS + 1):
newDict = {}
prevDict = probList[iteration - 3]
for mats, prob in prevDict.items():
listMats = list(mats)
# if previous outcome was already 3n mats, add 3 to unused mats with same probability
if listMats[0] % 3 == 0:
listMats[0] += 3
tup = tuple(listMats)
if tup not in newDict:
newDict[tup] = 0
newDict[tup] += prob
else:
listMats[1] += 1
# add 75% chance case
tup75 = tuple(listMats)
if tup75 not in newDict:
newDict[tup75] = 0
newDict[tup75] += prob * .75
# add 25% chance case
listMats[0] += 1
tup25 = tuple(listMats)
if tup25 not in newDict:
newDict[tup25] = 0
newDict[tup25] += prob * .25
probList.append(newDict)
# this code makes sure that the number of low-tier mats is 1, 2, or a multiple of 3 (0, 3, 6, ...)
# this makes sure that if there are still refunds to be performed, mats are not used for duplicate crafting in calcs
#for entry in probList:
# for mats, prob in entry.items():
# if(mats[0] > 3 and mats[0] % 3 != 0):
# print('whalien fucked up!')
# create list of expected outputs for duplicate-only
# counting +1 and +2
evRefundLow = []
for mats in range(NUM_ITERATIONS + 1):
evRefundLow.append(mats * 1.1)
# not counting +1 and +2
evRefundNoLow = []
for mats in range(NUM_ITERATIONS + 1):
evRefundNoLow.append((mats // 3) * 1.1 * 3)
# caring about +1 or +2
# +1 or +2 count for 1.1x
evStratOne = []
for entry in probList:
ev = 0
for mats, prob in entry.items():
sum = 3 * mats[1] + mats[0] * 1.1
ev += sum * prob
evStratOne.append(ev)
# not caring about +1 or +2
evStratTwo = []
for entry in probList:
ev = 0
for mats, prob in entry.items():
sum = 3 * mats[1] + ( (mats[0] // 3) * 1.1 * 3)
ev += sum * prob
evStratTwo.append(ev)
evDiffOne = []
for i in range(NUM_ITERATIONS + 1):
evDiffOne.append(evRefundLow[i] - evStratOne[i])
evDiffTwo = []
for i in range(NUM_ITERATIONS + 1):
evDiffTwo.append(evRefundNoLow[i] - evStratTwo[i])
'''plt.figure(0)
plt.plot(evDiffOne, linewidth = 1)
plt.scatter(range(NUM_ITERATIONS + 1), evDiffOne, s=10)
plt.grid()
plt.figure(1)
plt.plot(evDiffTwo, linewidth = 1)
# plt.scatter(range(len(evDiffTwo)), evDiffTwo, s=10)
plt.scatter(range(NUM_ITERATIONS + 1), evDiffTwo, s=10)
plt.grid()'''
evDiffs = [evDiffOne, evDiffTwo]
plotYs = [[[lst[j] for j in range(NUM_ITERATIONS + 1) if j % 3 == i] for lst in evDiffs] for i in range(3)]
plotXs = [[[j for j in range(NUM_ITERATIONS + 1) if j % 3 == i] for lst in evDiffs]for i in range(3)]
fig, axs = plt.subplots(3, 2, figsize=(20, 20))
for r in range(3):
for c in range(2):
axs[r, c].plot(plotXs[r][c], plotYs[r][c], linewidth = 1)
plt.savefig('craftingComparison.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment