- 체스: 기물이 출발 칸에서 미끄러져 와 내려앉음(내가 끌어다 놓은 수는 제외), 캐슬링은 룩도 같이, 잡힌 기물(앙파상 폰 포함) 사라짐, 체크 칸 빛·말풍선 튀어나옴, 마지막 수 칸 살짝 나타남 - 체스 소리: 나무 기물 톡, 잡기, 캐슬링, 승진, 체크, 체크메이트 순간, 무르기, 기물 집기, 안 되는 칸 (fx.ts 순수 함수 + 테스트) - 장기: 묵직한 기물 미끄러짐·내려앉기, 잡힌 기물 사라짐, 장군 궁 자리 고동, 상차림 마·상 하나씩 튀어나옴 - 장기 소리: 두꺼운 나무 "딱", 잡기, 장군·멍군·빅장, 외통 순간, 한수쉼, 무르기, 상차림 놓기 (fx.ts + 테스트) - 장기 상차림 고르는 시간에 무제한(0) 추가, 방 설정 "자세한 설정"에서 30초·1분·3분·무제한 (기본 1분 그대로), 무제한이면 상차림 시계 숨김, 끊긴 사람만 접속 유예 뒤 자동 선택 - 쿼리도: 말 한 칸은 살짝 튀며, 점프는 높이 뛰어 넘음, 도착 칸 고리, 벽 내려앉기+먼지, 무르기로 빠진 벽 사라짐, 안 되는 벽 흔들림, 목표 도착 띠 깜빡임·금빛 고리 - 쿼리도 소리: 말 톡, 점프, 벽 끼우기, 안 되는 곳, 목표 도착, 무르기 - 상대·컴퓨터 수도 화면 변화로 같은 소리·움직임, 새로 열면 다시 재생 안 함, 숨은 탭 내 차례 소리는 방 화면에 맡김 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
3.0 KiB
TypeScript
69 lines
3.0 KiB
TypeScript
/**
|
|
* What to play and animate when the janggi view changes (pure, so it is unit-tested; no DOM or audio here).
|
|
* Everything is derived from two consecutive views, so the opponent's and the computer's moves get the same
|
|
* sound and motion as mine, and one change gives exactly one set of cues.
|
|
*/
|
|
import type { JanggiMove, JanggiView, Piece } from '@bg/games/janggi';
|
|
|
|
export type JanggiCue = 'move' | 'capture' | 'pass' | 'janggun' | 'meonggun' | 'bikjang' | 'mate' | 'undo';
|
|
|
|
/** The parts of the previous view the cues compare against. */
|
|
export interface JanggiPrev {
|
|
count: number;
|
|
inCheck: JanggiView['inCheck'];
|
|
bikjang: JanggiView['bikjang'];
|
|
}
|
|
|
|
type CueView = Pick<JanggiView, 'moveCount' | 'moves' | 'inCheck' | 'bikjang' | 'phase'> & { result: { reason: string } | null };
|
|
|
|
/** Sounds for one change of the move list. Empty when no move was added or taken back. */
|
|
export function janggiCues(p: JanggiPrev, v: CueView): JanggiCue[] {
|
|
if (v.moveCount === p.count) return [];
|
|
if (v.moveCount < p.count) return ['undo'];
|
|
const m = v.moves[v.moves.length - 1];
|
|
if (!m) return [];
|
|
const out: JanggiCue[] = [m.kind === 'pass' ? 'pass' : m.captured ? 'capture' : 'move'];
|
|
// After a ply the mover is never in check, so a side in check now was just checked by that ply.
|
|
if (v.phase === 'finished' && v.result?.reason === 'checkmate') out.push('mate');
|
|
else if (v.inCheck) out.push('janggun');
|
|
else if (p.inCheck && v.phase === 'playing') out.push('meonggun');
|
|
if (v.bikjang && !p.bikjang) out.push('bikjang');
|
|
return out;
|
|
}
|
|
|
|
const key = (q: { f: number; r: number }) => q.r * 9 + q.f;
|
|
const same = (a: Piece | null | undefined, b: Piece | null | undefined) => (!a && !b) || (!!a && !!b && a.side === b.side && a.kind === b.kind);
|
|
|
|
export interface JanggiMotion {
|
|
/** Board index the moved piece now stands on, and where it came from. */
|
|
to: number;
|
|
from: number;
|
|
/** The piece it took (drawn fading on the same point). */
|
|
captured: Piece | null;
|
|
}
|
|
|
|
/** Motion for one ply forward (`before` = board one ply earlier, null on page load / undo / several plies at once). */
|
|
export function janggiMotion(before: readonly (Piece | null)[] | null, board: readonly (Piece | null)[], last: JanggiMove | undefined): JanggiMotion | null {
|
|
if (!before || !last || last.kind !== 'move') return null;
|
|
const to = key(last.to);
|
|
const from = key(last.from);
|
|
if (!board[to] || board[from]) return null;
|
|
const prev = before[to];
|
|
return { to, from, captured: prev && prev.side !== board[to]!.side ? prev : null };
|
|
}
|
|
|
|
/**
|
|
* Pieces that appeared during 상차림 (a 마·상 arrangement put on the board). Only a pure addition counts, so an undo
|
|
* or a move is never mistaken for it.
|
|
*/
|
|
export function addedPieces(before: readonly (Piece | null)[] | null, board: readonly (Piece | null)[]): number[] {
|
|
if (!before) return [];
|
|
const out: number[] = [];
|
|
for (let i = 0; i < board.length; i++) {
|
|
if (before[i]) {
|
|
if (!same(before[i], board[i])) return [];
|
|
} else if (board[i]) out.push(i);
|
|
}
|
|
return out;
|
|
}
|