윷놀이: 증강 윷놀이 옵션 추가 (원작 증강 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:
@@ -18,6 +18,8 @@
|
||||
"./tichu/combo": "./src/tichu/combo.ts",
|
||||
"./case-file/types": "./src/case-file/types.ts",
|
||||
"./castles-of-burgundy/data": "./src/castles-of-burgundy/data.ts",
|
||||
"./yut/board": "./src/yut/board.ts",
|
||||
"./yut/augments": "./src/yut/augments.ts",
|
||||
"./*": "./src/*/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
179
packages/games/src/yut/aug-bot.ts
Normal file
179
packages/games/src/yut/aug-bot.ts
Normal file
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* 증강 윷놀이 computer decisions: which augment to pick, how to answer prompts, and when to use an ability.
|
||||
* Returns null to fall back to the plain 윷놀이 bot (throwing and moving).
|
||||
*/
|
||||
import { AUGS, type AugId } from './augments';
|
||||
import { NODE_POS, remainingDistance, type NodeId } from './board';
|
||||
import type { YutAction, YutView } from './index';
|
||||
|
||||
/** Rough worth of each augment for a computer (higher = pick first). */
|
||||
const VALUE: Partial<Record<AugId, number>> = {
|
||||
comeback: 9, notme: 8, combo: 7, sleight: 7, tiger: 7, vanguard: 7, thief: 6, bigred: 6, truck: 6, baduk: 6, doberman: 6, shield: 6,
|
||||
friendshield: 6, dokkaebi: 6, marathon: 6, speedrun: 6, piggyback: 6, summon: 6, coup: 6, murder: 6, throwyut: 6, peace: 5,
|
||||
catlover: 5, turtle: 5, revenge: 5, fisherman: 5, kim: 5, party: 5, burden: 5, equiv: 5, triple7: 5, wait: 5, duel: 5, doggy: 5,
|
||||
score: 5, twins: 5, swap: 5, shortcut: 5, cannon: 5, poison: 4, jajinmori: 4, pawn: 4, queen: 4, bear: 4, treason: 4, echo: 4,
|
||||
domain: 4, getoff: 4, moordo: 4, leech: 4, illusion: 4, alkkagi: 4, four: 4, mine: 4, teleport: 4, cannibal: 3, alone: 3,
|
||||
nofriends: 3, plan: 3, necro: 3, cancel: 3, whoami: 3, roulette: 3, fold: 3, excess: 3, dual: 3, fog: 3, sniper: 3, ox: 3,
|
||||
detective: 3, delivery: 3, storm: 3, sacrifice: 3, moonwalk: 3, lastdance: 1, chosen: 2, objection: 2, timetravel: 2, cat: 1,
|
||||
};
|
||||
|
||||
type A = YutAction;
|
||||
|
||||
export function augBotAction(view: YutView, legal: A[], random: () => number): A | null {
|
||||
const aug = view.aug!;
|
||||
const me = view.mySide;
|
||||
const has = (t: string) => legal.filter((a) => a.type === t);
|
||||
// ---- picking an augment
|
||||
const picks = has('AUG_PICK') as Extract<A, { type: 'AUG_PICK' }>[];
|
||||
if (picks.length) {
|
||||
const progress = me === null ? 0 : standing(view, me);
|
||||
const worth = (id: AugId) => {
|
||||
let v = VALUE[id] ?? 3;
|
||||
if (id === 'bronze') v = progress >= 0.6 ? 2 : 8; // a sure 3rd place is good when behind
|
||||
if (id === 'cancel') v = (aug.sides.some((x) => x.id !== me && x.augs.some((o) => ['four', 'ox', 'score', 'catlover', 'coup', 'summon', 'queen', 'kim', 'bear', 'domain', 'marathon'].includes(o.id))) ? 7 : 2);
|
||||
return v + random() * 1.5;
|
||||
};
|
||||
const best = picks.reduce((x, y) => (worth(y.aug) > worth(x.aug) ? y : x));
|
||||
if (best.aug === 'detective' || best.aug === 'delivery') {
|
||||
const same = picks.filter((p) => p.aug === best.aug);
|
||||
return same.reduce((x, y) => ((VALUE[y.target!] ?? 3) > (VALUE[x.target!] ?? 3) ? y : x));
|
||||
}
|
||||
return best;
|
||||
}
|
||||
// ---- answering a prompt
|
||||
const answers = has('AUG_ANSWER') as Extract<A, { type: 'AUG_ANSWER' }>[];
|
||||
if (answers.length) {
|
||||
const pr = aug.prompt;
|
||||
if (!pr) return answers[0]!;
|
||||
const leader = [...view.sides].filter((x) => x.id !== me && !x.out && x.finishedRank === null).sort((p, q) => q.done - p.done || p.remaining - q.remaining)[0]?.id;
|
||||
const trailer = [...view.sides].filter((x) => x.id !== me && !x.out && x.finishedRank === null).sort((p, q) => p.done - q.done || q.remaining - p.remaining)[0]?.id;
|
||||
const byChoice = (v: number | undefined) => answers.find((a) => a.choice === v) ?? answers[Math.floor(random() * answers.length)]!;
|
||||
switch (pr.kind) {
|
||||
case 'leech':
|
||||
return byChoice(leader);
|
||||
case 'vote':
|
||||
return byChoice(leader);
|
||||
case 'duel':
|
||||
return byChoice(trailer);
|
||||
case 'roulette':
|
||||
return answers[random() < 0.5 ? 0 : answers.length - 1]!;
|
||||
case 'plan': {
|
||||
const order = [...view.sides].sort((p, q) => (p.finishedRank ?? 99) - (q.finishedRank ?? 99) || +p.out - +q.out || q.done - p.done || p.remaining - q.remaining).map((x) => x.id);
|
||||
return { type: 'AUG_ANSWER', choice: order } as A;
|
||||
}
|
||||
case 'illusion':
|
||||
case 'thief': {
|
||||
const opts = pr.choices ?? [];
|
||||
const val = (label: string) => {
|
||||
const name = label.split(' · ')[1] ?? '';
|
||||
const id = (Object.keys(VALUE) as AugId[]).find((k) => AUG_NAME[k] === name);
|
||||
return id ? (VALUE[id] ?? 3) : 3;
|
||||
};
|
||||
const top = opts.reduce((x, y) => (val(y.label) > val(x.label) ? y : x), opts[0]!);
|
||||
return byChoice(top?.value);
|
||||
}
|
||||
default:
|
||||
return answers[Math.floor(random() * answers.length)]!;
|
||||
}
|
||||
}
|
||||
// ---- my turn: abilities before throwing / moving
|
||||
const uses = has('AUG_USE') as Extract<A, { type: 'AUG_USE' }>[];
|
||||
const opt = (a: Extract<A, { type: 'AUG_USE' }>) => aug.uses.find((u) => u.uid === a.uid && u.action.piece === a.piece && u.action.node === a.node && u.action.node2 === a.node2 && u.action.target === a.target && u.action.result === a.result);
|
||||
const idOf = (a: Extract<A, { type: 'AUG_USE' }>) => aug.sides.find((x) => x.id === me)?.augs.find((o) => o.uid === a.uid)?.id;
|
||||
let bestUse: { a: A; v: number } | null = null;
|
||||
const consider = (a: A, v: number) => {
|
||||
if (v > 0 && (!bestUse || v > bestUse.v)) bestUse = { a, v };
|
||||
};
|
||||
const leaderSide = [...view.sides].filter((x) => x.id !== me && !x.out && x.finishedRank === null).sort((p, q) => q.done - p.done || p.remaining - q.remaining)[0]?.id;
|
||||
for (const u of uses) {
|
||||
const id = idOf(u);
|
||||
const o = opt(u);
|
||||
if (!id) continue;
|
||||
switch (id) {
|
||||
case 'combo':
|
||||
consider(u, (o?.kills ?? 0) >= 3 ? 10 + (o?.kills ?? 0) : 0);
|
||||
break;
|
||||
case 'truck':
|
||||
case 'baduk':
|
||||
consider(u, (o?.kills ?? 0) > 0 ? 8 + (o?.kills ?? 0) : 0);
|
||||
break;
|
||||
case 'sniper':
|
||||
consider(u, (o?.kills ?? 0) >= 2 ? 3 + (o?.kills ?? 0) : 0);
|
||||
break;
|
||||
case 'alkkagi': {
|
||||
if (u.angle === undefined) break;
|
||||
// aim at the nearest enemy stack from this stack
|
||||
if (o?.at === undefined || o.at === 'home') break;
|
||||
const [mx, my] = NODE_POS[o.at]!;
|
||||
const enemy = view.stacks.filter((st) => st.side !== me && st.side >= 0).map((st) => ({ st, d: Math.hypot(NODE_POS[st.node]![0] - mx, NODE_POS[st.node]![1] - my) })).sort((p, q) => p.d - q.d)[0];
|
||||
if (!enemy || enemy.d > 35) break;
|
||||
const [ex, ey] = NODE_POS[enemy.st.node]!;
|
||||
const angle = Math.round(((Math.atan2(ey - my, ex - mx) * 180) / Math.PI + 360) % 360) % 360;
|
||||
consider({ ...u, angle, power: 80 } as A, 7);
|
||||
break;
|
||||
}
|
||||
case 'doberman': {
|
||||
const n = Number(/(\d+)/.exec(o?.label ?? '')?.[1] ?? 0);
|
||||
consider(u, n >= 4 ? 6 : 0);
|
||||
break;
|
||||
}
|
||||
case 'sleight':
|
||||
consider(u, u.result === 'mo' ? 6 : u.result === 'yut' ? 5 : 0);
|
||||
break;
|
||||
case 'vanguard':
|
||||
case 'cannon':
|
||||
consider(u, (o?.label ?? '').startsWith('대기') ? 0 : 6);
|
||||
break;
|
||||
case 'dokkaebi':
|
||||
case 'pawn':
|
||||
case 'marathon':
|
||||
case 'fog':
|
||||
case 'mine':
|
||||
case 'twins':
|
||||
case 'shield':
|
||||
consider(u, 5);
|
||||
break;
|
||||
case 'throwyut':
|
||||
consider(u, u.target === leaderSide ? 6 : 1);
|
||||
break;
|
||||
case 'necro':
|
||||
consider(u, 4);
|
||||
break;
|
||||
case 'poison':
|
||||
consider(u, random() < 0.25 ? 4 : 0);
|
||||
break;
|
||||
case 'domain':
|
||||
consider(u, random() < 0.2 ? 3 : 0);
|
||||
break;
|
||||
case 'swap': {
|
||||
if (o?.at === undefined || o.at === 'home' || u.node === undefined) break;
|
||||
const gain = remainingDistance(o.at, view.options.finishRule) - remainingDistance(u.node as NodeId, view.options.finishRule);
|
||||
consider(u, gain >= 5 ? 5 : 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// special pieces: a free step forward (or a catch) is always worth it
|
||||
for (const sp of has('SPECIAL') as Extract<A, { type: 'SPECIAL' }>[]) {
|
||||
const m = aug.specials.find((x) => x.piece === sp.piece && x.to === sp.to);
|
||||
if (!m) continue;
|
||||
const fwd = m.to === 'goal' || m.from === 'home' || remainingDistance(m.to as NodeId, view.options.finishRule) < remainingDistance(m.from as NodeId, view.options.finishRule);
|
||||
consider(sp, m.captures ? 9 : m.to === 'goal' ? 8 : fwd ? 4 + random() : 0);
|
||||
}
|
||||
if (bestUse) return (bestUse as { a: A }).a;
|
||||
// 개돼지: pick the result
|
||||
const throws = has('THROW') as Extract<A, { type: 'THROW' }>[];
|
||||
if (throws.length > 1) return throws.find((t) => t.pick === 'gae') ?? throws[0]!;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 0 (last) .. 1 (first): how well I'm doing by finished pieces and distance. */
|
||||
function standing(view: YutView, me: number): number {
|
||||
const live = view.sides.filter((x) => !x.out && x.finishedRank === null);
|
||||
if (live.length <= 1) return 1;
|
||||
const sorted = [...live].sort((p, q) => q.done - p.done || p.remaining - q.remaining);
|
||||
const i = sorted.findIndex((x) => x.id === me);
|
||||
return i < 0 ? 0 : 1 - i / (sorted.length - 1);
|
||||
}
|
||||
|
||||
const AUG_NAME = Object.fromEntries(Object.values(AUGS).map((a) => [a.id, a.name])) as Record<AugId, string>;
|
||||
693
packages/games/src/yut/aug.test.ts
Normal file
693
packages/games/src/yut/aug.test.ts
Normal file
@@ -0,0 +1,693 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { SeededRng, playoutSeeds, randomPlayout, seedN, type Rng } from '@bg/engine';
|
||||
import { botPlayout } from '../bots/playout';
|
||||
import { decideBotAction } from '../bots/index';
|
||||
import { augGiveForTest } from './aug';
|
||||
import { AUG_IDS, AUGS, type AugId } from './augments';
|
||||
import { yut, type NodeId, type Throw, type YutAction, type YutOptions, type YutState } from './index';
|
||||
|
||||
// ---------------------------------------------------------------- helpers
|
||||
|
||||
class Script implements Rng {
|
||||
private vals: number[];
|
||||
constructor(vals: number[]) {
|
||||
this.vals = [...vals];
|
||||
}
|
||||
next(): number {
|
||||
const v = this.vals.shift();
|
||||
if (v === undefined) throw new Error('script exhausted');
|
||||
return v;
|
||||
}
|
||||
int(n: number): number {
|
||||
return Math.floor(this.next() * n);
|
||||
}
|
||||
shuffle<T>(a: readonly T[]): T[] {
|
||||
return [...a];
|
||||
}
|
||||
}
|
||||
const F = 0; // 배
|
||||
const R = 0.99; // 등
|
||||
const STICKS: Record<Throw, number[]> = { do: [R, F, R, R], backdo: [F, R, R, R], gae: [F, F, R, R], geol: [F, F, F, R], yut: [F, F, F, F], mo: [R, R, R, R] };
|
||||
const script = (...ts: Throw[]) => new Script(ts.flatMap((t) => STICKS[t]));
|
||||
const PLAYERS = ['A', 'B', 'C', 'D'];
|
||||
|
||||
/** 증강 game with the selection skipped: side 0 to throw, nobody has an augment yet. */
|
||||
function make(n = 2, opts: Partial<YutOptions> = {}): YutState {
|
||||
const options = yut.optionsSchema.parse({ augmented: true, ...opts });
|
||||
const s = yut.setup({ players: PLAYERS.slice(0, n), options, rng: SeededRng.fromSeed(seedN(3)), now: 0 });
|
||||
const a = s.aug!;
|
||||
a.select = null;
|
||||
a.selNo = 1;
|
||||
a.pendingBegin = false;
|
||||
a.firstSide = 0;
|
||||
Object.assign(s, { turnSide: 0, current: 'A', phase: 'throw', throwsOwed: 1, pending: [] });
|
||||
return s;
|
||||
}
|
||||
const give = (s: YutState, side: number, id: AugId, rng: Rng = SeededRng.fromSeed(seedN(9)), target?: AugId) => augGiveForTest(s, side, id, rng, target);
|
||||
function put(s: YutState, side: number, piece: number, node: NodeId, trail: NodeId[] = [node]): void {
|
||||
Object.assign(s.sides[side]!.pieces[piece]!, { status: 'board', node, trail, lapped: node === 0 });
|
||||
}
|
||||
function act(s: YutState, actor: string, a: YutAction, rng: Rng = SeededRng.fromSeed(seedN(5))): YutState {
|
||||
const v = yut.validate(s, actor, a);
|
||||
if (!v.ok) throw new Error(`${actor} ${JSON.stringify(a)}: ${v.reason}`);
|
||||
return yut.apply(s, actor, a, { rng, now: 1000 }).state;
|
||||
}
|
||||
const moving = (s: YutState, pending: Throw[]) => Object.assign(s, { phase: 'move', throwsOwed: 0, pending });
|
||||
const nodesOf = (s: YutState, side: number) => s.sides[side]!.pieces.map((p) => (p.status === 'board' ? p.node : p.status));
|
||||
const uidOf = (s: YutState, side: number, id: AugId) => s.aug!.sides[side]!.augs.find((o) => o.id === id)!.uid;
|
||||
|
||||
// ---------------------------------------------------------------- options & selection
|
||||
|
||||
describe('증강 윷놀이: options and selection', () => {
|
||||
test('개인전 only; plain games have no aug state', () => {
|
||||
expect(yut.playerCountError!(yut.optionsSchema.parse({ augmented: true, mode: 'team' }), 4)).toContain('개인전');
|
||||
const plain = yut.setup({ players: ['A', 'B'], options: yut.defaultOptions, rng: SeededRng.fromSeed(seedN(1)), now: 0 });
|
||||
expect(plain.aug).toBeUndefined();
|
||||
expect(yut.view(plain, 'A').aug).toBeUndefined();
|
||||
});
|
||||
|
||||
test('the game opens with everyone picking from private offers at once', () => {
|
||||
const s = yut.setup({ players: ['A', 'B', 'C'], options: yut.optionsSchema.parse({ augmented: true }), rng: SeededRng.fromSeed(seedN(2)), now: 0 });
|
||||
expect(s.phase).toBe('aug');
|
||||
expect(yut.activePlayers(s).sort()).toEqual(['A', 'B', 'C']);
|
||||
const va = yut.view(s, 'A').aug!;
|
||||
const vb = yut.view(s, 'B').aug!;
|
||||
expect(va.select!.offers).toHaveLength(3);
|
||||
// first selection: 범용 + 시작 전용 only
|
||||
for (const id of va.select!.offers) expect(['any', 'start']).toContain(AUGS[id].tier);
|
||||
// nobody sees someone else's offers
|
||||
expect(JSON.stringify(yut.view(s, null).aug!.select!.offers)).toBe('[]');
|
||||
expect(vb.select!.offers).toEqual(s.aug!.select!.offers['1']!);
|
||||
let t = s;
|
||||
for (const p of ['A', 'B', 'C']) {
|
||||
const offers = t.aug!.select!.offers[String(['A', 'B', 'C'].indexOf(p))]!;
|
||||
const id = offers.find((x) => x !== 'objection' && x !== 'detective' && x !== 'delivery') ?? offers[0]!;
|
||||
const legal = yut.legalActions!(t, p).find((a) => a.type === 'AUG_PICK' && a.aug === id)!;
|
||||
t = act(t, p, legal);
|
||||
}
|
||||
expect(['throw', 'prompt', 'finished']).toContain(t.phase);
|
||||
expect(t.aug!.sides.every((x) => x.augs.length === 1)).toBe(true);
|
||||
});
|
||||
|
||||
test('augOff: excluded augments are never offered', () => {
|
||||
const off = AUG_IDS.filter((id) => id !== 'cat' && id !== 'tiger' && id !== 'shield' && id !== 'kim');
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const s = yut.setup({ players: ['A', 'B'], options: yut.optionsSchema.parse({ augmented: true, augOff: off }), rng: SeededRng.fromSeed(seedN(40 + i)), now: 0 });
|
||||
for (const k of ['0', '1']) for (const id of s.aug!.select!.offers[k]!) expect(['cat', 'tiger', 'shield', 'kim']).toContain(id);
|
||||
}
|
||||
});
|
||||
|
||||
test('명탐정 voids the same augment picked by someone else in that selection', () => {
|
||||
const s = yut.setup({ players: ['A', 'B'], options: yut.optionsSchema.parse({ augmented: true }), rng: SeededRng.fromSeed(seedN(2)), now: 0 });
|
||||
s.aug!.select!.offers = { '0': ['detective', 'cat', 'fog'], '1': ['tiger', 'cat', 'fog'] };
|
||||
let t = act(s, 'A', { type: 'AUG_PICK', aug: 'detective', target: 'tiger' });
|
||||
expect(yut.validate(t, 'B', { type: 'AUG_PICK', aug: 'detective' }).ok).toBe(false);
|
||||
t = act(t, 'B', { type: 'AUG_PICK', aug: 'tiger' });
|
||||
expect(t.aug!.sides[1]!.augs[0]).toMatchObject({ id: 'tiger', voided: true });
|
||||
expect(yut.view(t, 'A').aug!.sides[1]!.augs[0]!.voided).toBe(true);
|
||||
});
|
||||
|
||||
test('이의있음! rerolls the offers and is not kept', () => {
|
||||
const s = yut.setup({ players: ['A', 'B'], options: yut.optionsSchema.parse({ augmented: true }), rng: SeededRng.fromSeed(seedN(2)), now: 0 });
|
||||
s.aug!.select!.offers['0'] = ['objection', 'cat', 'fog'];
|
||||
const t = act(s, 'A', { type: 'AUG_PICK', aug: 'objection' });
|
||||
const offers = t.aug!.select!.offers['0']!;
|
||||
expect(offers).toHaveLength(3);
|
||||
expect(offers).not.toContain('objection');
|
||||
expect(offers).not.toContain('cat');
|
||||
expect(t.aug!.select!.left['0']).toBe(1);
|
||||
});
|
||||
|
||||
test('간택: a 고양이 among the offers must be taken', () => {
|
||||
const s = make(2);
|
||||
give(s, 1, 'chosen');
|
||||
s.aug!.select = { no: 2, tier: 'mid', offers: { '0': ['cat', 'fog', 'tiger'], '1': ['fog', 'tiger', 'coup'] }, left: { '0': 1, '1': 1 }, picks: [] };
|
||||
s.phase = 'aug';
|
||||
expect(yut.validate(s, 'A', { type: 'AUG_PICK', aug: 'fog' }).ok).toBe(false);
|
||||
expect(yut.validate(s, 'A', { type: 'AUG_PICK', aug: 'cat' }).ok).toBe(true);
|
||||
expect(yut.view(s, 'A').aug!.select!.forced).toBe('cat');
|
||||
});
|
||||
|
||||
test('혼돈 모드: two picks per selection', () => {
|
||||
const s = yut.setup({ players: ['A', 'B'], options: yut.optionsSchema.parse({ augmented: true, augChaos: true }), rng: SeededRng.fromSeed(seedN(2)), now: 0 });
|
||||
expect(s.aug!.select!.left).toEqual({ '0': 2, '1': 2 });
|
||||
});
|
||||
|
||||
test('a new selection opens when round 6 starts, with 중간 전용 augments', () => {
|
||||
const s = make(2);
|
||||
s.aug!.round = 5;
|
||||
s.turnSide = 1;
|
||||
s.current = 'B';
|
||||
// B ends the round: throw 도, move in → next turn is A in round 6
|
||||
let t = act(s, 'B', { type: 'THROW' }, script('do'));
|
||||
t = act(t, 'B', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(t.aug!.round).toBe(6);
|
||||
expect(t.phase).toBe('aug');
|
||||
expect(t.aug!.select!.tier).toBe('mid');
|
||||
for (const id of t.aug!.select!.offers['0']!) expect(['any', 'mid']).toContain(AUGS[id].tier);
|
||||
});
|
||||
|
||||
test('timeouts pick for whoever is late', () => {
|
||||
const s = yut.setup({ players: ['A', 'B'], options: yut.optionsSchema.parse({ augmented: true }), rng: SeededRng.fromSeed(seedN(2)), now: 0 });
|
||||
expect(s.deadlineAt).toBe(60_000);
|
||||
let t = yut.apply(s, 'A', { type: 'TIMEOUT' }, { rng: SeededRng.fromSeed(seedN(1)), now: 1 }).state;
|
||||
expect(t.aug!.select!.left['0']).toBe(0);
|
||||
expect(t.aug!.select!.left['1']).toBe(1);
|
||||
t = yut.apply(t, 'B', { type: 'TIMEOUT' }, { rng: SeededRng.fromSeed(seedN(1)), now: 2 }).state;
|
||||
expect(t.phase).not.toBe('aug');
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- throwing
|
||||
|
||||
describe('증강 윷놀이: throws', () => {
|
||||
test('개돼지 picks 도 or 개', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'doggy');
|
||||
expect(yut.view(s, 'A').aug!.pickThrow).toBe(true);
|
||||
const t = act(s, 'A', { type: 'THROW', pick: 'do' });
|
||||
expect(t.lastThrow!.result).toBe('do');
|
||||
});
|
||||
|
||||
test('이도류 throws two pairs: two results, 모 becomes 도', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'dual');
|
||||
const t = act(s, 'A', { type: 'THROW' }, new Script([R, R, F, F]));
|
||||
expect(t.lastThrow!.results).toEqual(['do', 'gae']);
|
||||
expect(t.phase).toBe('move');
|
||||
});
|
||||
|
||||
test('과유불급: six sticks, all 배 → out', () => {
|
||||
const s = make(3);
|
||||
give(s, 0, 'excess');
|
||||
expect(s.aug!.sides[0]!.sticks).toBe(6);
|
||||
const t = act(s, 'A', { type: 'THROW' }, new Script([F, F, F, F, F, F]));
|
||||
expect(t.sides[0]!.out).toBe(true);
|
||||
expect(t.current).toBe('B');
|
||||
const u = act(make(2), 'A', { type: 'THROW' }, new Script([F, F, F, F]));
|
||||
expect(u.lastThrow!.result).toBe('yut');
|
||||
});
|
||||
|
||||
test('손은 눈보다 빠르다 throws the chosen result', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'sleight');
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'sleight'), result: 'mo' });
|
||||
expect(t.pending).toEqual(['mo']);
|
||||
expect(t.phase).toBe('throw'); // 모: one more throw
|
||||
expect(yut.view(t, 'A').aug!.uses.some((u) => u.id === 'sleight')).toBe(false);
|
||||
});
|
||||
|
||||
test('자진모리 장단: every second 걸 adds a 개', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'jajinmori');
|
||||
s.aug!.sides[0]!.augs[0]!.n = 1;
|
||||
const t = act(s, 'A', { type: 'THROW' }, script('geol'));
|
||||
expect(t.pending).toEqual(['geol', 'gae']);
|
||||
});
|
||||
|
||||
test('도베르만: 개 coins become 모', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'doberman');
|
||||
s.aug!.sides[0]!.thrown.gae = 5;
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'doberman') });
|
||||
expect(t.aug!.sides[0]!.dogCoins).toBe(5);
|
||||
t = act(t, 'A', { type: 'THROW' }, new Script([]));
|
||||
expect(t.lastThrow!.result).toBe('mo');
|
||||
expect(t.aug!.sides[0]!.dogCoins).toBe(3);
|
||||
});
|
||||
|
||||
test('독이 든 성배: three more throws, a 모 that turn is out', () => {
|
||||
const s = make(3);
|
||||
give(s, 0, 'poison');
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'poison') });
|
||||
expect(t.throwsOwed).toBe(4);
|
||||
t = act(t, 'A', { type: 'THROW' }, script('mo'));
|
||||
expect(t.sides[0]!.out).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- moving & catching
|
||||
|
||||
describe('증강 윷놀이: moves and catches', () => {
|
||||
test('천마군림보 - 달걸음: pieces walk the other way round', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'moonwalk');
|
||||
moving(s, ['gae']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 0)[0]).toBe(18);
|
||||
});
|
||||
|
||||
test('변환: 선봉장 adds a step to every forward move while it is on the board', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'vanguard');
|
||||
put(s, 0, 0, 3);
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'vanguard'), piece: 0 });
|
||||
moving(t, ['do']);
|
||||
t = act(t, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 0)[1]).toBe(2);
|
||||
});
|
||||
|
||||
test('평화 협정: no catching either way, the pieces stand together', () => {
|
||||
const s = make();
|
||||
give(s, 1, 'peace');
|
||||
put(s, 1, 0, 3);
|
||||
moving(s, ['geol']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 1)[0]).toBe(3);
|
||||
expect(nodesOf(t, 0)[0]).toBe(3);
|
||||
expect(yut.view(t, 'A').stacks.filter((st) => st.node === 3)).toHaveLength(2);
|
||||
});
|
||||
|
||||
test('천상의 보호막 saves a stack once', () => {
|
||||
const s = make();
|
||||
give(s, 1, 'shield');
|
||||
put(s, 1, 0, 3);
|
||||
s.sides[1]!.pieces[0]!.shield = true;
|
||||
moving(s, ['geol', 'geol']);
|
||||
let t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 1)[0]).toBe(3);
|
||||
expect(t.phase).toBe('move'); // nothing caught → no bonus throw
|
||||
t = act(t, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 1)[0]).toBe('home');
|
||||
});
|
||||
|
||||
test('프랜드 실드: a caught stack loses only one piece', () => {
|
||||
const s = make();
|
||||
give(s, 1, 'friendshield');
|
||||
put(s, 1, 0, 3);
|
||||
put(s, 1, 1, 3);
|
||||
put(s, 1, 2, 3);
|
||||
moving(s, ['geol']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 1).filter((n) => n === 3)).toHaveLength(2);
|
||||
});
|
||||
|
||||
test('카니발리즘: landing on my own piece catches it and throws again', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'cannibal');
|
||||
put(s, 0, 0, 3);
|
||||
moving(s, ['geol']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 0).filter((n) => n === 3)).toHaveLength(1);
|
||||
expect(t.phase).toBe('throw');
|
||||
});
|
||||
|
||||
test('히히 똥!: other pieces stop on the poop', () => {
|
||||
const s = make();
|
||||
s.aug!.objs.push({ kind: 'poop', node: 2, owner: 1 });
|
||||
moving(s, ['yut']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 0)[0]).toBe(2);
|
||||
});
|
||||
|
||||
test('말이오? 파티: 해골 catches, 선물 moves on, the owner is immune to its traps', () => {
|
||||
const s = make();
|
||||
s.aug!.objs.push({ kind: 'skull', node: 3, owner: 1 }, { kind: 'gift', node: 2, owner: 1 });
|
||||
moving(s, ['geol', 'gae']);
|
||||
let t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 0)[0]).toBe('home');
|
||||
t = act(t, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(nodesOf(t, 0)[0]).toBe(4);
|
||||
});
|
||||
|
||||
test('변환: 도깨비 steps once a turn without throwing', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'dokkaebi');
|
||||
put(s, 0, 0, 3, [1, 2, 3]);
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'dokkaebi'), piece: 0 });
|
||||
const sp = yut.view(t, 'A').aug!.specials;
|
||||
expect(sp.map((m) => m.to).sort()).toEqual([2, 4]);
|
||||
t = act(t, 'A', { type: 'SPECIAL', piece: 0, to: 4 });
|
||||
expect(nodesOf(t, 0)[0]).toBe(4);
|
||||
expect(yut.view(t, 'A').aug!.specials).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('변환: 포 jumps over one piece along a line', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'cannon');
|
||||
put(s, 0, 0, 1);
|
||||
put(s, 1, 0, 2);
|
||||
put(s, 1, 1, 4);
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'cannon'), piece: 0 });
|
||||
const tos = yut.view(t, 'A').aug!.specials.map((m) => m.to);
|
||||
expect(tos).toContain(3);
|
||||
expect(tos).toContain(4); // catch beyond the screen
|
||||
expect(tos).not.toContain(5);
|
||||
const u = act(t, 'A', { type: 'SPECIAL', piece: 0, to: 4 });
|
||||
expect(nodesOf(u, 1)[1]).toBe('home');
|
||||
});
|
||||
|
||||
test('변환: 폰 walks one step on every throw', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'pawn');
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'pawn'), piece: 0 });
|
||||
t = act(t, 'A', { type: 'THROW' }, script('gae'));
|
||||
expect(nodesOf(t, 0)[0]).toBe(1);
|
||||
expect(yut.view(t, 'A').legalMoves!.every((m) => m.from === 'home')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- abilities & instants
|
||||
|
||||
describe('증강 윷놀이: abilities and instant effects', () => {
|
||||
test('8톤 트럭 runs straight to the corner, catching on the way, and ends the turn', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'truck');
|
||||
put(s, 0, 0, 1);
|
||||
put(s, 0, 1, 1);
|
||||
put(s, 1, 0, 3);
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'truck'), piece: 0 });
|
||||
expect(nodesOf(t, 0).slice(0, 2)).toEqual([5, 5]);
|
||||
expect(nodesOf(t, 1)[0]).toBe('home');
|
||||
expect(t.current).toBe('B');
|
||||
});
|
||||
|
||||
test('3단 합체 필살기!!! catches every other stack', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'combo');
|
||||
for (const i of [0, 1, 2]) put(s, 0, i, 7);
|
||||
put(s, 0, 3, 2);
|
||||
put(s, 1, 0, 12);
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'combo'), piece: 0 });
|
||||
expect(nodesOf(t, 0)).toEqual([7, 7, 7, 'home']);
|
||||
expect(nodesOf(t, 1)[0]).toBe('home');
|
||||
});
|
||||
|
||||
test('바둑 catches between two stacks and throws that many times more', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'baduk');
|
||||
put(s, 0, 0, 1);
|
||||
put(s, 0, 1, 4);
|
||||
put(s, 1, 0, 2);
|
||||
put(s, 1, 1, 3);
|
||||
moving(s, ['do']);
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'baduk'), node: 1, node2: 4 });
|
||||
expect(nodesOf(t, 1).slice(0, 2)).toEqual(['home', 'home']);
|
||||
expect(t.phase).toBe('throw');
|
||||
expect(t.throwsOwed).toBe(2);
|
||||
});
|
||||
|
||||
test('명사수 uses a throw and shoots the node when my next turn starts', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'sniper');
|
||||
put(s, 1, 0, 9);
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'sniper'), node: 9 });
|
||||
expect(t.current).toBe('B'); // that was the only throw
|
||||
expect(yut.view(t, 'B').aug!.objs).toContainEqual({ kind: 'mark', node: 9, owner: 0 });
|
||||
t = act(t, 'B', { type: 'THROW' }, script('do'));
|
||||
t = act(t, 'B', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(t.current).toBe('A');
|
||||
expect(nodesOf(t, 1)[0]).toBe('home');
|
||||
expect(t.aug!.objs).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('알까기 knocks a piece off the board', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'alkkagi');
|
||||
put(s, 0, 0, 2);
|
||||
put(s, 1, 0, 1);
|
||||
// straight down from 개 (2) onto 도 (1), hard: 도 flies off the bottom-right edge
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'alkkagi'), piece: 0, angle: 90, power: 100 });
|
||||
expect(nodesOf(t, 1)[0]).toBe('home');
|
||||
expect(t.aug!.fx.some((f) => f.kind === 'flick' && f.bodies!.length >= 2)).toBe(true);
|
||||
expect(t.current).toBe('B');
|
||||
});
|
||||
|
||||
test('나만 아니면 돼~ wipes the board pieces of another player', () => {
|
||||
const s = make(3);
|
||||
put(s, 1, 0, 4);
|
||||
put(s, 2, 0, 6);
|
||||
give(s, 0, 'notme', new Script([0.1]));
|
||||
expect(nodesOf(s, 1)[0]).toBe('home');
|
||||
expect(nodesOf(s, 2)[0]).toBe(6);
|
||||
});
|
||||
|
||||
test('크고 빨간 버튼 clears both diagonals (own pieces too), not the corners', () => {
|
||||
const s = make();
|
||||
put(s, 0, 0, 22);
|
||||
put(s, 1, 0, 26);
|
||||
put(s, 1, 1, 5);
|
||||
give(s, 0, 'bigred');
|
||||
expect(nodesOf(s, 0)[0]).toBe('home');
|
||||
expect(nodesOf(s, 1).slice(0, 2)).toEqual(['home', 5]);
|
||||
});
|
||||
|
||||
test('거머리 gives a piece and shares the winner’s rank', () => {
|
||||
const s = make(3, { ranking: 'all' });
|
||||
give(s, 0, 'leech');
|
||||
expect(s.phase).toBe('prompt');
|
||||
let t = act(s, 'A', { type: 'AUG_ANSWER', choice: 2 });
|
||||
expect(t.sides[0]!.pieces).toHaveLength(3);
|
||||
expect(t.sides[2]!.pieces).toHaveLength(5);
|
||||
expect(t.phase).toBe('throw');
|
||||
// C brings everything home but one piece, then finishes it
|
||||
for (const p of t.sides[2]!.pieces) Object.assign(p, { status: 'done', node: null, trail: [] });
|
||||
put(t, 2, 0, 19);
|
||||
Object.assign(t, { turnSide: 2, current: 'C' });
|
||||
moving(t, ['gae']);
|
||||
t = act(t, 'C', { type: 'MOVE', throwIndex: 0, from: 19 });
|
||||
expect(t.sides[2]!.finishedRank).toBe(1);
|
||||
expect(t.sides[0]!.finishedRank).toBe(1);
|
||||
});
|
||||
|
||||
test('나 누구게? hides colours until everyone guessed; a wrong guess skips a turn', () => {
|
||||
const s = make(3);
|
||||
put(s, 1, 0, 4);
|
||||
give(s, 0, 'whoami');
|
||||
expect(s.phase).toBe('prompt');
|
||||
const vb = yut.view(s, 'B');
|
||||
expect(vb.aug!.hidden).toBe(true);
|
||||
expect(vb.mySide).toBe(null);
|
||||
expect(vb.stacks.every((st) => st.side === -1)).toBe(true);
|
||||
expect(JSON.stringify(vb.sides.map((x) => x.members))).toBe('[[],[],[]]');
|
||||
let t = act(s, 'B', { type: 'AUG_ANSWER', choice: 1 });
|
||||
t = act(t, 'C', { type: 'AUG_ANSWER', choice: 0 });
|
||||
expect(t.aug!.hidden).toBe(false);
|
||||
expect(t.aug!.sides[1]!.skip).toBe(0);
|
||||
expect(t.aug!.sides[2]!.skip).toBe(1);
|
||||
});
|
||||
|
||||
test('내려: the owner votes twice; the most votes skips a turn', () => {
|
||||
const s = make(3);
|
||||
give(s, 0, 'getoff');
|
||||
let t = act(s, 'A', { type: 'AUG_ANSWER', choice: 2 });
|
||||
t = act(t, 'B', { type: 'AUG_ANSWER', choice: 0 });
|
||||
t = act(t, 'C', { type: 'AUG_ANSWER', choice: 0 });
|
||||
expect(t.aug!.sides[0]!.skip).toBe(1);
|
||||
expect(t.aug!.sides[2]!.skip).toBe(1);
|
||||
});
|
||||
|
||||
test('게임 접어라: the folded half lands on the other half and catches there', () => {
|
||||
const s = make();
|
||||
put(s, 0, 0, 11); // left side
|
||||
put(s, 1, 0, 4); // right side, mirror of 11
|
||||
give(s, 0, 'fold');
|
||||
const t = act(s, 'A', { type: 'AUG_ANSWER', choice: 0 });
|
||||
expect(nodesOf(t, 0)[0]).toBe(4);
|
||||
expect(nodesOf(t, 1)[0]).toBe('home');
|
||||
});
|
||||
|
||||
test('돌려돌려 돌림판 turns every piece; one re-spin', () => {
|
||||
const s = make();
|
||||
put(s, 0, 0, 1);
|
||||
give(s, 0, 'roulette', new Script([0.1]));
|
||||
expect(s.aug!.prompts[0]!.spin).toBe(1);
|
||||
let t = act(s, 'A', { type: 'AUG_ANSWER', choice: 1 }, new Script([0.9]));
|
||||
expect(t.aug!.prompts[0]!.spin).toBe(3);
|
||||
expect(yut.view(t, 'A').aug!.prompt!.canRespin).toBe(false);
|
||||
t = act(t, 'A', { type: 'AUG_ANSWER', choice: 0 });
|
||||
expect(nodesOf(t, 0)[0]).toBe(6); // three quarter turns clockwise: 도 → 날도 → 찌도 → 뒷도
|
||||
});
|
||||
|
||||
test('잠깐! freezes the furthest enemy stack for two rounds', () => {
|
||||
const s = make();
|
||||
put(s, 1, 0, 3);
|
||||
put(s, 1, 1, 17);
|
||||
give(s, 0, 'wait');
|
||||
expect(s.sides[1]!.pieces[1]!.frozenUntil).toBe(3);
|
||||
expect(yut.view(s, 'B').stacks.find((st) => st.node === 17)!.frozen).toBe(true);
|
||||
});
|
||||
|
||||
test('안개 hides enemy stacks far from my pieces', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'fog');
|
||||
put(s, 0, 0, 3);
|
||||
put(s, 1, 0, 4);
|
||||
put(s, 1, 1, 12);
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'fog') });
|
||||
const own = yut.view(t, 'A').stacks.map((st) => st.node);
|
||||
expect(own).toEqual(expect.arrayContaining([3, 4, 12]));
|
||||
// B sees only near its own pieces (4 and 12): 3 is next to 4, so visible
|
||||
put(t, 0, 1, 20);
|
||||
const vb = yut.view(t, 'B');
|
||||
expect(vb.aug!.fogged).toBe(true);
|
||||
expect(vb.stacks.some((st) => st.node === 20)).toBe(false);
|
||||
expect(vb.stacks.some((st) => st.node === 3)).toBe(true);
|
||||
});
|
||||
|
||||
test('지뢰 is only visible to its owner', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'mine');
|
||||
put(s, 0, 0, 6);
|
||||
const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'mine'), node: 6 });
|
||||
expect(yut.view(t, 'A').aug!.objs.some((o) => o.kind === 'mine')).toBe(true);
|
||||
expect(yut.view(t, 'B').aug!.objs.some((o) => o.kind === 'mine')).toBe(false);
|
||||
expect(yut.view(t, null).aug!.objs.some((o) => o.kind === 'mine')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- winning & going out
|
||||
|
||||
describe('증강 윷놀이: special wins and ranks', () => {
|
||||
test('중전마마 wins after 12 throws', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'queen');
|
||||
expect(nodesOf(s, 0)).toContain(10);
|
||||
s.aug!.sides[0]!.augs[0]!.n = 11;
|
||||
const t = act(s, 'A', { type: 'THROW' }, script('gae'));
|
||||
expect(t.sides[0]!.finishedRank).toBe(1);
|
||||
expect(t.phase).toBe('finished');
|
||||
expect(t.final!.ranking[0]!.reason).toBe('시작 변환: 중전마마');
|
||||
expect(yut.result(t)!.scoreText!.A).toContain('중전마마');
|
||||
});
|
||||
|
||||
test('김첨지 home within six turns wins', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'kim');
|
||||
const kim = s.sides[0]!.pieces.find((p) => p.kind === 'kim')!;
|
||||
put(s, 0, kim.id, 19);
|
||||
moving(s, ['gae']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 19, piece: kim.id });
|
||||
expect(t.final!.ranking[0]!.reason).toBe('김첨지 완주');
|
||||
});
|
||||
|
||||
test('동메달도 잘한 거야: 3rd place at once', () => {
|
||||
const s = make(4, { ranking: 'all' });
|
||||
give(s, 1, 'bronze');
|
||||
expect(s.sides[1]!.finishedRank).toBe(3);
|
||||
expect(s.phase).not.toBe('finished');
|
||||
});
|
||||
|
||||
test('라스트 댄스 doubles moves and goes out at the end of the turn', () => {
|
||||
const s = make(3);
|
||||
give(s, 0, 'lastdance');
|
||||
let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'lastdance') });
|
||||
t = act(t, 'A', { type: 'THROW' }, script('gae'));
|
||||
t = act(t, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(t.sides[0]!.out).toBe(true);
|
||||
expect(t.current).toBe('B');
|
||||
});
|
||||
|
||||
test('메아리의 형상: everyone plays two turns in a row', () => {
|
||||
const s = make();
|
||||
give(s, 0, 'echo');
|
||||
let t = act(s, 'A', { type: 'THROW' }, script('do'));
|
||||
t = act(t, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(t.current).toBe('B');
|
||||
s.aug!.echo!.on = true;
|
||||
let u = act(s, 'A', { type: 'THROW' }, script('do'));
|
||||
u = act(u, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(u.current).toBe('A');
|
||||
u = act(u, 'A', { type: 'THROW' }, script('do'));
|
||||
u = act(u, 'A', { type: 'MOVE', throwIndex: 0, from: 1 });
|
||||
expect(u.current).toBe('B');
|
||||
});
|
||||
|
||||
test('나에게 윷놀이는 "살인"이다: catches cost health, 0 is out', () => {
|
||||
const s = make(3);
|
||||
give(s, 0, 'murder');
|
||||
s.aug!.sides[1]!.hp = 1;
|
||||
put(s, 1, 0, 3);
|
||||
moving(s, ['geol']);
|
||||
const t = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(t.sides[1]!.out).toBe(true);
|
||||
});
|
||||
|
||||
test('취~소 brings special winners back into the game', () => {
|
||||
const s = make(3, { ranking: 'all' });
|
||||
give(s, 1, 'catlover');
|
||||
give(s, 2, 'cat');
|
||||
// catlover won at once
|
||||
expect(s.sides[1]!.finishedRank).toBe(null); // checked after the selection / next action
|
||||
let t = act(s, 'A', { type: 'THROW' }, script('do'));
|
||||
expect(t.sides[1]!.finishedRank).toBe(1);
|
||||
give(t, 0, 'cancel');
|
||||
expect(t.sides[1]!.finishedRank).toBe(null);
|
||||
expect(t.aug!.winsOff).toBe(true);
|
||||
});
|
||||
|
||||
test('계획대로: a correct prediction wins alone', () => {
|
||||
const s = make(2);
|
||||
give(s, 1, 'plan');
|
||||
let t = act(s, 'B', { type: 'AUG_ANSWER', choice: [0, 1] });
|
||||
for (const p of t.sides[0]!.pieces) Object.assign(p, { status: 'done', node: null, trail: [] });
|
||||
put(t, 0, 0, 19);
|
||||
moving(t, ['gae']);
|
||||
t = act(t, 'A', { type: 'MOVE', throwIndex: 0, from: 19 });
|
||||
expect(t.phase).toBe('finished');
|
||||
expect(t.final!.winners).toEqual(['B']);
|
||||
expect(t.final!.summary).toContain('계획대로');
|
||||
});
|
||||
|
||||
test('승부다!: the challenged side must bring a piece home within 3 turns', () => {
|
||||
const s = make(3);
|
||||
give(s, 0, 'duel');
|
||||
let t = act(s, 'A', { type: 'AUG_ANSWER', choice: 1 });
|
||||
t.aug!.sides[0]!.augs[0]!.n = 1;
|
||||
Object.assign(t, { turnSide: 1, current: 'B' });
|
||||
t = act(t, 'B', { type: 'THROW' }, script('do'));
|
||||
t = act(t, 'B', { type: 'MOVE', throwIndex: 0, from: 'home' });
|
||||
expect(t.sides[1]!.out).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- whole games
|
||||
|
||||
describe('증강 윷놀이: whole games', () => {
|
||||
test.each(Array.from({ length: playoutSeeds(60) }, (_, i) => i))('random playout %i', (i) => {
|
||||
const n = 2 + (i % 3);
|
||||
const players = PLAYERS.slice(0, n);
|
||||
const options = yut.optionsSchema.parse({
|
||||
augmented: true,
|
||||
augRounds: (['standard', 'quick', 'many'] as const)[i % 3],
|
||||
augChaos: i % 4 === 0,
|
||||
augOffers: 4,
|
||||
nakPercent: i % 5 === 0 ? 5 : 0,
|
||||
stacking: i % 6 === 0 ? 'choose' : 'always',
|
||||
ranking: i % 2 ? 'all' : 'first',
|
||||
});
|
||||
const r = randomPlayout(yut, {
|
||||
players,
|
||||
options,
|
||||
seed: seedN(1000 + i),
|
||||
maxSteps: 6000,
|
||||
maxApplyMs: 50,
|
||||
invariant: (st) => {
|
||||
const s = st as YutState;
|
||||
for (const p of [...players, null]) yut.view(s, p);
|
||||
for (const x of s.sides) {
|
||||
expect(x.out && x.finishedRank !== null).toBe(false);
|
||||
if (x.out || x.finishedRank !== null) expect(x.pieces.some((p) => p.status === 'board')).toBe(false);
|
||||
}
|
||||
if (s.phase === 'throw' || s.phase === 'move') expect(s.sides[s.turnSide]!.out || s.sides[s.turnSide]!.finishedRank !== null).toBe(false);
|
||||
},
|
||||
});
|
||||
expect(r.finished).toBe(true);
|
||||
});
|
||||
|
||||
test('computers finish 증강 games without getting stuck', () => {
|
||||
for (let g = 0; g < playoutSeeds(30); g++) {
|
||||
const n = 2 + (g % 3);
|
||||
const players = ['bot1', 'bot2', 'bot3', 'H'].slice(0, n);
|
||||
const r = botPlayout(yut, { players, options: yut.optionsSchema.parse({ augmented: true, augChaos: g % 3 === 0 }), seed: seedN(g + 7), isBot: (p) => p.startsWith('bot') });
|
||||
expect(r.finished).toBe(true);
|
||||
expect(r.botTimeouts).toBe(0);
|
||||
}
|
||||
});
|
||||
|
||||
test('a computer picks an augment and answers prompts', () => {
|
||||
const s = yut.setup({ players: ['bot', 'H'], options: yut.optionsSchema.parse({ augmented: true }), rng: SeededRng.fromSeed(seedN(2)), now: 0 });
|
||||
const a = decideBotAction(yut, s, 'bot', { now: 1, random: () => 0.3 });
|
||||
expect(a).toMatchObject({ type: 'AUG_PICK' });
|
||||
});
|
||||
});
|
||||
3085
packages/games/src/yut/aug.ts
Normal file
3085
packages/games/src/yut/aug.ts
Normal file
File diff suppressed because it is too large
Load Diff
156
packages/games/src/yut/augments.ts
Normal file
156
packages/games/src/yut/augments.ts
Normal file
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* 증강 윷놀이 증강 목록 (docs/games/yut-augmented.md). Pure data shared by the rules, the options screen and the board.
|
||||
* Augments are based on the Steam game 「증강 윷놀이」(어수룩 게임즈, 2026); `custom` ones are this site's own.
|
||||
*/
|
||||
|
||||
/** When an augment can be offered: any selection, or only the first / middle / last one. */
|
||||
export type AugTier = 'any' | 'start' | 'mid' | 'final';
|
||||
/** How it works: passive rule, effect right when picked, a button to use, or a win condition. */
|
||||
export type AugKind = 'passive' | 'instant' | 'active' | 'win';
|
||||
|
||||
export interface AugInfo {
|
||||
id: AugId;
|
||||
name: string;
|
||||
tier: AugTier;
|
||||
kind: AugKind;
|
||||
/** Usable once (the slot gets a "사용함" stamp after). */
|
||||
once?: boolean;
|
||||
/** Using it ends the turn, so it can only be used before the first throw of a turn. */
|
||||
wholeTurn?: boolean;
|
||||
/** Has a special win (or 3rd place) condition; [취~소] turns these off. */
|
||||
win?: boolean;
|
||||
/** This site's own augment (not in the original game). */
|
||||
custom?: boolean;
|
||||
/** One or two plain sentences (해요체). */
|
||||
text: string;
|
||||
/** Extra rule details for the rules sheet. */
|
||||
note?: string;
|
||||
}
|
||||
|
||||
export const AUG_IDS = [
|
||||
// 범용
|
||||
'truck', 'combo', 'chosen', 'fold', 'cat', 'excess', 'doggy', 'leech', 'whoami', 'notme', 'getoff', 'doberman',
|
||||
'roulette', 'sniper', 'detective', 'moordo', 'baduk', 'delivery', 'dokkaebi', 'vanguard', 'cannon', 'pawn', 'four',
|
||||
'ox', 'sleight', 'timetravel', 'score', 'fog', 'alkkagi', 'catlover', 'fisherman', 'illusion', 'throwyut', 'dual',
|
||||
'objection', 'jajinmori', 'moonwalk', 'shield', 'bigred', 'friendshield', 'sacrifice', 'poop',
|
||||
// 시작 전용
|
||||
'equiv', 'party', 'speedrun', 'kim', 'queen', 'bear', 'piggyback', 'burden', 'alone',
|
||||
// 중간 전용
|
||||
'triple7', 'nofriends', 'summon', 'coup', 'treason', 'wait', 'peace',
|
||||
// 마무리 전용
|
||||
'plan', 'murder', 'necro', 'poison', 'bronze', 'lastdance', 'echo', 'marathon', 'duel', 'comeback', 'domain', 'cancel',
|
||||
'cannibal',
|
||||
// 이 사이트 추가
|
||||
'teleport', 'shortcut', 'turtle', 'revenge', 'thief', 'mine', 'tiger', 'twins', 'swap', 'storm',
|
||||
] as const;
|
||||
export type AugId = (typeof AUG_IDS)[number];
|
||||
|
||||
const L: Omit<AugInfo, 'id'>[] = [
|
||||
// ---------------------------------------------------------------- 범용
|
||||
{ name: '8톤 트럭', tier: 'any', kind: 'active', once: true, wholeTurn: true, text: '말이 2개 이상 업힌 내 말뭉치 하나가 꺾이는 곳까지 앞으로 쭉 달려요. 지나가는 길의 다른 편 말은 모두 잡아요.', note: '차례를 다 써요(던지기 전에만). 모서리·방에 서 있었다면 지름길로 출발하고, 모서리·참먹이에 닿으면 멈춰요.' },
|
||||
{ name: '3단 합체 필살기!!!', tier: 'any', kind: 'active', once: true, wholeTurn: true, text: '말이 3개 이상 업힌 내 말뭉치를 골라요. 그 말뭉치를 뺀 판 위의 모든 말뭉치를 잡아요(내 다른 말도요).', note: '차례를 다 써요(던지기 전에만).' },
|
||||
{ name: '간택', tier: 'any', kind: 'passive', text: '이제 모든 사람은 증강 후보에 고양이가 나오면 꼭 고양이를 골라야 해요.' },
|
||||
{ name: '게임 접어라', tier: 'any', kind: 'instant', text: '윷판을 반으로 접어요. 접는 방향을 고르면, 접히는 쪽 말이 반대쪽 같은 자리로 옮겨져요.', note: '옮겨진 말이 다른 편 말 위에 떨어지면 그 말을 잡아요. 내 말끼리는 업혀요.' },
|
||||
{ name: '고양이', tier: 'any', kind: 'passive', text: '아무 능력이 없어요. 왜 있냐고요? 귀엽잖아요.' },
|
||||
{ name: '과유불급', tier: 'any', kind: 'passive', text: '윷가락 6개로 던져요. 배가 0개면 모, 4~5개면 윷, 6개가 모두 배면 탈락해요.', note: '배가 1~3개면 도·개·걸이에요. 이 증강의 윷가락은 앞뒤가 반반으로 나와요.' },
|
||||
{ name: '개돼지', tier: 'any', kind: 'passive', text: '던지면 도와 개만 나오지만, 둘 중 하나를 골라서 낼 수 있어요.' },
|
||||
{ name: '거머리', tier: 'any', kind: 'instant', text: '다른 사람 한 명에게 내 말 1개를 줘요. 그 사람이 이기면 나도 같은 순위로 이기고, 탈락하면 나도 탈락해요.', note: '대기 중인 말을 먼저 줘요. 나도 따로 이길 수 있어요.' },
|
||||
{ name: '나 누구게?', tier: 'any', kind: 'instant', text: '잠깐 모든 말의 색이 가려져요. 다른 사람은 자기 색을 맞혀야 하고, 틀리면 차례를 한 번 건너뛰어요.' },
|
||||
{ name: '나만 아니면 돼~', tier: 'any', kind: 'instant', text: '다른 사람 중 무작위로 한 명의 판 위 말을 모두 잡아요.' },
|
||||
{ name: '내려', tier: 'any', kind: 'instant', text: '모두 투표해요. 표를 가장 많이 받은 사람은 차례를 한 번 건너뛰어요. 나는 2표를 행사해요.', note: '자기 자신에게는 투표할 수 없어요. 동점이면 동점인 사람이 모두 건너뛰어요.' },
|
||||
{ name: '도베르만', tier: 'any', kind: 'active', once: true, text: '이번 게임에서 낸 개 수만큼 개 코인을 받아요. 그 뒤로는 던질 때마다 개 코인 2개를 써서 모가 나와요.', note: '개 코인이 2개보다 적으면 평소처럼 던져요.' },
|
||||
{ name: '돌려돌려 돌림판', tier: 'any', kind: 'instant', text: '판을 돌려 모든 말이 돌아간 자리로 옮겨져요. 결과가 마음에 안 들면 한 번 더 돌릴 수 있어요.' },
|
||||
{ name: '명사수', tier: 'any', kind: 'active', text: '던지기 한 번을 써서 칸 하나를 조준해요. 다음 내 차례가 시작될 때 그 칸의 말을 모두 잡아요.', note: '한 차례에 한 번, 조준은 한 곳만 할 수 있어요. 내 말도 잡혀요.' },
|
||||
{ name: '명탐정', tier: 'any', kind: 'instant', text: '증강 하나를 지목해요. 이번 증강 선택에서 다른 사람이 그 증강을 고르면 무효가 돼요.' },
|
||||
{ name: '모 아니면 도', tier: 'any', kind: 'passive', text: '던지면 모 아니면 도만 나와요. 모가 나올 확률은 40%예요.' },
|
||||
{ name: '바둑', tier: 'any', kind: 'active', once: true, text: '한 줄 위에 있는 내 말뭉치 둘 사이의 다른 편 말을 모두 잡고, 잡은 말 수만큼 더 던져요.' },
|
||||
{ name: '배달', tier: 'any', kind: 'instant', text: '증강 하나를 주문해요. 다음 증강 선택 때 그 증강이 내 후보에 꼭 나와요.' },
|
||||
{ name: '변환: 도깨비', tier: 'any', kind: 'active', once: true, text: '내 일반 말 하나를 도깨비로 바꿔요. 도깨비는 내 차례마다 한 번, 던지지 않고 앞이나 뒤로 1칸 갈 수 있어요.' },
|
||||
{ name: '변환: 선봉장', tier: 'any', kind: 'active', once: true, text: '내 일반 말 하나를 선봉장으로 바꿔요. 선봉장이 판 위에 있는 동안 내 말은 앞으로 갈 때마다 1칸 더 가요.' },
|
||||
{ name: '변환: 포', tier: 'any', kind: 'active', once: true, text: '내 판 위 일반 말 하나를 포로 바꿔요. 포는 내 차례마다 한 번, 말이 있는 칸 하나를 넘어 한 줄로 원하는 만큼 갈 수 있어요.', note: '넘은 뒤 처음 만나는 말이 다른 편이면 잡을 수 있어요. 참먹이에는 내려앉지 못해요.' },
|
||||
{ name: '변환: 폰', tier: 'any', kind: 'active', once: true, text: '내 일반 말 하나를 폰으로 바꿔요. 폰은 직접 움직일 수 없지만 내가 던질 때마다 1칸씩 앞으로 가요.' },
|
||||
{ name: '사목', tier: 'any', kind: 'win', win: true, text: '내 말이 한 줄로 이어진 네 칸을 차지하거나, 내 말 4개가 한 말뭉치가 되면 이겨요.' },
|
||||
{ name: '소 뒷걸음질', tier: 'any', kind: 'win', win: true, text: '빽도로 말을 두 번 잡으면 이겨요.' },
|
||||
{ name: '손은 눈보다 빠르다', tier: 'any', kind: 'active', once: true, text: '이번 던지기의 결과를 원하는 대로 골라서 내요.' },
|
||||
{ name: '시간 여행', tier: 'any', kind: 'active', once: true, text: '내 말뭉치 하나를 지나온 칸 중 원하는 곳으로 되돌려요.' },
|
||||
{ name: '악보가 완성되었다!', tier: 'any', kind: 'win', win: true, text: '이번 게임에서 빽도·도·개·걸·윷·모를 모두 한 번 이상 내면 이겨요.', note: '증강을 얻기 전에 낸 것도 세요.' },
|
||||
{ name: '안개', tier: 'any', kind: 'active', once: true, text: '내 차례 두 번이 돌아올 때까지 판에 안개가 껴요. 다른 사람은 자기 말 근처만 볼 수 있어요.' },
|
||||
{ name: '알까기', tier: 'any', kind: 'active', once: true, wholeTurn: true, text: '내 말 하나를 손가락으로 튕겨요. 부딪힌 말이 판 밖으로 나가면 잡혀요.', note: '차례를 다 써요(던지기 전에만). 업힌 말뭉치를 고르면 말 1개만 날아가요. 멈춘 말은 가장 가까운 칸에 서요.' },
|
||||
{ name: '애묘인', tier: 'any', kind: 'win', win: true, text: '누구든 고양이를 고른 사람이 있으면 이겨요.', note: '이미 고른 사람이 있어도 돼요.' },
|
||||
{ name: '어부지리', tier: 'any', kind: 'passive', text: '내 차례가 아닐 때 다른 사람 말이 2개 잡힐 때마다 개를 하나 받아요. 받은 개는 다음 내 차례에 써요.' },
|
||||
{ name: '언제부터 착각한 거지?', tier: 'any', kind: 'instant', text: '다른 사람의 증강 하나를 3라운드 동안 고양이로 바꿔요.', note: '이미 다 쓴 증강은 고를 수 없어요.' },
|
||||
{ name: '윷을 잘 던져봐', tier: 'any', kind: 'active', once: true, text: '윷을 던져 한 사람을 맞혀요. 맞은 사람은 차례를 두 번 건너뛰어요.' },
|
||||
{ name: '이도류', tier: 'any', kind: 'passive', text: '윷가락을 2개씩 두 번 던져서 결과를 두 개 받아요. 모(둘 다 등)는 도로 바뀌어요.', note: '도·개·빽도만 나와서 한 번 더 던지는 일은 없어요.' },
|
||||
{ name: '이의있음!', tier: 'any', kind: 'instant', text: '이번 증강 선택을 없던 걸로 하고 새 후보 중에서 다시 골라요.' },
|
||||
{ name: '자진모리 장단', tier: 'any', kind: 'passive', text: '걸이 두 번 나올 때마다 개를 하나 더 받아요.' },
|
||||
{ name: '천마군림보 - 달걸음', tier: 'any', kind: 'passive', text: '내 말은 모두 반대 방향(시계 방향)으로 돌아요.', note: '참먹이에서 날윷 쪽으로 출발하고, 찌모·뒷모·방에 멈추면 지름길로 꺾어요.' },
|
||||
{ name: '천상의 보호막', tier: 'any', kind: 'active', once: true, text: '내 말뭉치 하나에 보호막을 씌워요. 보호막은 잡힐 때 한 번 막아 줘요.', note: '막아 낸 말은 그 자리에 그대로 남아요.' },
|
||||
{ name: '크고 빨간 버튼', tier: 'any', kind: 'instant', text: '두 대각선 지름길(방 포함, 모서리 제외)에 있는 모든 말을 잡아요. 내 말도요.' },
|
||||
{ name: '프랜드 실드', tier: 'any', kind: 'passive', text: '내 말뭉치가 잡힐 때 말 1개만 잡히고 나머지는 남아요.' },
|
||||
{ name: '희생', tier: 'any', kind: 'active', once: true, text: '판 위의 내 말 하나를 스스로 잡혀요. 판 위의 다른 내 말에 모두 보호막을 씌워요.' },
|
||||
{ name: '히히 똥!', tier: 'any', kind: 'instant', text: '무작위 칸에 똥을 싸요. 다른 사람 말은 지나가다 똥을 밟으면 그 자리에 멈춰요.' },
|
||||
// ---------------------------------------------------------------- 시작 전용
|
||||
{ name: '등가교환', tier: 'start', kind: 'instant', text: '내 말 1개와 윷가락 1개를 빼고 시작해요.', note: '윷가락 3개로는 윷이 나오지 않아요(배 3개는 걸).' },
|
||||
{ name: '말이오? 파티', tier: 'start', kind: 'instant', text: '판에 함정 6개와 선물 4개를 깔아요. 딱 멈춘 말은 잡히거나 옮겨져요. 내가 깐 함정에는 걸리지 않아요.', note: '해골: 잡힘 · 마녀 모자: 뒤로 2칸 · 선물: 앞으로 2칸(누구나).' },
|
||||
{ name: '스겜', tier: 'start', kind: 'instant', text: '모든 사람의 말이 2개가 되고, 내 말은 도와 개 자리에서 시작해요.' },
|
||||
{ name: '시작 변환: 김첨지', tier: 'start', kind: 'instant', win: true, text: '내 말 하나가 김첨지가 돼요. 김첨지가 내 차례 6번 안에 나면 이겨요.', note: '6번이 지나면 보통 말처럼 움직여요.' },
|
||||
{ name: '시작 변환: 중전마마', tier: 'start', kind: 'instant', win: true, text: '내 말 하나가 중전마마가 되어 뒷모(왼쪽 위)에 서요. 내가 12번 던질 때까지 지키면 이기고, 목숨이 다 떨어지면 탈락해요.', note: '중전마마는 날 수 없어요. 목숨은 1개로 시작하고, 다른 말이 날 때마다 1개 늘어요. 잡히면 목숨을 잃고 대기로 돌아가요.' },
|
||||
{ name: '웅녀', tier: 'start', kind: 'instant', win: true, text: '무작위 칸 3곳에 마늘이 놓여요. 내 말이 마늘 칸에 멈춰 3개를 모두 모으면 이겨요.' },
|
||||
{ name: '이리 오너라 업고 놀자', tier: 'start', kind: 'instant', text: '내 말을 모두 업은 채 도 자리에서 시작해요.' },
|
||||
{ name: '짐덩이와 복덩이', tier: 'start', kind: 'instant', text: '내 말 1개와 윷가락 1개를 더하고 시작해요.', note: '윷가락 5개로 던져요. 배가 4~5개면 윷이에요.' },
|
||||
{ name: '천상천하 유아독존', tier: 'start', kind: 'win', win: true, text: '내가 잡아서 판 위에 내 말뭉치 1개만 남으면 이겨요.' },
|
||||
// ---------------------------------------------------------------- 중간 전용
|
||||
{ name: '777', tier: 'mid', kind: 'win', win: true, text: '한 차례 안에 같은 결과가 세 번 나오면 이겨요.' },
|
||||
{ name: '나만 친구 없어', tier: 'mid', kind: 'win', win: true, text: '이 증강을 고른 뒤 다른 모든 사람이 내 말을 한 번씩 잡으면 이겨요.' },
|
||||
{ name: '마신 소환', tier: 'mid', kind: 'instant', win: true, text: '내 일반 말이 모두 광신도가 돼요. 내 차례가 시작될 때 판 위 광신도마다 의식 코인을 1개 받고, 12개를 모으면 이겨요.' },
|
||||
{ name: '무신정변', tier: 'mid', kind: 'win', win: true, text: '이 증강을 고른 뒤 다른 편 말을 4개 잡으면 이겨요.' },
|
||||
{ name: '역모', tier: 'mid', kind: 'passive', text: '나보다 난 말이 많은 사람의 말을 잡으면 한 번 더 던져요.' },
|
||||
{ name: '잠깐!', tier: 'mid', kind: 'instant', text: '다른 사람 말 중 가장 앞선 말뭉치 하나가 2라운드 동안 못 움직여요.' },
|
||||
{ name: '평화 협정', tier: 'mid', kind: 'passive', text: '나는 다른 사람 말을 잡을 수 없고, 다른 사람도 내 말을 잡을 수 없어요. 증강으로 잡는 것도요.', note: '같은 칸에 멈추면 함께 서 있어요.' },
|
||||
// ---------------------------------------------------------------- 마무리 전용
|
||||
{ name: '계획대로', tier: 'final', kind: 'instant', win: true, text: '모든 사람의 최종 순위를 예언해요. 다 맞히면 순위를 없애고 나 혼자 이겨요.' },
|
||||
{ name: '나에게 윷놀이는 "살인"이다', tier: 'final', kind: 'instant', text: '모든 사람에게 체력 3이 생겨요. 내가 말을 잡을 때마다 잡힌 말 수만큼 그 사람 체력이 줄고, 0이 되면 탈락해요.' },
|
||||
{ name: '네크로맨서', tier: 'final', kind: 'active', once: true, text: '탈락한 사람 한 명을 되살려요. 그 사람이 이기면 나도 같은 순위로 이겨요.', note: '기권하거나 나간 사람은 되살릴 수 없어요.' },
|
||||
{ name: '독이 든 성배', tier: 'final', kind: 'active', text: '내 차례에 마시면 던지기 3번을 더 받아요. 마신 차례에 모가 나오면 탈락해요.', note: '한 차례에 한 번 마실 수 있어요.' },
|
||||
{ name: '동메달도 잘한 거야', tier: 'final', kind: 'instant', win: true, text: '바로 3위로 게임을 마쳐요.', note: '3명 이상 남아 있을 때만 후보에 나와요.' },
|
||||
{ name: '라스트 댄스', tier: 'final', kind: 'active', once: true, text: '이번 차례 동안 내 말이 모두 두 배로 움직여요. 차례가 끝나면 탈락해요.', note: '이번 차례에 이기면 탈락하지 않아요.' },
|
||||
{ name: '메아리의 형상', tier: 'final', kind: 'instant', text: '내 차례부터 모든 사람이 차례를 두 번씩 해요.' },
|
||||
{ name: '변환: 마라토너', tier: 'final', kind: 'active', once: true, win: true, text: '대기 중인 내 일반 말 하나를 마라토너로 바꿔요. 마라토너가 나면 이겨요.' },
|
||||
{ name: '승부다!', tier: 'final', kind: 'instant', text: '한 사람을 골라요. 그 사람이 자기 차례 3번 안에 말을 하나도 못 내면 탈락하고, 내면 내가 탈락해요.' },
|
||||
{ name: '역전 찬스', tier: 'final', kind: 'instant', text: '무작위 증강 3개를 받아요.' },
|
||||
{ name: '영역 전개', tier: 'final', kind: 'active', once: true, win: true, text: '판 위 내 말뭉치 하나를 못 움직이게 묶어요. 내 차례가 두 번 돌아올 때까지 살아남으면 이기고, 잡히면 탈락해요.' },
|
||||
{ name: '취~소', tier: 'final', kind: 'instant', text: '모든 특수 승리를 취소해요. 승리 조건 증강은 모두 효과가 없어지고, 특수 승리로 끝낸 사람은 게임으로 돌아와요.' },
|
||||
{ name: '카니발리즘', tier: 'final', kind: 'passive', text: '내 말끼리 업을 수 없는 대신 내 말을 잡을 수 있어요. 내 말을 잡으면 한 번 더 던져요.' },
|
||||
// ---------------------------------------------------------------- 이 사이트 추가
|
||||
{ name: '순간이동', tier: 'any', kind: 'active', once: true, custom: true, text: '내 말뭉치 하나를 다른 내 말뭉치 자리로 옮겨 업어요.' },
|
||||
{ name: '지름길 달인', tier: 'any', kind: 'passive', custom: true, text: '내 말은 모서리와 방을 지나가기만 해도 지름길로 꺾어요.' },
|
||||
{ name: '거북이 등껍질', tier: 'any', kind: 'passive', custom: true, text: '말이 3개 이상 업힌 내 말뭉치는 잡히지 않아요.' },
|
||||
{ name: '복수의 칼날', tier: 'any', kind: 'passive', custom: true, text: '내 말이 잡힐 때마다 다음 내 차례에 한 번 더 던져요.', note: '모아 둘 수 있는 건 2번까지예요.' },
|
||||
{ name: '손버릇', tier: 'any', kind: 'instant', custom: true, text: '다른 사람의 아직 쓰지 않은 증강 하나를 빼앗아 와요.' },
|
||||
{ name: '지뢰 매설', tier: 'any', kind: 'active', once: true, custom: true, text: '내 말이 있는 칸에 지뢰를 몰래 묻어요. 다른 사람 말이 그 칸에 멈추면 잡혀요.', note: '지뢰는 나에게만 보이고, 한 번 터지면 사라져요.' },
|
||||
{ name: '호랑이 기운', tier: 'any', kind: 'passive', custom: true, text: '걸이 나와도 윷·모처럼 한 번 더 던져요.' },
|
||||
{ name: '쌍둥이', tier: 'any', kind: 'active', once: true, custom: true, text: '대기 중인 내 말 하나를 판 위 내 말뭉치에 바로 업혀요.' },
|
||||
{ name: '자리 바꾸기', tier: 'any', kind: 'active', once: true, custom: true, text: '내 말뭉치 하나와 다른 사람 말뭉치 하나의 자리를 맞바꿔요.' },
|
||||
{ name: '회오리', tier: 'mid', kind: 'instant', custom: true, text: '판 위의 모든 말뭉치가 회오리에 휩쓸려 무작위 칸으로 흩어져요.', note: '참먹이에는 떨어지지 않고, 말뭉치끼리 겹치지 않아요.' },
|
||||
];
|
||||
|
||||
export const AUGS: Record<AugId, AugInfo> = Object.fromEntries(AUG_IDS.map((id, i) => [id, { id, ...L[i]! }])) as Record<AugId, AugInfo>;
|
||||
|
||||
if (L.length !== AUG_IDS.length) throw new Error(`augments: ${L.length} entries for ${AUG_IDS.length} ids`);
|
||||
|
||||
export const TIER_KO: Record<AugTier, string> = { any: '범용', start: '시작 전용', mid: '중간 전용', final: '마무리 전용' };
|
||||
export const KIND_KO: Record<AugKind, string> = { passive: '규칙', instant: '즉시', active: '사용', win: '승리 조건' };
|
||||
|
||||
/** 증강 선택 라운드 presets (옵션 `augRounds`). */
|
||||
export const AUG_ROUNDS = { standard: [1, 6, 12], quick: [1, 4, 8], many: [1, 3, 5, 7, 9] } as const;
|
||||
export type AugRoundsKey = keyof typeof AUG_ROUNDS;
|
||||
|
||||
/** Tier of the `i`-th selection out of `n`: the first is 시작, the last 마무리, the rest 중간. */
|
||||
export function selectionTier(i: number, n: number): Exclude<AugTier, 'any'> {
|
||||
if (i === 0) return 'start';
|
||||
if (i === n - 1) return 'final';
|
||||
return 'mid';
|
||||
}
|
||||
|
||||
/** Side colours of 개인전 (mirrors SOLO_NAMES in index.ts) — used in augment texts. */
|
||||
export const COLOR_NAMES = ['빨강', '파랑', '초록', '노랑'] as const;
|
||||
@@ -158,3 +158,78 @@ export function throwProbabilities(p: number, backdo = true): Record<Throw, numb
|
||||
mo: q ** 4,
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- geometry (증강 윷놀이)
|
||||
|
||||
/**
|
||||
* Node centres on a 0..100 board (same layout as the screen): 참먹이 bottom-right, 모 top-right, 뒷모 top-left,
|
||||
* 찌모 bottom-left. Used by augments that fold, turn or flick the board.
|
||||
*/
|
||||
export const NODE_POS: readonly (readonly [number, number])[] = (() => {
|
||||
const LO = 8;
|
||||
const HI = 92;
|
||||
const GAP = (HI - LO) / 5;
|
||||
const p: [number, number][] = [];
|
||||
p[0] = [HI, HI];
|
||||
for (let i = 1; i <= 4; i++) p[i] = [HI, HI - GAP * i];
|
||||
p[5] = [HI, LO];
|
||||
for (let i = 6; i <= 9; i++) p[i] = [HI - GAP * (i - 5), LO];
|
||||
p[10] = [LO, LO];
|
||||
for (let i = 11; i <= 14; i++) p[i] = [LO, LO + GAP * (i - 10)];
|
||||
p[15] = [LO, HI];
|
||||
for (let i = 16; i <= 19; i++) p[i] = [LO + GAP * (i - 15), HI];
|
||||
const lerp = (a: [number, number], b: [number, number], t: number): [number, number] => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
||||
[20, 21, 22, 23, 24].forEach((n, k) => (p[n] = lerp(p[5]!, p[15]!, (k + 1) / 6)));
|
||||
[25, 26].forEach((n, k) => (p[n] = lerp(p[10]!, p[0]!, (k + 1) / 6)));
|
||||
[27, 28].forEach((n, k) => (p[n] = lerp(p[10]!, p[0]!, (k + 4) / 6)));
|
||||
return p;
|
||||
})();
|
||||
|
||||
/** The six straight lines of the board, end to end (4 sides, 2 diagonals through 방). */
|
||||
export const STRAIGHT_LINES: readonly (readonly NodeId[])[] = [
|
||||
[0, 1, 2, 3, 4, 5],
|
||||
[5, 6, 7, 8, 9, 10],
|
||||
[10, 11, 12, 13, 14, 15],
|
||||
[15, 16, 17, 18, 19, 0],
|
||||
[5, 20, 21, 22, 23, 24, 15],
|
||||
[10, 25, 26, 22, 27, 28, 0],
|
||||
];
|
||||
|
||||
/** Nodes joined by a board line (graph neighbours, both directions). */
|
||||
export const NEIGHBOURS: readonly (readonly NodeId[])[] = (() => {
|
||||
const nb: Set<NodeId>[] = Array.from({ length: NODE_COUNT }, () => new Set<NodeId>());
|
||||
for (const line of STRAIGHT_LINES)
|
||||
for (let i = 0; i + 1 < line.length; i++) {
|
||||
nb[line[i]!]!.add(line[i + 1]!);
|
||||
nb[line[i + 1]!]!.add(line[i]!);
|
||||
}
|
||||
return nb.map((x) => [...x].sort((a, b) => a - b));
|
||||
})();
|
||||
|
||||
/** Node whose centre is `pt` (exact layout match); throws if none. */
|
||||
function nodeAt(pt: readonly [number, number]): NodeId {
|
||||
const i = NODE_POS.findIndex((q) => Math.abs(q[0] - pt[0]) < 1e-6 && Math.abs(q[1] - pt[1]) < 1e-6);
|
||||
if (i < 0) throw new Error(`no node at ${pt}`);
|
||||
return i;
|
||||
}
|
||||
|
||||
const mapNodes = (f: (p: readonly [number, number]) => [number, number]): NodeId[] => NODE_POS.map((p) => nodeAt(f(p)));
|
||||
|
||||
/** Mirror over the 참먹이–뒷모 diagonal: walking the mirrored board forward = walking this one backwards (달걸음). */
|
||||
export const MIRROR_DIAG: readonly NodeId[] = mapNodes(([x, y]) => [y, x]);
|
||||
/** Left ↔ right, top ↔ bottom mirrors and a quarter turn clockwise (as seen on screen). */
|
||||
export const MIRROR_LR: readonly NodeId[] = mapNodes(([x, y]) => [100 - x, y]);
|
||||
export const MIRROR_TB: readonly NodeId[] = mapNodes(([x, y]) => [x, 100 - y]);
|
||||
export const ROTATE_CW: readonly NodeId[] = mapNodes(([x, y]) => [100 - y, x]);
|
||||
|
||||
/** Nodes on the two diagonals, corners excluded (크고 빨간 버튼). */
|
||||
export const DIAGONAL_NODES: readonly NodeId[] = [20, 21, 22, 23, 24, 25, 26, 27, 28];
|
||||
|
||||
/** Result of `k` sticks of which `flats` show 배 (0 = 모, ≥ 4 = 윷); the marked stick alone gives 빽도. */
|
||||
export function throwOfCount(flats: number, markedOnly: boolean, backdo: boolean): Throw {
|
||||
if (flats === 0) return 'mo';
|
||||
if (flats === 1) return backdo && markedOnly ? 'backdo' : 'do';
|
||||
if (flats === 2) return 'gae';
|
||||
if (flats === 3) return 'geol';
|
||||
return 'yut';
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { BotStrategy } from '../bots/types';
|
||||
import { answerRequests, best, pick, playable } from '../bots/policy';
|
||||
import { FLAT_P, GOAL, THROW_STEPS, advance, defaultPrev, remainingDistance, throwProbabilities, type NodeId, type Throw } from './board';
|
||||
import type { YutAction, YutLegalMove, YutView } from './index';
|
||||
import { augBotAction } from './aug-bot';
|
||||
|
||||
const STEP = 3; // points per step of progress per piece
|
||||
const THROWS: Throw[] = ['backdo', 'do', 'gae', 'geol', 'yut', 'mo'];
|
||||
@@ -14,6 +15,10 @@ const THROWS: Throw[] = ['backdo', 'do', 'gae', 'geol', 'yut', 'mo'];
|
||||
export const yutBot: BotStrategy<YutView, YutAction> = ({ view, legal, random }) => {
|
||||
const req = answerRequests(legal);
|
||||
if (req) return req;
|
||||
if (view.aug) {
|
||||
const a = augBotAction(view, legal, random);
|
||||
if (a) return a;
|
||||
}
|
||||
const moves = legal.filter((a) => a.type === 'MOVE') as Extract<YutAction, { type: 'MOVE' }>[];
|
||||
if (!moves.length || !view.legalMoves) return pick(playable(legal), random);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
122
packages/games/src/yut/physics.ts
Normal file
122
packages/games/src/yut/physics.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 알까기 (증강): a small deterministic disc simulation on the 0..100 board. Runs on the server only; the screen just
|
||||
* replays the sampled frames. Same inputs give the same result (fixed step, no randomness).
|
||||
*/
|
||||
export interface Disc {
|
||||
x: number;
|
||||
y: number;
|
||||
/** Pieces in the disc (heavier stacks are pushed less). */
|
||||
mass: number;
|
||||
}
|
||||
|
||||
export interface FlickResult {
|
||||
/** Final centre of every disc. */
|
||||
end: [number, number][];
|
||||
/** Discs whose centre left the board. */
|
||||
out: boolean[];
|
||||
/** Discs that moved at all. */
|
||||
moved: boolean[];
|
||||
/** Sampled centres of the discs that moved (index → points, ~30 per second), for the animation. */
|
||||
frames: Record<number, [number, number][]>;
|
||||
}
|
||||
|
||||
export const DISC_R = 3.8;
|
||||
const DT = 1 / 60;
|
||||
const MAX_STEPS = 600;
|
||||
const FRICTION = 55; // units / s²
|
||||
const MAX_SPEED = 170; // units / s at power 100
|
||||
const RESTITUTION = 0.9;
|
||||
/** A centre outside this square has fallen off the board. */
|
||||
export const EDGE_LO = 0.5;
|
||||
export const EDGE_HI = 99.5;
|
||||
const SAMPLE_EVERY = 2;
|
||||
|
||||
/**
|
||||
* Flicks disc `hit` towards `angleDeg` (screen degrees: 0 = right, 90 = down) with `power` 1..100.
|
||||
* `ghost`: a disc that starts under the flicked one (the rest of its stack) and does not collide with it until they
|
||||
* have separated once.
|
||||
*/
|
||||
export function flick(discs: Disc[], hit: number, angleDeg: number, power: number, ghost: number | null = null): FlickResult {
|
||||
const n = discs.length;
|
||||
const x = discs.map((d) => d.x);
|
||||
const y = discs.map((d) => d.y);
|
||||
const vx = new Array<number>(n).fill(0);
|
||||
const vy = new Array<number>(n).fill(0);
|
||||
const out = new Array<boolean>(n).fill(false);
|
||||
const moved = new Array<boolean>(n).fill(false);
|
||||
const a = (angleDeg * Math.PI) / 180;
|
||||
const sp = (Math.max(1, Math.min(100, power)) / 100) * MAX_SPEED;
|
||||
vx[hit] = Math.cos(a) * sp;
|
||||
vy[hit] = Math.sin(a) * sp;
|
||||
moved[hit] = true;
|
||||
let ghostOn = ghost !== null;
|
||||
const frames: Record<number, [number, number][]> = {};
|
||||
const r1 = (v: number) => Math.round(v * 10) / 10;
|
||||
const sample = () => {
|
||||
for (let i = 0; i < n; i++) if (moved[i] && !out[i]) (frames[i] ??= [[r1(discs[i]!.x), r1(discs[i]!.y)]]).push([r1(x[i]!), r1(y[i]!)]);
|
||||
};
|
||||
for (let step = 0; step < MAX_STEPS; step++) {
|
||||
// move + friction
|
||||
let anyMoving = false;
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (out[i]) continue;
|
||||
const v = Math.hypot(vx[i]!, vy[i]!);
|
||||
if (v === 0) continue;
|
||||
const nv = Math.max(0, v - FRICTION * DT);
|
||||
const k = nv / v;
|
||||
vx[i] = vx[i]! * k;
|
||||
vy[i] = vy[i]! * k;
|
||||
x[i] = x[i]! + vx[i]! * DT;
|
||||
y[i] = y[i]! + vy[i]! * DT;
|
||||
if (nv < 0.4) {
|
||||
vx[i] = 0;
|
||||
vy[i] = 0;
|
||||
} else anyMoving = true;
|
||||
if (x[i]! < EDGE_LO || x[i]! > EDGE_HI || y[i]! < EDGE_LO || y[i]! > EDGE_HI) {
|
||||
out[i] = true;
|
||||
vx[i] = 0;
|
||||
vy[i] = 0;
|
||||
}
|
||||
}
|
||||
// collisions (equal radius, masses by piece count)
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (out[i]) continue;
|
||||
for (let j = i + 1; j < n; j++) {
|
||||
if (out[j]) continue;
|
||||
const dx = x[j]! - x[i]!;
|
||||
const dy = y[j]! - y[i]!;
|
||||
const d = Math.hypot(dx, dy);
|
||||
const isGhost = ghostOn && ((i === hit && j === ghost) || (j === hit && i === ghost));
|
||||
if (isGhost) {
|
||||
if (d >= DISC_R * 2) ghostOn = false;
|
||||
continue;
|
||||
}
|
||||
if (d >= DISC_R * 2 || d === 0) continue;
|
||||
const nx = dx / d;
|
||||
const ny = dy / d;
|
||||
const rel = (vx[i]! - vx[j]!) * nx + (vy[i]! - vy[j]!) * ny;
|
||||
// push apart
|
||||
const overlap = DISC_R * 2 - d;
|
||||
const mi = discs[i]!.mass;
|
||||
const mj = discs[j]!.mass;
|
||||
x[i] = x[i]! - nx * overlap * (mj / (mi + mj));
|
||||
y[i] = y[i]! - ny * overlap * (mj / (mi + mj));
|
||||
x[j] = x[j]! + nx * overlap * (mi / (mi + mj));
|
||||
y[j] = y[j]! + ny * overlap * (mi / (mi + mj));
|
||||
if (rel <= 0) continue;
|
||||
const imp = ((1 + RESTITUTION) * rel) / (1 / mi + 1 / mj);
|
||||
vx[i] = vx[i]! - (imp / mi) * nx;
|
||||
vy[i] = vy[i]! - (imp / mi) * ny;
|
||||
vx[j] = vx[j]! + (imp / mj) * nx;
|
||||
vy[j] = vy[j]! + (imp / mj) * ny;
|
||||
moved[i] = true;
|
||||
moved[j] = true;
|
||||
anyMoving = true;
|
||||
}
|
||||
}
|
||||
if (step % SAMPLE_EVERY === 0) sample();
|
||||
if (!anyMoving) break;
|
||||
}
|
||||
sample();
|
||||
return { end: x.map((xi, i) => [xi, y[i]!]), out, moved, frames };
|
||||
}
|
||||
Reference in New Issue
Block a user