자동 시점 · 점수판 보완: 궁극기 점수는 공수 교대(선수 시작 자리가 40m 넘게 옮겨 간 라운드) 초기화를 사용으로 보지 않음 (한 명만 점수가 있어도) · 전략 보기 카메라 거리를 시야각 · 화면비 · 기울기로 계산해 모든 선수가 화면 안 (fitDistance) · 라운드가 끝난 뒤 점수판 팀 점수는 그 라운드까지 (최종 점수) · 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-08 22:54:41 +09:00
parent c36db3ef9a
commit a5a1c8406a
5 changed files with 133 additions and 16 deletions

View File

@@ -3,12 +3,14 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import type { ReplayFile } from '../../web/src/lib/replay.ts';
import { buildDirector, shotIndexAt, FIGHT_LEAD, type Shot } from '../../web/src/lib/director.ts';
import { boardAt, boardIndex, loadoutAt, teamScoreAt } from '../../web/src/lib/scoreboard.ts';
import { boardAt, boardIndex, loadoutAt, sideSwaps, teamScoreAt } from '../../web/src/lib/scoreboard.ts';
import { fitDistance } from '../../web/src/lib/director.ts';
import * as THREE from '../../web/node_modules/three/build/three.module.js';
// 선수 0·1·4 아군, 2·3·5 상대. 라운드 1: 구매 0~30초, 교전 30초~, 끝 90초. 라운드 2: 100초~
const still = (n = 2000) => {
// 선수 0·1·4 아군, 2·3·5 상대. 라운드 1: 구매 0~30초, 교전 30초~, 끝 90초. 라운드 2: 100초~ (공수 교대: 시작 자리가 100m 옮겨 감)
const still = (n = 2000, swapAt = 100_000) => {
const t = Array.from({ length: n }, (_, i) => i * 100);
return { t, x: t.map(() => 0), y: t.map(() => 0), z: t.map(() => 100), yaw: t.map(() => 0), pitch: t.map(() => 0) };
return { t, x: t.map((v) => (v >= swapAt ? 10_000 : 0)), y: t.map(() => 0), z: t.map(() => 100), yaw: t.map(() => 0), pitch: t.map(() => 0) };
};
function replay(extra: Partial<ReplayFile> = {}): ReplayFile {
return {
@@ -130,3 +132,51 @@ test('점수판: 예전 리플레이(값 없음)는 킬 · 데스를 킬 기록
assert.deepEqual(teamScoreAt(r, rounds, 50_000), { round: 1, ally: 0, enemy: 0 });
assert.deepEqual(teamScoreAt(r, rounds, 150_000), { round: 2, ally: 1, enemy: 0 });
});
test('점수판: 한 명만 궁 점수가 있어도 공수 교대 초기화는 궁 사용이 아니다 · 교대가 없으면 라운드 끝 0 은 사용', () => {
// 선수 1(피닉스)만 3점을 모은 채 1라운드가 끝나고(90초) 2라운드 구매 시작(100초) 직전에 0
const sb = [[20_000, 1, 800, 3, -1, -1, -1, -1], [99_000, 1, 800, 0, -1, -1, -1, -1]];
const r = replay({ scoreboard: sb });
assert.deepEqual([...sideSwaps(r)], [1]);
const ix = boardIndex(r);
assert.equal(ix.ultMax[1], 7); // 요원 표 (피닉스 7), 3 이 아니다
assert.equal(boardAt(r, ix, 1, 50_000).ult, 3);
// 같은 기록이라도 교대가 아니면(시작 자리 그대로) 쓴 것으로 본다
const same = replay({ scoreboard: sb, players: [0, 1, 2, 3, 4, 5].map((i) => ({ puuid: `p${i}`, character: 'Phoenix_PC_C', track: still(2000, Infinity) })) });
assert.deepEqual([...sideSwaps(same)], []);
assert.equal(boardIndex(same).ultMax[1], 3);
});
test('점수판: 마지막 라운드가 끝난 뒤에는 최종 점수', () => {
const r = replay({ rounds: [{ num: 1, buy: 0, combat: 30_000, end: 90_000 }, { num: 2, buy: 100_000, combat: 130_000, end: 180_000 }] });
const rounds = [{ num: 1, score: { ally: 1, enemy: 0 } }, { num: 2, score: { ally: 2, enemy: 0 } }];
assert.deepEqual(teamScoreAt(r, rounds, 170_000), { round: 2, ally: 1, enemy: 0 });
assert.deepEqual(teamScoreAt(r, rounds, 190_000), { round: 2, ally: 2, enemy: 0 });
// 1라운드 끝 ~ 2라운드 구매 사이도 그 라운드 결과까지
assert.deepEqual(teamScoreAt(r, rounds, 95_000), { round: 1, ally: 1, enemy: 0 });
});
test('전략 보기 카메라: 시야각 · 화면비 · 기울기를 넣어 구한 거리면 모든 선수가 화면 안 (three.js 투영으로 확인)', () => {
const dir: [number, number, number] = [0, 0.92 / Math.hypot(0.92, 0.42), 0.42 / Math.hypot(0.92, 0.42)];
const cases: { pts: [number, number, number][]; aspect: number }[] = [
{ pts: [[-35, 0, -40], [35, 0, 40]], aspect: 1 },
{ pts: [[-45, 2, 10], [40, 8, -45], [0, 0, 48]], aspect: 16 / 9 },
{ pts: [[-10, 0, -45], [10, 0, 45]], aspect: 0.6 },
];
for (const { pts, aspect } of cases) {
const c = pts.reduce((a, p) => [a[0] + p[0] / pts.length, a[1] + p[1] / pts.length, a[2] + p[2] / pts.length], [0, 0, 0]) as [number, number, number];
const d = fitDistance(pts, c, dir, 45, aspect);
const cam = new THREE.PerspectiveCamera(45, aspect, 0.5, 2000);
cam.position.set(c[0] + dir[0] * d, c[1] + dir[1] * d, c[2] + dir[2] * d);
cam.lookAt(c[0], c[1], c[2]);
cam.updateMatrixWorld();
let edge = 0;
for (const p of pts) {
const v = new THREE.Vector3(...p).project(cam);
assert.ok(Math.abs(v.x) <= 0.86 && Math.abs(v.y) <= 0.86, `화면 밖 ${p} → ${v.x.toFixed(3)},${v.y.toFixed(3)} (화면비 ${aspect})`);
edge = Math.max(edge, Math.abs(v.x), Math.abs(v.y));
}
// 가장 짧은 거리: 가장 바깥 선수가 가장자리(0.85)에 닿는다
assert.ok(edge > 0.84, `너무 멀다 ${edge}`);
}
});