윷놀이: 증강 윷놀이 옵션 추가 (원작 증강 71개 + 추가 10개, 증강 탭·선택 창·능력·알까기·특수 승리)
- 엔진 aug.ts: 라운드·동시 비공개 증강 선택(1·6·12 등, 혼돈 모드, 후보 수, 제외 목록), 질문(거머리·접기·돌림판·투표·색 맞히기 등), 특수 말·보호막·함께 서기·함정/선물/똥/마늘/조준/지뢰, 특수 승리·탈락·순위, 컴퓨터(aug-bot.ts), 알까기 물리(physics.ts) - 화면: 방 설정 [게임 종류] + [증강 윷놀이] 탭(켜기/끄기·찾기), 증강 선택 창, 내 증강 쓰기, 증강 칸, 특수 승리 팝업, 안개, 알까기 조준 - 문서 docs/games/yut-augmented.md, 테스트 aug.test.ts 59개, e2e yut-aug Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,24 @@ import {
|
||||
type Sticks,
|
||||
type Throw,
|
||||
} from './board';
|
||||
import { AUGS, AUG_IDS } from './augments';
|
||||
import {
|
||||
augActivePlayers,
|
||||
augApply,
|
||||
augAutoAction,
|
||||
augLegalActions,
|
||||
augMoves,
|
||||
augSetup,
|
||||
augValidate,
|
||||
augView,
|
||||
type AugState,
|
||||
type PieceKind,
|
||||
type YutAugView,
|
||||
} from './aug';
|
||||
|
||||
export * from './board';
|
||||
export type { AugFx, AugObj, AugOwnedView, AugSideView, AugSpecialMove, AugUseOption, PieceKind, YutAugView } from './aug';
|
||||
export { PIECE_KO } from './aug';
|
||||
|
||||
// ---------------------------------------------------------------- options
|
||||
|
||||
@@ -78,23 +94,58 @@ export const yutOptionsSchema = z.object({
|
||||
.union([z.literal(15), z.literal(30), z.literal(60), z.literal(null)])
|
||||
.default(30)
|
||||
.meta({ title: '행동 제한 시간', labels: { 15: '15초', 30: '30초', 60: '60초', null: '무제한' } }),
|
||||
// ---- 증강 윷놀이 (docs/games/yut-augmented.md). 개인전 only.
|
||||
augmented: z.boolean().default(false).meta({ title: '증강 윷놀이' }),
|
||||
augChaos: z.boolean().default(false).meta({ title: '증강: 혼돈 모드(한 번에 2개씩 고름)' }),
|
||||
augRounds: z
|
||||
.enum(['standard', 'quick', 'many'])
|
||||
.default('standard')
|
||||
.meta({ title: '증강: 고르는 라운드', labels: { standard: '1·6·12라운드', quick: '1·4·8라운드', many: '1·3·5·7·9라운드' } }),
|
||||
augOffers: z
|
||||
.union([z.literal(2), z.literal(3), z.literal(4)])
|
||||
.default(3)
|
||||
.meta({ title: '증강: 후보 수', labels: { 2: '2개', 3: '3개', 4: '4개' } }),
|
||||
augOff: z.array(z.enum(AUG_IDS).meta({ labels: Object.fromEntries(AUG_IDS.map((id) => [id, AUGS[id].name])) })).max(AUG_IDS.length).default([]).meta({ title: '증강: 나오지 않게 뺀 증강' }),
|
||||
});
|
||||
export type YutOptions = z.infer<typeof yutOptionsSchema>;
|
||||
|
||||
const THROW_IDS = ['do', 'gae', 'geol', 'yut', 'mo', 'backdo'] as const;
|
||||
const NODE_NO = z.number().int().min(0).max(28);
|
||||
const PIECE_NO = z.number().int().min(0).max(39);
|
||||
|
||||
export const yutActionSchema = z.discriminatedUnion('type', [
|
||||
z.object({ type: z.literal('THROW') }),
|
||||
/** `pick`: 개돼지 (증강) chooses 도 or 개. */
|
||||
z.object({ type: z.literal('THROW'), pick: z.enum(['do', 'gae']).optional() }),
|
||||
z.object({
|
||||
type: z.literal('MOVE'),
|
||||
throwIndex: z.number().int().min(0).max(999),
|
||||
from: z.union([z.literal('home'), z.number().int().min(0).max(28)]),
|
||||
/** Which stack on `from` (any piece id in it) when one node holds several own stacks (`stacking = choose`). */
|
||||
piece: z.number().int().min(0).max(4).optional(),
|
||||
from: z.union([z.literal('home'), NODE_NO]),
|
||||
/**
|
||||
* Which stack on `from` (any piece id in it) when one node holds several own stacks (`stacking = choose`, 증강 special
|
||||
* pieces), or which waiting piece (증강 special pieces).
|
||||
*/
|
||||
piece: PIECE_NO.optional(),
|
||||
/** Take the other road at the starting fork (`forkRule = choose`). */
|
||||
alt: z.boolean().optional(),
|
||||
/** false = do not stack on own pieces there (`stacking = choose`). */
|
||||
stack: z.boolean().optional(),
|
||||
}),
|
||||
z.object({ type: z.literal('CONCEDE') }),
|
||||
// ---- 증강
|
||||
z.object({ type: z.literal('AUG_PICK'), aug: z.enum(AUG_IDS), target: z.enum(AUG_IDS).optional() }),
|
||||
z.object({ type: z.literal('AUG_ANSWER'), choice: z.union([z.number().int().min(0).max(99999), z.array(z.number().int().min(0).max(7)).max(8)]) }),
|
||||
z.object({
|
||||
type: z.literal('AUG_USE'),
|
||||
uid: z.number().int().min(0).max(99999),
|
||||
piece: PIECE_NO.optional(),
|
||||
node: NODE_NO.optional(),
|
||||
node2: NODE_NO.optional(),
|
||||
target: z.number().int().min(0).max(7).optional(),
|
||||
result: z.enum(THROW_IDS).optional(),
|
||||
angle: z.number().int().min(0).max(359).optional(),
|
||||
power: z.number().int().min(1).max(100).optional(),
|
||||
}),
|
||||
z.object({ type: z.literal('SPECIAL'), piece: PIECE_NO, to: z.union([z.literal('goal'), NODE_NO]) }),
|
||||
]);
|
||||
/** Client actions plus the system-only timer action (not in the schema). */
|
||||
export type YutAction = z.infer<typeof yutActionSchema> | { type: 'TIMEOUT' };
|
||||
@@ -118,6 +169,12 @@ export interface Piece {
|
||||
* that stack. Absent = the node's ordinary stack. Pieces on one node with the same key move together.
|
||||
*/
|
||||
group?: number;
|
||||
/** 증강: special piece kind (absent = ordinary piece). */
|
||||
kind?: PieceKind;
|
||||
/** 증강: survives one catch. */
|
||||
shield?: boolean;
|
||||
/** 증강: can't move before this round (잠깐!, 영역 전개). */
|
||||
frozenUntil?: number;
|
||||
}
|
||||
|
||||
export interface SideState {
|
||||
@@ -162,6 +219,8 @@ export interface YutRankEntry {
|
||||
side: SideId;
|
||||
finishedPieces: number;
|
||||
remainingDistance: number;
|
||||
/** 증강: why this rank (전원 완주, an augment, 탈락 …). */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface YutResult {
|
||||
@@ -179,12 +238,14 @@ export interface YutState {
|
||||
sides: SideState[];
|
||||
turnSide: SideId;
|
||||
current: PlayerId;
|
||||
phase: 'throw' | 'move' | 'finished';
|
||||
/** 증강 adds `aug` (everyone picks an augment) and `prompt` (someone answers an augment's question). */
|
||||
phase: 'throw' | 'move' | 'finished' | 'aug' | 'prompt';
|
||||
/** Throws still owed this turn (윷/모/잡기 bonus). 1 when the throw phase starts. */
|
||||
throwsOwed: number;
|
||||
/** Results collected this turn, in throw order. */
|
||||
pending: Throw[];
|
||||
lastThrow: { no: number; player: PlayerId; sticks: Sticks | null; result: Throw | 'nak' } | null;
|
||||
/** `sticks` has 4 entries in plain games (증강 may use 2~7); `results`: 이도류 gives two; `note`: which augment decided it. */
|
||||
lastThrow: { no: number; player: PlayerId; sticks: Sticks | boolean[] | null; result: Throw | 'nak'; results?: Throw[]; note?: string } | null;
|
||||
lastMove: YutMoveInfo | null;
|
||||
throwNo: number;
|
||||
moveNo: number;
|
||||
@@ -197,6 +258,8 @@ export interface YutState {
|
||||
nextRank: number;
|
||||
outCount: number;
|
||||
final: YutResult | null;
|
||||
/** 증강 윷놀이 only. */
|
||||
aug?: AugState;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- views
|
||||
@@ -231,6 +294,8 @@ export interface YutSideView {
|
||||
onBoard: number;
|
||||
done: number;
|
||||
remaining: number;
|
||||
/** 증강: pieces of this side (augments change it). */
|
||||
total?: number;
|
||||
}
|
||||
|
||||
export interface YutStackView {
|
||||
@@ -239,6 +304,10 @@ export interface YutStackView {
|
||||
count: number;
|
||||
/** Lowest piece id of the stack, only when one node holds several stacks of this side apart (`stacking = choose`). */
|
||||
piece?: number;
|
||||
/** 증강 */
|
||||
kind?: PieceKind;
|
||||
shield?: boolean;
|
||||
frozen?: boolean;
|
||||
}
|
||||
|
||||
export interface YutView {
|
||||
@@ -265,6 +334,8 @@ export interface YutView {
|
||||
log: GameEvent[];
|
||||
stats: YutStats;
|
||||
result: YutResult | null;
|
||||
/** 증강 윷놀이 only. */
|
||||
aug?: YutAugView;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- helpers
|
||||
@@ -284,7 +355,8 @@ export function playerRange(o: Pick<YutOptions, 'mode'>): { min: number; max: nu
|
||||
}
|
||||
|
||||
/** Player-count check that `playersFor` cannot express (팀전은 짝수만). */
|
||||
export function playerCountError(o: Pick<YutOptions, 'mode'>, n: number): string | null {
|
||||
export function playerCountError(o: Pick<YutOptions, 'mode'> & { augmented?: boolean }, n: number): string | null {
|
||||
if (o.mode === 'team' && o.augmented) return '증강 윷놀이는 개인전(2~4명)으로만 할 수 있어요.';
|
||||
if (o.mode === 'team') return n === 4 || n === 6 || n === 8 ? null : '팀전은 4명, 6명, 8명(짝수)으로만 할 수 있어요.';
|
||||
return n >= 2 && n <= 4 ? null : '개인전은 2~4명이 할 수 있어요.';
|
||||
}
|
||||
@@ -788,6 +860,11 @@ function refreshDeadline(s: YutState, now: number): void {
|
||||
s.deadlineAt = null;
|
||||
return;
|
||||
}
|
||||
if (s.phase === 'aug') {
|
||||
// everyone picks at once: a longer, shared clock (reading three cards takes a while)
|
||||
s.deadlineAt = now + Math.max(30, s.options.turnSeconds * 2) * 1000;
|
||||
return;
|
||||
}
|
||||
const away = (s.timeouts[s.current] ?? 0) >= AWAY_AFTER;
|
||||
s.deadlineAt = now + (away ? AWAY_MS : s.options.turnSeconds * 1000);
|
||||
}
|
||||
@@ -854,7 +931,11 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
outCount: 0,
|
||||
final: null,
|
||||
};
|
||||
startTurn(s, rng.int(nSides), []);
|
||||
if (options.augmented) {
|
||||
s.turnSide = rng.int(nSides);
|
||||
s.current = s.sides[s.turnSide]!.members[0]!;
|
||||
augSetup(s, rng, []);
|
||||
} else startTurn(s, rng.int(nSides), []);
|
||||
refreshDeadline(s, now);
|
||||
return s;
|
||||
},
|
||||
@@ -869,6 +950,9 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
if (side.finishedRank !== null) return fail('이미 말을 모두 냈어요.');
|
||||
return ok;
|
||||
}
|
||||
if (s.aug) return augValidate(s, actor, a);
|
||||
if (a.type === 'AUG_PICK' || a.type === 'AUG_ANSWER' || a.type === 'AUG_USE' || a.type === 'SPECIAL') return fail('증강 윷놀이에서만 쓸 수 있어요.');
|
||||
if (a.type === 'THROW' && a.pick) return fail('이 방은 결과를 고를 수 없어요.');
|
||||
if (actor !== s.current) return fail('지금은 다른 사람 차례예요.');
|
||||
switch (a.type) {
|
||||
case 'TIMEOUT':
|
||||
@@ -881,6 +965,7 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
const t = s.pending[a.throwIndex];
|
||||
if (!t) return fail('그 윷 결과는 없어요.');
|
||||
const o = s.options;
|
||||
if (a.from === 'home' && a.piece !== undefined) return fail('그 말은 움직일 수 없어요.');
|
||||
if (o.useOrder === 'thrown' && a.throwIndex !== 0) return fail('이 방은 던진 순서대로 써요. 맨 앞의 결과부터 써 주세요.');
|
||||
if (a.from === 'home') {
|
||||
if (!side.pieces.some((p) => p.status === 'home')) return fail('기다리는 말이 없어요.');
|
||||
@@ -910,12 +995,17 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
const s = structuredClone(prev);
|
||||
const events: GameEvent[] = [];
|
||||
s.turnSeq += 1;
|
||||
const act: Exclude<YutAction, { type: 'TIMEOUT' }> = a.type === 'TIMEOUT' ? autoAction(s) : a;
|
||||
const act: Exclude<YutAction, { type: 'TIMEOUT' }> = a.type === 'TIMEOUT' ? (s.aug ? augAutoAction(s, actor) : autoAction(s)) : a;
|
||||
if (a.type === 'TIMEOUT') {
|
||||
s.timeouts[actor] = (s.timeouts[actor] ?? 0) + 1;
|
||||
pushLog(s, events, { type: 'timeout', player: actor });
|
||||
if (s.timeouts[actor] === AWAY_AFTER) pushLog(s, events, { type: 'away', player: actor });
|
||||
} else if (a.type !== 'CONCEDE') s.timeouts[actor] = 0;
|
||||
if (s.aug) {
|
||||
augApply(s, actor, act, rng, events);
|
||||
refreshDeadline(s, now);
|
||||
return { state: s, events };
|
||||
}
|
||||
switch (act.type) {
|
||||
case 'THROW':
|
||||
doThrow(s, rng, events);
|
||||
@@ -926,6 +1016,8 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
case 'CONCEDE':
|
||||
doConcede(s, actor, events);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`yut: ${act.type} needs 증강 윷놀이`);
|
||||
}
|
||||
refreshDeadline(s, now);
|
||||
return { state: s, events };
|
||||
@@ -944,9 +1036,10 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
}
|
||||
stacks.sort((a, b) => a.node - b.node || (a.piece ?? -1) - (b.piece ?? -1));
|
||||
const mine = s.phase === 'move' && viewer !== null && viewer === s.current;
|
||||
const plans = mine ? legalPlans(s) : [];
|
||||
const plans = mine && !s.aug ? legalPlans(s) : [];
|
||||
const auto = mine && plans.length ? chooseAuto(s, plans) : null;
|
||||
return {
|
||||
const am = s.aug ? augMoves(s, viewer) : null;
|
||||
const base: YutView = {
|
||||
options: o,
|
||||
team: o.mode === 'team',
|
||||
me: mySide === null ? null : viewer,
|
||||
@@ -974,15 +1067,17 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
turnSeq: s.turnSeq,
|
||||
deadlineAt: s.deadlineAt,
|
||||
away: s.players.filter((p) => (s.timeouts[p] ?? 0) >= AWAY_AFTER),
|
||||
legalMoves: mine ? plans.map(toLegal) : null,
|
||||
suggested: auto ? (({ type: _t, ...rest }) => rest)(planAction(auto)) : null,
|
||||
legalMoves: am ? am.legal : mine ? plans.map(toLegal) : null,
|
||||
suggested: am ? am.suggested : auto ? (({ type: _t, ...rest }) => rest)(planAction(auto)) : null,
|
||||
log: s.log,
|
||||
stats: s.stats,
|
||||
result: s.final,
|
||||
};
|
||||
return s.aug ? augView(s, viewer, base) : base;
|
||||
},
|
||||
|
||||
activePlayers(s) {
|
||||
if (s.aug) return augActivePlayers(s);
|
||||
return s.phase === 'finished' ? [] : [s.current];
|
||||
},
|
||||
|
||||
@@ -991,6 +1086,7 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
},
|
||||
|
||||
timeoutPlayers(s) {
|
||||
if (s.aug) return augActivePlayers(s);
|
||||
return s.phase === 'finished' ? [] : [s.current];
|
||||
},
|
||||
|
||||
@@ -1016,7 +1112,9 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
return {
|
||||
ranking: [...groups.entries()].sort((a, b) => a[0] - b[0]).map(([, ps]) => ps),
|
||||
scores,
|
||||
scoreText: Object.fromEntries(Object.entries(scores).map(([p, n]) => [p, `난 말 ${n}개`])),
|
||||
scoreText: Object.fromEntries(
|
||||
f.ranking.flatMap((r) => r.players.map((p) => [p, r.reason && s.aug ? `난 말 ${r.finishedPieces}개 · ${r.reason}` : `난 말 ${r.finishedPieces}개`])),
|
||||
),
|
||||
summary: f.summary,
|
||||
reason: f.reason,
|
||||
};
|
||||
@@ -1024,6 +1122,7 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
|
||||
/** Test helper: THROW in the throw phase, every distinct legal MOVE in the move phase (CONCEDE is left out). */
|
||||
legalActions(s, p) {
|
||||
if (s.aug) return augLegalActions(s, p);
|
||||
if (s.phase === 'finished' || p !== s.current) return [];
|
||||
if (s.phase === 'throw') return [{ type: 'THROW' }];
|
||||
return legalPlans(s).map(planAction);
|
||||
|
||||
Reference in New Issue
Block a user