Skip to content

Commit d1eea27

Browse files
committed
Optimize gachacalc
1 parent 095035e commit d1eea27

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pages/tools/gachacalc.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,20 @@ function calcSimsInt(starterSim: Sim, pulls: number, banner: Banner): ReducedSim
237237

238238
function calcSimsExact(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8) {
239239
for (let i = 0; i < pulls; i++) {
240-
const newSims: Sim[] = []
240+
const newSims: Record<number, Sim> = {}
241241

242242
const addOrMerge = (sim: Sim) => {
243243
if (sim.rate <= 0) return
244244

245-
const v = (((sim.const + 1) * (banner.maxPity + 5) + sim.pity) * 2 + (+sim.guaranteed)) * (banner.guaranteedPity ?? 1) + sim.guaranteedPity
245+
const v = sim.pity + (banner.maxPity + 1) * ((sim.const + 1) + ((banner.maxConst + 2) * (+sim.guaranteed + (2 * sim.guaranteedPity))))
246246
const other = newSims[v]
247247

248248
if (other) {
249+
// if (other.const != sim.const) console.error("const", v, sim, other)
250+
// if (other.guaranteed != sim.guaranteed) console.error("guaranteed", v, sim, other)
251+
// if (other.guaranteedPity != sim.guaranteedPity) console.error("guaranteedPity", v, sim, other)
252+
// if (other.pity != sim.pity) console.error("pity", v, sim, other)
253+
249254
other.rate += sim.rate
250255
return
251256
}
@@ -303,7 +308,7 @@ function calcSimsExact(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8)
303308
addOrMerge({
304309
pity: 0,
305310
guaranteed: false,
306-
guaranteedPity: sim.guaranteedPity + 1,
311+
guaranteedPity: banner.guaranteedPity ? sim.guaranteedPity + 1 : 0,
307312
const: sim.const,
308313
rate: sim.rate * rate * bannerRate * (1 - banner.guaranteed)
309314
})
@@ -313,13 +318,13 @@ function calcSimsExact(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8)
313318
addOrMerge({
314319
pity: 0,
315320
guaranteed: true,
316-
guaranteedPity: sim.guaranteedPity + 1,
321+
guaranteedPity: banner.guaranteedPity ? sim.guaranteedPity + 1 : 0,
317322
const: sim.const,
318323
rate: sim.rate * rate * (1 - bannerRate)
319324
})
320325
}
321326

322-
sims = newSims
327+
sims = Object.values(newSims)
323328
}
324329
return sims
325330
}

0 commit comments

Comments
 (0)