Files
jaengseung-made/lib/tarot/shuffle.ts
gahusb 53e8b592f0 feat(phase2): 타로 셔플·reference 순수 유틸 + 테스트
Fisher-Yates 셔플, 카드 픽 생성, 참고 블록/메타데이터 빌더 구현.
Task 4(interpret API)·Task 6(UI)에서 소비됨.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 20:40:30 +09:00

19 lines
556 B
TypeScript

import type { TarotCard } from './cards';
export type Pick = { card: TarotCard; position: string; reversed: boolean };
export function fisherYates<T>(input: T[]): T[] {
const a = [...input];
for (let i = a.length - 1; i > 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
export function buildShuffle(deck: TarotCard[], size: number): (TarotCard & { reversed: boolean })[] {
return fisherYates(deck)
.slice(0, size)
.map((c) => ({ ...c, reversed: Math.random() < 0.5 }));
}