feedback7: the battle sim uses engine-independent math — Chrome, Firefox, Safari and the server agree bit for bit (PR #373 by @Cloudnyco)
- server/sim/detmath.js: hypot (sqrt of the squares, rescaled outside 2^±500), powi (integer powers in double-double, one rounding), sin / cos (fdlibm 5.3) and atan2 (fdlibm / FreeBSD msun) built only from correctly rounded IEEE operations; the sim's Math.hypot / sin / cos / atan2 / pow calls go through it (65 files); eslint.config.js forbids the approximated Math functions under server/sim and test/sim/detmath.test.js scans for them. - sin / cos / atan2 are the algorithms V8 runs in Node, so the server's results stay; only hypot differs from V8's. Golden: 2 moved — diy-027 (a hypot distance, damage +80) and coop3-ABYSS-5 (a later card pick from round 9, same end). - Applied unchanged after review (Grok static review: MERGE; the diff read in full: no network, no new dependency). - Tests: broad node --test 5155 / 5155 with the new file tracked (detmath 7 / 7, package 10 / 10); lint 0 errors, typecheck, check:imports.
This commit is contained in:
1 parent
2580152a3a
commit
ae22335cfe
65 files changed
+616
-141
No files matched your search
+4
-3
@@ -8,6 +8,7 @@
|
||||
// Additive mod keys scale with stacks (value × stacks); *Mul keys multiply (value ^ stacks).
|
||||
|
||||
import { COLD_ASPD, COLD_FREEZE_DURATION, FREEZE_RES_DOWN, RESIST_DEFAULT, RESIST_PALSY_DECAY } from './constants.js';
|
||||
import { powi } from './detmath.js';
|
||||
|
||||
/** 抵抗: "麻痹等状态每5秒流失1层" — tick of the resist buff. */
|
||||
function resistPalsyDecay({ battle, unit }) {
|
||||
@@ -200,12 +201,12 @@ export function aggregateMods(buffs) {
|
||||
const v = m[k];
|
||||
if (typeof v !== 'number' || !Number.isFinite(v)) continue;
|
||||
if (k === 'shield') continue;
|
||||
if (k.endsWith('Mul')) mul[k] = (mul[k] ?? 1) * (st === 1 ? v : Math.pow(v, st));
|
||||
if (k.endsWith('Mul')) mul[k] = (mul[k] ?? 1) * (st === 1 ? v : powi(v, st));
|
||||
else if ((k === 'dodgePhys' || k === 'dodgeArts') && v > 0) {
|
||||
const p = Math.min(1, v);
|
||||
const d = dodge[k];
|
||||
if (!d) dodge[k] = { n: st, p, miss: Math.pow(1 - p, st) };
|
||||
else { d.n += st; d.miss *= Math.pow(1 - p, st); }
|
||||
if (!d) dodge[k] = { n: st, p, miss: powi(1 - p, st) };
|
||||
else { d.n += st; d.miss *= powi(1 - p, st); }
|
||||
} else {
|
||||
add[k] = (add[k] ?? 0) + v * st;
|
||||
if (k === 'rangeExtend' && b.persist && b.duration === Infinity) permRangeExtend += v * st;
|
||||
|
||||
Reference in new issue
Block a user