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
@@ -38,6 +38,7 @@
|
||||
|
||||
import { bodyInKeys } from '../../../body.js';
|
||||
import { absoluteRangeKeys, sortEnemyTargets } from '../../../targeting.js';
|
||||
import { hypot } from '../../../detmath.js';
|
||||
|
||||
// ---- text-only constants (the official blackboards carry no key for these) --------------------------------------
|
||||
/** 华法琳 S1 "只当目标生命值不满一半时才会触发"; 塞雷娅 S1 "血量小于等于一半"; 山 module "生命值高于50%时". */
|
||||
@@ -70,7 +71,7 @@ const maxCharges = (chess, def) => num(def?.skill?.maxCharges, num(chess?.skill?
|
||||
const batPct = (sec, chess) => { const b = num(chess?.stats?.bat, 1) || 1; const v = num(sec) / b; return v ? Math.max(-0.9, v) : 0; };
|
||||
/** Drop zero / non-finite entries (a zero mod is noise in the buff list). */
|
||||
const mods = (m) => { const o = {}; for (const k of Object.keys(m)) { const v = m[k]; if (typeof v === 'number' && Number.isFinite(v) && v !== 0) o[k] = v; } return o; };
|
||||
const dist = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
||||
const dist = (a, b) => hypot(a.x - b.x, a.y - b.y);
|
||||
const nationOf = (u) => u?.def?.raw?.nationId ?? null;
|
||||
const inFaction = (u, bond, nations) => !!u?.def && ((u.def.bonds || []).includes(bond) || nations.includes(nationOf(u)));
|
||||
const isAbyssal = (u) => u?.def?.raw?.groupId === 'abyssal' || ABYSSAL.has(u?.def?.charId);
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
import { absoluteRangeKeys } from '../../../targeting.js';
|
||||
import { COLS, ROWS, PULL_STOP_RADIUS } from '../../../constants.js';
|
||||
import { hasHp } from '../../../damage.js';
|
||||
import { hypot } from '../../../detmath.js';
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
// helpers
|
||||
@@ -237,7 +238,7 @@ function bestTile(battle, tiles) {
|
||||
let best = tiles[0], bd = Infinity;
|
||||
for (const t of tiles) {
|
||||
let d = Infinity;
|
||||
for (const e of en) d = Math.min(d, Math.hypot(e.x - t[1], e.y - t[0]));
|
||||
for (const e of en) d = Math.min(d, hypot(e.x - t[1], e.y - t[0]));
|
||||
if (d < bd - 1e-9) { bd = d; best = t; }
|
||||
}
|
||||
return best;
|
||||
|
||||
Reference in new issue
Block a user