Skip to content

Commit d9a8b2b

Browse files
committed
Fix gc hashing formula, optimize regular & 4*
1 parent dc29361 commit d9a8b2b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/commands/misc/gachacalc.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,20 @@ ${createTable(
250250

251251
private calcSimsExact(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8) {
252252
for (let i = 0; i < pulls; i++) {
253-
const newSims: Sim[] = []
253+
const newSims: Record<number, Sim> = {}
254254

255255
const addOrMerge = (sim: Sim) => {
256256
if (sim.rate <= 0) return
257257

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

261261
if (other) {
262+
// if (other.const != sim.const) console.error("const", v, sim, other)
263+
// if (other.guaranteed != sim.guaranteed) console.error("guaranteed", v, sim, other)
264+
// if (other.guaranteedPity != sim.guaranteedPity) console.error("guaranteedPity", v, sim, other)
265+
// if (other.pity != sim.pity) console.error("pity", v, sim, other)
266+
262267
other.rate += sim.rate
263268
return
264269
}
@@ -316,7 +321,7 @@ ${createTable(
316321
addOrMerge({
317322
pity: 0,
318323
guaranteed: false,
319-
guaranteedPity: sim.guaranteedPity + 1,
324+
guaranteedPity: banner.guaranteedPity ? sim.guaranteedPity + 1 : 0,
320325
const: sim.const,
321326
rate: sim.rate * rate * bannerRate * (1 - banner.guaranteed)
322327
})
@@ -326,22 +331,23 @@ ${createTable(
326331
addOrMerge({
327332
pity: 0,
328333
guaranteed: true,
329-
guaranteedPity: sim.guaranteedPity + 1,
334+
guaranteedPity: banner.guaranteedPity ? sim.guaranteedPity + 1 : 0,
330335
const: sim.const,
331336
rate: sim.rate * rate * (1 - bannerRate)
332337
})
333338
}
334339

335-
sims = newSims
340+
sims = Object.values(newSims)
336341
}
337342
return sims
338343
}
339344
}
340-
// const gc = new GachaCalc("a")
341-
// while (true) {
342-
// const start = Date.now()
343-
// for (let i = 0; i < 1000; i += 20) {
344-
// gc.calcSims(0, i, false, "char")
345-
// }
346-
// console.log(Date.now() - start)
347-
// }
345+
346+
/*
347+
const gc = new GachaCalc("gc")
348+
const start = Date.now()
349+
for (let i = 0; i < 1000; i += 20) {
350+
gc.calcSims(-1, 0, i, false, 0, gachas.weapon)
351+
}
352+
console.log(Date.now() - start)
353+
*/

0 commit comments

Comments
 (0)