새 게임 타자 대결: 한국어·영어, 가장 먼저 입력·서바이벌·타수 비교·정확도 대결·타임어택, 단어·짧은글·긴글, 주제 여러 개, 1~10라운드
- 규칙 packages/games/src/typing: 함께 치기(같은 문제를 동시에, 정해지면 1.5초 쉬고 다음)와 각자 치기(한 줄씩 자기 속도로). 가장 먼저 입력은 문제마다 먼저 정확하게 친 사람 1점, 나머지는 라운드 1등 1점, 최종은 점수 → 평균 타수 → 정확도. 서바이벌 탈락 조건: 틀렸을 때(목숨 1~5, 기본 3)·문장별(가장 늦게 친 사람)·시간별(간격마다 가장 적게 친 사람)·시간 초과. 서바이벌은 문제마다 시간이 0.9배씩 줄어(900타 + 1초 아래로는 안 줄어) 반드시 끝나고, 모두 한꺼번에 탈락하게 되면 아무도 탈락하지 않음. 제한 시간 자동(글 길이)/10초~5분/무제한, 타임어택 30초~2분, 3초 카운트다운, 라운드 결과 6초. - 타수: 두벌식 자판 수(겹모음·겹받침 2타), 조합 중 글자는 친 자판까지 맞은 것으로, 정확도 = 1 − 편집 거리/길이. 붙여 넣기 막기: 화면에서 막고 서버는 2,400타/분 + 0.15초보다 빠른 정답을 거절, 진행 막대도 그 속도 이상 못 앞섬. - 진행은 stream 액션(progress)이라 서버는 이벤트만 전달(보기 재계산·DB 쓰기 없이 묶어서 저장). - 글 묶음 37개 주제: 한국어 단어 8(과일·동물·채소·나라·음식·직업·스포츠·사자성어), 짧은글 4(속담·명언·잰말놀이·일상 문장), 긴글 11(애국가·별 헤는 밤·서시·진달래꽃·산유화·님의 침묵·훈민정음 서문·전래 동화 3), 영어 단어 7·짧은글 4·긴글 7. 시는 위키문헌 원문과 대조해 현대 맞춤법으로. 일반 자판 글자만(테스트로 확인), 긴 줄은 띄어쓰기에서 나눔. - 컴퓨터(live): 레벨에 따라 120~620타(영어 100~500), 읽는 시간, 오타 확률. 함께 치기는 틀리면 고쳐서 다시. - 화면: 글자별 초록/빨강/조합 중 표시, 긴글은 단락 전체와 지금 줄(자동 스크롤), 다음 두 줄 미리 보기, 한글 조합 중 Enter 처리, 한/영 경고, 지금 타수·정확도, 모두의 진행 막대(실시간)·목숨 하트, "먼저 쳤어요"/"탈락" 띠, 라운드 결과 표, 소리, 휴대폰. - 등록: GAMES·LIVE_BOT_STRATEGIES·BOT_GAMES·CATALOG·GAME_UI·아이콘 ⌨️·파티 탭, README(43개), docs/games/typing.md. - 테스트: 규칙 34·타수/글 묶음 9·컴퓨터 12·방 통합 4·웹 도움말 3, e2e games.e2e.ts typing·typingSpeed·typingSurvival. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
149
e2e/games.e2e.ts
149
e2e/games.e2e.ts
@@ -1385,6 +1385,22 @@ async function cobStep(p: Page, st: Record<string, number>): Promise<string | nu
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 타자 대결: the text my input asks for (its label), or null when it is off. */
|
||||
async function typingTarget(p: Page): Promise<string | null> {
|
||||
const box = p.locator('input.ty-input');
|
||||
if (!(await box.count()) || !(await box.isEnabled().catch(() => false))) return null;
|
||||
const label = (await box.getAttribute('aria-label')) ?? '';
|
||||
return label.startsWith('여기에 쳐요: ') ? label.slice('여기에 쳐요: '.length) : null;
|
||||
}
|
||||
|
||||
/** Types like a person (one key at a time, so the paste guard lets it in) and presses Enter. */
|
||||
async function typeLine(p: Page, text: string, delay = 70) {
|
||||
const box = p.locator('input.ty-input');
|
||||
await box.click();
|
||||
await p.keyboard.type(text, { delay });
|
||||
await p.keyboard.press('Enter');
|
||||
}
|
||||
|
||||
const PLANS: Record<string, Plan> = {
|
||||
'case-file': {
|
||||
// PC host + phone guest, "고른 사람만 읽기": 의뢰 → 반장 돌기(두 번 눌러 고르기) → 단서 읽기(다른 사람은 제목만)
|
||||
@@ -3597,6 +3613,139 @@ const PLANS: Record<string, Plan> = {
|
||||
console.log(` apple: ${st.pc} mouse + ${st.key} keyboard clears on PC, ${st.phone}+ touch clears on the phone, ${st.miss} miss; final PC ${await appleScore(host)} / phone ${await appleScore(guest)}`);
|
||||
},
|
||||
},
|
||||
typing: {
|
||||
// 2026-11-12 타자 대결, 가장 먼저 입력 · 짧은글 · 1라운드: host and phone take turns typing each sentence for real
|
||||
// (keyboard, one key at a time). A wrong Enter shakes the box and keeps the text; the other side sees the "먼저 쳤어요"
|
||||
// banner and the score; the progress bar of the one typing moves on the other screen while they type.
|
||||
lobby: async (host) => {
|
||||
await host.getByRole('group', { name: '라운드' }).getByRole('button', { name: '1', exact: true }).click();
|
||||
await host.getByText(/짧은글\(전체 주제\) · 1라운드/).first().waitFor();
|
||||
},
|
||||
drive: async (pages) => {
|
||||
const [host, guest] = pages as [Page, Page];
|
||||
let n = 0;
|
||||
let wrongShown = false;
|
||||
let barSeen = false;
|
||||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||||
const until = Date.now() + 120_000;
|
||||
while (Date.now() < until && !(await over())) {
|
||||
const typer = n % 2 === 0 ? host : guest;
|
||||
const other = typer === host ? guest : host;
|
||||
const text = await typingTarget(typer);
|
||||
if (!text) {
|
||||
await host.waitForTimeout(150);
|
||||
continue;
|
||||
}
|
||||
if (!wrongShown) {
|
||||
await typeLine(typer, 'ㅋ');
|
||||
await typer.getByText('틀린 곳이 있어요. 빨간 글자를 고쳐요').waitFor({ timeout: 3000 });
|
||||
await typer.locator('.ty-target .bad').first().waitFor();
|
||||
await typer.screenshot({ path: join(SHOTS, 'typing-wrong.png') });
|
||||
await typer.locator('input.ty-input').fill('');
|
||||
wrongShown = true;
|
||||
}
|
||||
const box = typer.locator('input.ty-input');
|
||||
await box.click();
|
||||
const half = Math.ceil([...text].length / 2);
|
||||
await typer.keyboard.type([...text].slice(0, half).join(''), { delay: 70 });
|
||||
if (!barSeen) {
|
||||
// The other screen shows my bar moving (streamed progress), before I press Enter.
|
||||
await other.waitForFunction(() => [...document.querySelectorAll('.ty-bar')].some((b) => Number(b.getAttribute('aria-valuenow')) > 0), null, { timeout: 3000 });
|
||||
barSeen = true;
|
||||
await host.screenshot({ path: join(SHOTS, 'typing-typing-pc.png') });
|
||||
await guest.screenshot({ path: join(SHOTS, 'typing-typing-phone.png') });
|
||||
}
|
||||
await typer.keyboard.type([...text].slice(half).join(''), { delay: 70 });
|
||||
await typer.keyboard.press('Enter');
|
||||
await other.locator('.ty-banner').filter({ hasText: '먼저 쳤어요' }).first().waitFor({ timeout: 4000 }).catch(() => {});
|
||||
n++;
|
||||
}
|
||||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||||
await host.waitForTimeout(600);
|
||||
await host.screenshot({ path: join(SHOTS, 'typing-result-pc.png') });
|
||||
await guest.screenshot({ path: join(SHOTS, 'typing-result-phone.png') });
|
||||
const text = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||||
if (!/3문제 · 평균 \d+타 · 정확도 \d+(\.\d)?%/.test(text) || !/2문제/.test(text)) throw new Error(`result: ${text.replace(/\n/g, ' ')}`);
|
||||
console.log(` typing: ${n} sentences typed for real; result: ${text.replace(/\n/g, ' ').slice(0, 160)}`);
|
||||
},
|
||||
},
|
||||
typingSpeed: {
|
||||
// 타수 비교 · 영어 · 긴글 · 1라운드: each types the passage line by line at their own pace; the next line shows at once
|
||||
// after Enter; the phone makes a typo on purpose and gets the lower accuracy; the round table shows 타수 and 정확도.
|
||||
game: 'typing',
|
||||
lobby: async (host) => {
|
||||
await host.getByRole('group', { name: '언어' }).getByRole('button', { name: '영어' }).click();
|
||||
await host.getByRole('group', { name: '대결 방식' }).getByRole('button', { name: '타수 비교' }).click();
|
||||
await host.getByRole('group', { name: '대결 종목' }).getByRole('button', { name: '긴글' }).click();
|
||||
await host.getByRole('group', { name: '주제' }).getByRole('button', { name: 'Twinkle, Twinkle, Little Star' }).click();
|
||||
await host.getByRole('group', { name: '라운드' }).getByRole('button', { name: '1', exact: true }).click();
|
||||
await host.getByText(/영어 · 타수 비교 · 긴글\(Twinkle, Twinkle, Little Star\) · 1라운드/).first().waitFor();
|
||||
},
|
||||
drive: async (pages) => {
|
||||
const [host, guest] = pages as [Page, Page];
|
||||
const lines: Record<string, number> = { host: 0, guest: 0 };
|
||||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||||
const until = Date.now() + 150_000;
|
||||
let shot = false;
|
||||
while (Date.now() < until && !(await over())) {
|
||||
let acted = false;
|
||||
for (const [who, p] of [['host', host], ['guest', guest]] as const) {
|
||||
const text = await typingTarget(p);
|
||||
if (!text) continue;
|
||||
// The passage is shown with the line I am on.
|
||||
await p.locator('.ty-passage li[data-s="cur"]').filter({ hasText: text }).first().waitFor({ timeout: 3000 });
|
||||
await typeLine(p, who === 'guest' && lines.guest === 0 ? text.replace(/a/, 'q') : text, 25);
|
||||
lines[who]!++;
|
||||
acted = true;
|
||||
if (!shot && lines.host === 2) {
|
||||
shot = true;
|
||||
await host.screenshot({ path: join(SHOTS, 'typing-speed-pc.png') });
|
||||
}
|
||||
}
|
||||
if (!acted) await host.waitForTimeout(200);
|
||||
}
|
||||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||||
await host.waitForTimeout(600);
|
||||
await host.screenshot({ path: join(SHOTS, 'typing-speed-result-pc.png') });
|
||||
const text = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||||
if (lines.host < 8 || !/정확도 100%/.test(text) || !/정확도 9\d(\.\d)?%/.test(text)) throw new Error(`lines ${JSON.stringify(lines)}; result: ${text.replace(/\n/g, ' ')}`);
|
||||
console.log(` typingSpeed: lines ${JSON.stringify(lines)}; result: ${text.replace(/\n/g, ' ').slice(0, 160)}`);
|
||||
},
|
||||
},
|
||||
typingSurvival: {
|
||||
// 서바이벌 · 틀렸을 때(목숨 2) · 단어 · 1라운드: the phone presses Enter on a wrong word twice — a heart goes the
|
||||
// first time (both screens), the second time it is out and the host is the survivor.
|
||||
game: 'typing',
|
||||
lobby: async (host) => {
|
||||
await host.getByRole('group', { name: '대결 방식' }).getByRole('button', { name: '서바이벌' }).click();
|
||||
await host.getByRole('group', { name: '목숨' }).getByRole('button', { name: '2개' }).click();
|
||||
await host.getByRole('group', { name: '대결 종목' }).getByRole('button', { name: '단어' }).click();
|
||||
await host.getByRole('group', { name: '라운드' }).getByRole('button', { name: '1', exact: true }).click();
|
||||
await host.getByText(/서바이벌\(틀렸을 때 · 목숨 2\) · 단어\(전체 주제\) · 1라운드/).first().waitFor();
|
||||
},
|
||||
drive: async (pages) => {
|
||||
const [host, guest] = pages as [Page, Page];
|
||||
let word: string | null = null;
|
||||
for (let t = 0; t < 100 && !word; t++) {
|
||||
word = await typingTarget(guest);
|
||||
if (!word) await guest.waitForTimeout(150);
|
||||
}
|
||||
if (!word) throw new Error('no word to type');
|
||||
await host.getByLabel('목숨 2개').first().waitFor();
|
||||
await typeLine(guest, '틀림');
|
||||
await guest.getByText('틀렸어요! 목숨 하나를 잃었어요').waitFor({ timeout: 3000 });
|
||||
await host.getByLabel('목숨 1개').first().waitFor({ timeout: 3000 });
|
||||
await guest.waitForTimeout(400);
|
||||
// Out of lives with only the host left: the round (and this one-round game) ends at once.
|
||||
await typeLine(guest, '또틀림');
|
||||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||||
await guest.screenshot({ path: join(SHOTS, 'typing-survival-out-phone.png') });
|
||||
const text = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||||
if (!/1등\s*방\s*방장\s*1승/.test(text)) throw new Error(`result: ${text.replace(/\n/g, ' ')}`);
|
||||
await host.getByRole('cell', { name: /친구 · 탈락/ }).first().waitFor();
|
||||
console.log(` typingSurvival: result: ${text.replace(/\n/g, ' ').slice(0, 120)}`);
|
||||
},
|
||||
},
|
||||
appleUnlimited: {
|
||||
// 2026-10-14: 무제한 — the stopwatch runs (tenths) and stops when I finish; 💡 힌트 shows a glowing box that adds up
|
||||
// to 10 (button off while it shows), using it clears the box; the result shows 걸린 시간 and 힌트 N번.
|
||||
|
||||
Reference in New Issue
Block a user