72 lines
4.5 KiB
TypeScript
72 lines
4.5 KiB
TypeScript
/** 윷놀이 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
|
|
import type { Throw, YutView } from '@bg/games/yut';
|
|
import type { PublicUser } from '@bg/shared/lite';
|
|
|
|
const THROW_KO: Record<Throw, string> = { do: '도', gae: '개', geol: '걸', yut: '윷', mo: '모', backdo: '빽도' };
|
|
|
|
const pendingText = (v: YutView) => v.pending.map((t) => THROW_KO[t]).join(', ');
|
|
|
|
/** Why the current player throws (again): fresh turn, 윷·모, or a capture bonus. */
|
|
function throwReason(v: YutView): 'fresh' | 'yutmo' | 'capture' {
|
|
for (let i = v.log.length - 1; i >= 0; i--) {
|
|
const e = v.log[i]!;
|
|
if (e.type === 'bonusThrow') return 'capture';
|
|
if (e.type === 'thrown') return e.result === 'yut' || e.result === 'mo' ? 'yutmo' : 'fresh';
|
|
if (e.type === 'turnChanged' || e.type === 'nak' || e.type === 'moved') return 'fresh';
|
|
}
|
|
return 'fresh';
|
|
}
|
|
|
|
export function helpNow(v: YutView, me: string | null, players: Record<string, PublicUser>): string {
|
|
const goal = '내 말을 모두 먼저 한 바퀴 돌려 판 밖으로 내보내면(날) 이겨요.';
|
|
if (v.phase === 'finished') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.';
|
|
const turnSide = v.sides[v.turnSide];
|
|
const sideTag = turnSide ? `(${turnSide.name}${v.team ? '' : ' 말'})` : '';
|
|
const who = `${players[v.current]?.nickname ?? '다른 사람'}님`;
|
|
const doing = v.phase === 'throw' ? '윷을 던지는 중이에요.' : `말을 옮기는 중이에요. 모아 둔 결과: ${pendingText(v)}.`;
|
|
const mySide = v.mySide !== null ? v.sides[v.mySide] : undefined;
|
|
const progress = mySide ? `${v.team ? '우리 팀 말' : '내 말'}: 대기 ${mySide.home}개, 판 위 ${mySide.onBoard}개, 난 말 ${mySide.done}/${v.options.pieces}개.` : '';
|
|
|
|
if (!mySide || !me) return `${who}${sideTag} 차례예요. ${doing}\n${goal.replace('내 말을', '자기 편 말을')}`;
|
|
if (mySide.conceded.includes(me)) return `나는 기권해서 지금은 구경만 할 수 있어요. ${who}${sideTag} 차례예요.`;
|
|
|
|
if (v.current !== me) {
|
|
const ours = v.team && v.mySide === v.turnSide ? '(우리 팀)' : sideTag;
|
|
return `${who}${ours} 차례예요. ${doing} 기다려 주세요.\n${progress}`;
|
|
}
|
|
|
|
// My turn.
|
|
if (v.phase === 'throw') {
|
|
const reason = throwReason(v);
|
|
const lines: string[] = [];
|
|
if (reason === 'yutmo') lines.push('윷이나 모가 나와서 한 번 더 던져요! [🥢 한 번 더 던지기]를 눌러 주세요.');
|
|
else if (reason === 'capture') lines.push('상대 말을 잡아서 한 번 더 던져요! [🥢 한 번 더 던지기]를 눌러 주세요.');
|
|
else lines.push(`내 차례예요. [🥢 윷 던지기]를 눌러 윷을 던져요.`);
|
|
if (v.pending.length) lines.push(`모아 둔 결과(${pendingText(v)})는 다 던진 뒤에 원하는 순서로 써요.`);
|
|
else lines.push(`도 1칸, 개 2칸, 걸 3칸, 윷 4칸, 모 5칸 움직여요. 윷·모가 나오면 한 번 더 던져요.`);
|
|
lines.push(progress);
|
|
return lines.join('\n');
|
|
}
|
|
|
|
const moves = v.legalMoves ?? [];
|
|
const lines = [`내 차례예요. 모아 둔 결과(${pendingText(v)})를 하나씩 써서 말을 움직여요.`];
|
|
if (moves.length === 1) {
|
|
lines.push('지금 움직일 수 있는 방법이 하나뿐이에요. 초록색 [자동 이동] 버튼을 누르면 바로 움직여요.');
|
|
} else {
|
|
lines.push('아래 결과를 먼저 누르고(한 가지뿐이면 이미 골라져 있어요), 반짝이는 말을 누르면 갈 자리가 보여요. 한 번 더 누르면 움직여요.');
|
|
if (mySide.home > 0 && moves.some((m) => m.from === 'home')) lines.push(`새 말은 [대기 ${mySide.home}개] 버튼을 눌러 판에 올려요.`);
|
|
}
|
|
const usable = new Set(moves.map((m) => m.throw));
|
|
if (v.pending.some((t) => !usable.has(t))) lines.push('지금 쓸 곳이 없는 결과는 눌리지 않아요. 다른 결과를 먼저 써 보세요.');
|
|
const tips: string[] = [];
|
|
if (moves.some((m) => m.captures > 0)) {
|
|
const bonus = moves.some((m) => m.captures > 0 && (m.throw !== 'backdo' || v.options.backdoCaptureBonus));
|
|
tips.push(`상대 말을 잡을 수 있어요${bonus ? '(잡으면 한 번 더 던져요)' : ''}`);
|
|
}
|
|
if (moves.some((m) => m.finishes)) tips.push('판 밖으로 낼(날) 수 있는 말이 있어요');
|
|
if (moves.some((m) => m.stacks)) tips.push('내 말끼리 업어서 함께 움직일 수 있어요');
|
|
if (tips.length) lines.push(`${tips.join('. ')}.`);
|
|
lines.push(progress);
|
|
return lines.join('\n');
|
|
}
|