윷놀이 지역 룰 옵션: 말 없을 때 빽도(버림·다시 던지기·날윷), 낙이면 차례 끝, 던진 순서대로, 업기 고르기, 갈림길 고르기
- 엔진: 새 옵션 5개(기본값은 예전 동작 그대로), MOVE에 piece·alt·stack(선택), 따로 선 무더기는 Piece.group으로 구분 - 컴퓨터: 다른 길·따로 두기·날윷 빽도를 점수로 판단, 따로 선 말도 함께 잡힐 위험으로 계산 - 화면: 방 설정 "지역 룰(우리 동네 규칙)" 묶음(빽도/말 움직이기/던지기, 고른 값 설명, 기본으로 되돌리기), 로비 요약·규칙 보기·도움말에 적용 중인 룰, 게임 중 갈 길 고르기·업기/따로 두기 버튼 - 문서: docs/games/yut.md 2장 표, 7장(추가한 룰·뺀 룰과 이유), 테스트·E2E 갱신 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
THROW_STEPS,
|
||||
advance,
|
||||
defaultPrev,
|
||||
isFork,
|
||||
remainingDistance,
|
||||
rollSticks,
|
||||
type NodeId,
|
||||
@@ -49,6 +50,30 @@ export const yutOptionsSchema = z.object({
|
||||
.enum(['first', 'all'])
|
||||
.default('first')
|
||||
.meta({ title: '3~4명 개인전에서 1등이 나오면', labels: { first: '바로 끝(나머지는 진행도로 순위)', all: '꼴찌가 정해질 때까지 계속' } }),
|
||||
// ---- 지역 룰 (docs/games/yut.md §7). Defaults keep the original rules.
|
||||
backdoNoPiece: z
|
||||
.enum(['discard', 'rethrow', 'enter'])
|
||||
.default('discard')
|
||||
.meta({
|
||||
title: '판에 내 말이 없을 때 빽도가 나오면',
|
||||
labels: { discard: '쓸 곳이 없어 버림', rethrow: '다시 던짐', enter: '새 말이 참먹이 뒤(날윷)로 감' },
|
||||
}),
|
||||
nakRule: z
|
||||
.enum(['keep', 'lose'])
|
||||
.default('keep')
|
||||
.meta({ title: '낙이 나오면', labels: { keep: '그 던지기만 무효(모아 둔 결과는 남음)', lose: '차례가 끝남(모아 둔 결과도 버림)' } }),
|
||||
useOrder: z
|
||||
.enum(['free', 'thrown'])
|
||||
.default('free')
|
||||
.meta({ title: '모아 둔 결과를 쓰는 순서', labels: { free: '원하는 순서로', thrown: '던진 순서대로' } }),
|
||||
stacking: z
|
||||
.enum(['always', 'choose'])
|
||||
.default('always')
|
||||
.meta({ title: '내 말이 있는 자리에 멈추면', labels: { always: '무조건 업음', choose: '업을지 따로 둘지 고름' } }),
|
||||
forkRule: z
|
||||
.enum(['shortcut', 'choose'])
|
||||
.default('shortcut')
|
||||
.meta({ title: '모서리·방에 멈췄다가 출발할 때', labels: { shortcut: '늘 지름길(방에서는 참먹이 쪽)', choose: '갈 길을 고름' } }),
|
||||
turnSeconds: z
|
||||
.union([z.literal(15), z.literal(30), z.literal(60), z.literal(null)])
|
||||
.default(30)
|
||||
@@ -62,6 +87,12 @@ export const yutActionSchema = z.discriminatedUnion('type', [
|
||||
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(),
|
||||
/** 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') }),
|
||||
]);
|
||||
@@ -82,6 +113,11 @@ export interface Piece {
|
||||
lapped: boolean;
|
||||
/** Nodes visited since entering the board, current node last (for 빽도). Shared by a stack. */
|
||||
trail: NodeId[];
|
||||
/**
|
||||
* Stack key when own pieces share a node without being stacked (`stacking = choose`): the lowest piece id of
|
||||
* that stack. Absent = the node's ordinary stack. Pieces on one node with the same key move together.
|
||||
*/
|
||||
group?: number;
|
||||
}
|
||||
|
||||
export interface SideState {
|
||||
@@ -108,6 +144,10 @@ export interface YutMoveInfo {
|
||||
count: number;
|
||||
captured: { side: SideId; count: number }[];
|
||||
stacked: boolean;
|
||||
/** Took the other road at the fork (`forkRule = choose`). */
|
||||
alt?: boolean;
|
||||
/** Stopped on own pieces without stacking (`stacking = choose`). */
|
||||
apart?: boolean;
|
||||
}
|
||||
|
||||
export interface YutStats {
|
||||
@@ -174,6 +214,10 @@ export interface YutLegalMove {
|
||||
captures: number;
|
||||
stacks: boolean;
|
||||
finishes: boolean;
|
||||
/** Action fields that pick this variant (see the MOVE schema); absent for the ordinary move. */
|
||||
piece?: number;
|
||||
alt?: boolean;
|
||||
stack?: false;
|
||||
}
|
||||
|
||||
export interface YutSideView {
|
||||
@@ -193,6 +237,8 @@ export interface YutStackView {
|
||||
node: NodeId;
|
||||
side: SideId;
|
||||
count: number;
|
||||
/** Lowest piece id of the stack, only when one node holds several stacks of this side apart (`stacking = choose`). */
|
||||
piece?: number;
|
||||
}
|
||||
|
||||
export interface YutView {
|
||||
@@ -215,7 +261,7 @@ export interface YutView {
|
||||
/** Only for the player to move (null otherwise). */
|
||||
legalMoves: YutLegalMove[] | null;
|
||||
/** The move a timeout would play (§8.5), for the player to move. */
|
||||
suggested: { throwIndex: number; from: NodeId | 'home' } | null;
|
||||
suggested: Omit<YutMoveAction, 'type'> | null;
|
||||
log: GameEvent[];
|
||||
stats: YutStats;
|
||||
result: YutResult | null;
|
||||
@@ -272,6 +318,36 @@ function pushLog(s: YutState, events: GameEvent[], e: GameEvent): void {
|
||||
if (s.log.length > LOG_MAX) s.log.splice(0, s.log.length - LOG_MAX);
|
||||
}
|
||||
|
||||
/** Pieces of one stack share node and key; `group` is only set while own stacks share a node apart (`stacking = choose`). */
|
||||
const groupKey = (p: Piece) => p.group ?? -1;
|
||||
|
||||
function clearPiece(p: Piece, status: 'home' | 'done'): void {
|
||||
Object.assign(p, { status, node: null, lapped: false, trail: [] });
|
||||
delete p.group;
|
||||
}
|
||||
|
||||
/** Own stacks on the board, by node then lowest piece id; `ids` ascending. */
|
||||
function stacksOf(x: SideState): { node: NodeId; ids: number[] }[] {
|
||||
const byKey = new Map<string, { node: NodeId; ids: number[] }>();
|
||||
for (const p of [...x.pieces].sort((a, b) => a.id - b.id)) {
|
||||
if (p.status !== 'board') continue;
|
||||
const k = `${p.node}:${groupKey(p)}`;
|
||||
const g = byKey.get(k);
|
||||
if (g) g.ids.push(p.id);
|
||||
else byKey.set(k, { node: p.node!, ids: [p.id] });
|
||||
}
|
||||
return [...byKey.values()].sort((a, b) => a.node - b.node || a.ids[0]! - b.ids[0]!);
|
||||
}
|
||||
|
||||
/** A 빽도 that could never be used this turn: no own piece on the board and no forward result to bring one on. */
|
||||
function backdoUseless(s: YutState): boolean {
|
||||
const side = s.sides[s.turnSide]!;
|
||||
return !side.pieces.some((p) => p.status === 'board') && !s.pending.some((t) => t !== 'backdo');
|
||||
}
|
||||
|
||||
/** Variant fields of a MOVE (see the action schema). */
|
||||
type MoveSel = Pick<YutMoveAction, 'piece' | 'alt' | 'stack'>;
|
||||
|
||||
interface Plan {
|
||||
throwIndex: number;
|
||||
throw: Throw;
|
||||
@@ -282,29 +358,46 @@ interface Plan {
|
||||
trailAfter: NodeId[];
|
||||
victims: { side: SideId; ids: number[] }[];
|
||||
stackWith: number[];
|
||||
/** Action selector for the stack on `from` (only when that node holds several own stacks). */
|
||||
piece?: number;
|
||||
alt: boolean;
|
||||
/** Stops on own pieces but stays apart. */
|
||||
apart: boolean;
|
||||
}
|
||||
|
||||
/** Where `from` would go with `pending[throwIndex]`; null if that is not a legal move. */
|
||||
function planMove(s: YutState, sideId: SideId, throwIndex: number, from: NodeId | 'home'): Plan | null {
|
||||
function planMove(s: YutState, sideId: SideId, throwIndex: number, from: NodeId | 'home', sel: MoveSel = {}): Plan | null {
|
||||
const t = s.pending[throwIndex];
|
||||
const side = s.sides[sideId];
|
||||
if (!t || !side) return null;
|
||||
const o = s.options;
|
||||
const alt = sel.alt === true;
|
||||
if (alt && (o.forkRule !== 'choose' || from === 'home' || !isFork(from) || t === 'backdo')) return null;
|
||||
let movers: Piece[];
|
||||
let to: NodeId | typeof GOAL;
|
||||
let path: NodeId[];
|
||||
let trailAfter: NodeId[];
|
||||
if (from === 'home') {
|
||||
if (t === 'backdo') return null;
|
||||
const p = side.pieces.find((x) => x.status === 'home');
|
||||
if (!p) return null;
|
||||
movers = [p];
|
||||
const adv = advance('home', THROW_STEPS[t], o.finishRule);
|
||||
({ to, path } = adv);
|
||||
trailAfter = to === GOAL ? [] : [...path];
|
||||
if (t === 'backdo') {
|
||||
// 지역 룰: with no own piece on the board, a 빽도 puts a new piece one step behind 참먹이 (날윷).
|
||||
if (o.backdoNoPiece !== 'enter' || side.pieces.some((x) => x.status === 'board')) return null;
|
||||
to = 19;
|
||||
path = [19];
|
||||
trailAfter = [19];
|
||||
} else {
|
||||
const adv = advance('home', THROW_STEPS[t], o.finishRule);
|
||||
({ to, path } = adv);
|
||||
trailAfter = to === GOAL ? [] : [...path];
|
||||
}
|
||||
} else {
|
||||
movers = side.pieces.filter((x) => x.status === 'board' && x.node === from);
|
||||
if (movers.length === 0) return null;
|
||||
const here = side.pieces.filter((x) => x.status === 'board' && x.node === from);
|
||||
if (here.length === 0) return null;
|
||||
const lead = sel.piece === undefined ? here.reduce((a, b) => (b.id < a.id ? b : a)) : here.find((x) => x.id === sel.piece);
|
||||
if (!lead) return null;
|
||||
movers = here.filter((x) => groupKey(x) === groupKey(lead));
|
||||
const trail = movers[0]!.trail;
|
||||
if (t === 'backdo') {
|
||||
if (trail.length >= 2) {
|
||||
@@ -319,7 +412,7 @@ function planMove(s: YutState, sideId: SideId, throwIndex: number, from: NodeId
|
||||
}
|
||||
path = to === GOAL ? [] : [to];
|
||||
} else {
|
||||
const adv = advance(from, THROW_STEPS[t], o.finishRule);
|
||||
const adv = advance(from, THROW_STEPS[t], o.finishRule, alt);
|
||||
({ to, path } = adv);
|
||||
trailAfter = to === GOAL ? [] : [...trail, ...path];
|
||||
}
|
||||
@@ -334,28 +427,70 @@ function planMove(s: YutState, sideId: SideId, throwIndex: number, from: NodeId
|
||||
else victims.push({ side: x.id, ids: here });
|
||||
}
|
||||
}
|
||||
return { throwIndex, throw: t, from, to, path, movers: movers.map((p) => p.id), trailAfter, victims, stackWith };
|
||||
const apart = sel.stack === false;
|
||||
if (apart && (o.stacking !== 'choose' || stackWith.length === 0)) return null;
|
||||
return {
|
||||
throwIndex,
|
||||
throw: t,
|
||||
from,
|
||||
to,
|
||||
path,
|
||||
movers: movers.map((p) => p.id),
|
||||
trailAfter,
|
||||
victims,
|
||||
stackWith: apart ? [] : stackWith,
|
||||
...(sel.piece !== undefined ? { piece: sel.piece } : {}),
|
||||
alt,
|
||||
apart,
|
||||
};
|
||||
}
|
||||
|
||||
/** Legal moves of the side to move. Equal results are listed once (first index). Order: index, node, 'home' last. */
|
||||
/**
|
||||
* Legal moves of the side to move. Equal results are listed once (first index; with `useOrder = thrown` only the
|
||||
* first result). Order: index, stack (node, then lowest id), 'home' last; per source the ordinary move first, then
|
||||
* "apart", the other road, other road + apart.
|
||||
*/
|
||||
function legalPlans(s: YutState): Plan[] {
|
||||
if (s.phase !== 'move') return [];
|
||||
const o = s.options;
|
||||
const side = s.sides[s.turnSide]!;
|
||||
const sources: (NodeId | 'home')[] = [...new Set(side.pieces.filter((p) => p.status === 'board').map((p) => p.node!))].sort((a, b) => a - b);
|
||||
if (side.pieces.some((p) => p.status === 'home')) sources.push('home');
|
||||
const stacks = stacksOf(side);
|
||||
const sources: { from: NodeId | 'home'; piece?: number }[] = stacks.map((g) =>
|
||||
stacks.filter((h) => h.node === g.node).length > 1 ? { from: g.node, piece: g.ids[0]! } : { from: g.node },
|
||||
);
|
||||
if (side.pieces.some((p) => p.status === 'home')) sources.push({ from: 'home' });
|
||||
const out: Plan[] = [];
|
||||
const seen = new Set<Throw>();
|
||||
s.pending.forEach((t, i) => {
|
||||
const indices = o.useOrder === 'thrown' ? s.pending.slice(0, 1) : s.pending;
|
||||
indices.forEach((t, i) => {
|
||||
if (seen.has(t)) return;
|
||||
seen.add(t);
|
||||
for (const from of sources) {
|
||||
const p = planMove(s, s.turnSide, i, from);
|
||||
if (p) out.push(p);
|
||||
for (const src of sources) {
|
||||
const roads = o.forkRule === 'choose' && src.from !== 'home' && isFork(src.from) && t !== 'backdo' ? [false, true] : [false];
|
||||
for (const alt of roads) {
|
||||
const sel: MoveSel = { ...(src.piece !== undefined ? { piece: src.piece } : {}), ...(alt ? { alt } : {}) };
|
||||
const p = planMove(s, s.turnSide, i, src.from, sel);
|
||||
if (!p) continue;
|
||||
out.push(p);
|
||||
if (o.stacking === 'choose' && p.stackWith.length) out.push(planMove(s, s.turnSide, i, src.from, { ...sel, stack: false })!);
|
||||
}
|
||||
}
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The MOVE action that plays `p`. */
|
||||
function planAction(p: Plan): YutMoveAction {
|
||||
return {
|
||||
type: 'MOVE',
|
||||
throwIndex: p.throwIndex,
|
||||
from: p.from,
|
||||
...(p.piece !== undefined ? { piece: p.piece } : {}),
|
||||
...(p.alt ? { alt: true } : {}),
|
||||
...(p.apart ? { stack: false } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
const toLegal = (p: Plan): YutLegalMove => ({
|
||||
throwIndex: p.throwIndex,
|
||||
throw: p.throw,
|
||||
@@ -366,14 +501,23 @@ const toLegal = (p: Plan): YutLegalMove => ({
|
||||
captures: p.victims.reduce((a, v) => a + v.ids.length, 0),
|
||||
stacks: p.stackWith.length > 0,
|
||||
finishes: p.to === GOAL,
|
||||
...(p.piece !== undefined ? { piece: p.piece } : {}),
|
||||
...(p.alt ? { alt: true } : {}),
|
||||
...(p.apart ? { stack: false as const } : {}),
|
||||
});
|
||||
|
||||
/** Deterministic auto move (§8.5): capture > finish > stack > most-behind piece with the biggest result > enter > rest. */
|
||||
function chooseAuto(s: YutState, plans: Plan[]): Plan {
|
||||
const rule = s.options.finishRule;
|
||||
const side = s.sides[s.turnSide]!;
|
||||
const flag = (x: boolean) => (x ? 1 : 0);
|
||||
const byTie = (a: Plan, b: Plan) =>
|
||||
a.throwIndex - b.throwIndex || (a.from === 'home' ? 1 : 0) - (b.from === 'home' ? 1 : 0) || (a.from === 'home' ? 0 : a.from) - (b.from === 'home' ? 0 : (b.from as number));
|
||||
a.throwIndex - b.throwIndex ||
|
||||
flag(a.from === 'home') - flag(b.from === 'home') ||
|
||||
(a.from === 'home' ? 0 : a.from) - (b.from === 'home' ? 0 : (b.from as number)) ||
|
||||
(a.piece ?? -1) - (b.piece ?? -1) ||
|
||||
flag(a.alt) - flag(b.alt) ||
|
||||
flag(a.apart) - flag(b.apart);
|
||||
const pick = (list: Plan[], cmp: (a: Plan, b: Plan) => number) => [...list].sort((a, b) => cmp(a, b) || byTie(a, b))[0];
|
||||
const caps = plans.filter((p) => p.victims.length > 0);
|
||||
if (caps.length) return pick(caps, (a, b) => toLegal(b).captures - toLegal(a).captures)!;
|
||||
@@ -394,8 +538,7 @@ export function autoAction(s: YutState): Exclude<YutAction, { type: 'TIMEOUT' }>
|
||||
if (s.phase !== 'move') return { type: 'THROW' };
|
||||
const plans = legalPlans(s);
|
||||
if (plans.length === 0) return { type: 'THROW' }; // unreachable: stuck results are discarded right away
|
||||
const p = chooseAuto(s, plans);
|
||||
return { type: 'MOVE', throwIndex: p.throwIndex, from: p.from };
|
||||
return planAction(chooseAuto(s, plans));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- transitions
|
||||
@@ -482,9 +625,15 @@ function finishGame(s: YutState, events: GameEvent[]): void {
|
||||
pushLog(s, events, { type: 'gameOver', winners, summary });
|
||||
}
|
||||
|
||||
/** In the move phase: if no pending result can be used, discard them all and end the turn (§5.3-2). */
|
||||
/**
|
||||
* In the move phase: if no pending result can be used, discard them all and end the turn (§5.3-2).
|
||||
* With `useOrder = thrown` only the first result counts: an unusable first result is dropped and the next one is tried.
|
||||
*/
|
||||
function settleMovePhase(s: YutState, events: GameEvent[]): void {
|
||||
if (s.phase !== 'move') return;
|
||||
if (s.options.useOrder === 'thrown') {
|
||||
while (s.pending.length && legalPlans(s).length === 0) pushLog(s, events, { type: 'discarded', side: s.turnSide, player: s.current, throws: s.pending.splice(0, 1) });
|
||||
}
|
||||
if (s.pending.length === 0) {
|
||||
endTurn(s, events);
|
||||
return;
|
||||
@@ -501,8 +650,22 @@ function doThrow(s: YutState, rng: Rng, events: GameEvent[]): void {
|
||||
s.stats.throws[r.result] += 1;
|
||||
s.lastThrow = { no: s.throwNo, player: s.current, sticks: r.sticks, result: r.result };
|
||||
s.throwsOwed -= 1;
|
||||
if (r.result === 'nak' && s.options.nakRule === 'lose') {
|
||||
// 지역 룰: a 낙 ends the turn and every unused result of this turn is lost.
|
||||
pushLog(s, events, { type: 'nak', side: s.turnSide, player: s.current, endsTurn: true });
|
||||
if (s.pending.length) pushLog(s, events, { type: 'discarded', side: s.turnSide, player: s.current, throws: [...s.pending] });
|
||||
s.pending = [];
|
||||
s.throwsOwed = 0;
|
||||
endTurn(s, events);
|
||||
return;
|
||||
}
|
||||
if (r.result === 'nak') {
|
||||
pushLog(s, events, { type: 'nak', side: s.turnSide, player: s.current });
|
||||
} else if (r.result === 'backdo' && s.options.backdoNoPiece === 'rethrow' && backdoUseless(s)) {
|
||||
// 지역 룰: a 빽도 that could not be used is not kept; throw again.
|
||||
pushLog(s, events, { type: 'thrown', side: s.turnSide, player: s.current, sticks: r.sticks, result: r.result });
|
||||
pushLog(s, events, { type: 'backdoRethrow', side: s.turnSide, player: s.current });
|
||||
s.throwsOwed += 1;
|
||||
} else {
|
||||
s.pending.push(r.result);
|
||||
if (r.result === 'yut' || r.result === 'mo') s.throwsOwed += 1;
|
||||
@@ -513,20 +676,30 @@ function doThrow(s: YutState, rng: Rng, events: GameEvent[]): void {
|
||||
settleMovePhase(s, events);
|
||||
}
|
||||
|
||||
function doMove(s: YutState, throwIndex: number, from: NodeId | 'home', events: GameEvent[]): void {
|
||||
const plan = planMove(s, s.turnSide, throwIndex, from);
|
||||
if (!plan) throw new Error(`yut: illegal move ${throwIndex} ${from}`);
|
||||
function doMove(s: YutState, a: YutMoveAction, events: GameEvent[]): void {
|
||||
const plan = planMove(s, s.turnSide, a.throwIndex, a.from, a);
|
||||
if (!plan) throw new Error(`yut: illegal move ${a.throwIndex} ${a.from}`);
|
||||
const side = s.sides[s.turnSide]!;
|
||||
s.pending.splice(throwIndex, 1);
|
||||
s.pending.splice(a.throwIndex, 1);
|
||||
const movers = side.pieces.filter((p) => plan.movers.includes(p.id));
|
||||
const lead = Math.min(...plan.movers);
|
||||
for (const p of movers) {
|
||||
if (plan.to === GOAL) Object.assign(p, { status: 'done', node: null, lapped: false, trail: [] });
|
||||
else Object.assign(p, { status: 'board', node: plan.to, lapped: plan.to === 0, trail: [...plan.trailAfter] });
|
||||
if (plan.to === GOAL) clearPiece(p, 'done');
|
||||
else {
|
||||
Object.assign(p, { status: 'board', node: plan.to, lapped: plan.to === 0, trail: [...plan.trailAfter] });
|
||||
// Standing apart next to own pieces keeps a key of its own; otherwise it is the node's ordinary stack.
|
||||
if (plan.apart) p.group = lead;
|
||||
else delete p.group;
|
||||
}
|
||||
}
|
||||
for (const p of side.pieces) {
|
||||
if (!plan.stackWith.includes(p.id)) continue;
|
||||
Object.assign(p, { lapped: plan.to === 0, trail: [...plan.trailAfter] });
|
||||
delete p.group;
|
||||
}
|
||||
for (const p of side.pieces) if (plan.stackWith.includes(p.id)) Object.assign(p, { lapped: plan.to === 0, trail: [...plan.trailAfter] });
|
||||
let caught = 0;
|
||||
for (const v of plan.victims) {
|
||||
for (const p of s.sides[v.side]!.pieces) if (v.ids.includes(p.id)) Object.assign(p, { status: 'home', node: null, lapped: false, trail: [] });
|
||||
for (const p of s.sides[v.side]!.pieces) if (v.ids.includes(p.id)) clearPiece(p, 'home');
|
||||
caught += v.ids.length;
|
||||
}
|
||||
s.moveNo += 1;
|
||||
@@ -541,8 +714,21 @@ function doMove(s: YutState, throwIndex: number, from: NodeId | 'home', events:
|
||||
count: movers.length,
|
||||
captured: plan.victims.map((v) => ({ side: v.side, count: v.ids.length })),
|
||||
stacked: plan.stackWith.length > 0,
|
||||
...(plan.alt ? { alt: true } : {}),
|
||||
...(plan.apart ? { apart: true } : {}),
|
||||
};
|
||||
pushLog(s, events, { type: 'moved', side: side.id, player: s.current, throw: plan.throw, from: plan.from, to: plan.to, path: plan.path, count: movers.length });
|
||||
pushLog(s, events, {
|
||||
type: 'moved',
|
||||
side: side.id,
|
||||
player: s.current,
|
||||
throw: plan.throw,
|
||||
from: plan.from,
|
||||
to: plan.to,
|
||||
path: plan.path,
|
||||
count: movers.length,
|
||||
...(plan.alt ? { alt: true } : {}),
|
||||
...(plan.apart ? { apart: true } : {}),
|
||||
});
|
||||
if (plan.stackWith.length) pushLog(s, events, { type: 'stacked', side: side.id, node: plan.to, count: movers.length + plan.stackWith.length });
|
||||
for (const v of plan.victims) pushLog(s, events, { type: 'captured', side: side.id, victimSide: v.side, count: v.ids.length, node: plan.to });
|
||||
if (caught) s.stats.captures[String(side.id)] = (s.stats.captures[String(side.id)] ?? 0) + 1;
|
||||
@@ -586,7 +772,7 @@ function doConcede(s: YutState, actor: PlayerId, events: GameEvent[]): void {
|
||||
}
|
||||
side.out = true;
|
||||
side.outSeq = ++s.outCount;
|
||||
for (const p of side.pieces) if (p.status === 'board') Object.assign(p, { status: 'home', node: null, lapped: false, trail: [] });
|
||||
for (const p of side.pieces) if (p.status === 'board') clearPiece(p, 'home');
|
||||
if (gameShouldEnd(s)) {
|
||||
finishGame(s, events);
|
||||
return;
|
||||
@@ -694,13 +880,27 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
if (s.phase !== 'move') return fail('지금은 말을 움직일 차례가 아니에요. 먼저 윷을 던져 주세요.');
|
||||
const t = s.pending[a.throwIndex];
|
||||
if (!t) return fail('그 윷 결과는 없어요.');
|
||||
const o = s.options;
|
||||
if (o.useOrder === 'thrown' && a.throwIndex !== 0) return fail('이 방은 던진 순서대로 써요. 맨 앞의 결과부터 써 주세요.');
|
||||
if (a.from === 'home') {
|
||||
if (t === 'backdo') return fail('빽도로는 새 말을 올릴 수 없어요.');
|
||||
if (!side.pieces.some((p) => p.status === 'home')) return fail('기다리는 말이 없어요.');
|
||||
} else if (!side.pieces.some((p) => p.status === 'board' && p.node === a.from)) {
|
||||
if (t === 'backdo') {
|
||||
if (o.backdoNoPiece !== 'enter') return fail('빽도로는 새 말을 올릴 수 없어요.');
|
||||
if (side.pieces.some((p) => p.status === 'board')) return fail('판에 내 말이 있으면 빽도는 판 위의 말에 써야 해요.');
|
||||
}
|
||||
} else if (!side.pieces.some((p) => p.status === 'board' && p.node === a.from && (a.piece === undefined || p.id === a.piece))) {
|
||||
return fail('그 말은 움직일 수 없어요.');
|
||||
}
|
||||
return planMove(s, sideId, a.throwIndex, a.from) ? ok : fail('그 말은 움직일 수 없어요.');
|
||||
if (a.alt) {
|
||||
if (o.forkRule !== 'choose') return fail('이 방은 갈 길을 고르지 않아요. 모서리·방에 멈췄던 말은 늘 지름길로 가요.');
|
||||
if (a.from === 'home' || !isFork(a.from) || t === 'backdo') return fail('모서리나 방에 멈춰 있던 말이 앞으로 갈 때만 길을 고를 수 있어요.');
|
||||
}
|
||||
if (a.stack === false) {
|
||||
if (o.stacking !== 'choose') return fail('이 방은 내 말이 있는 자리에 멈추면 무조건 업어요.');
|
||||
const plain = planMove(s, sideId, a.throwIndex, a.from, { ...a, stack: undefined });
|
||||
if (plain && plain.stackWith.length === 0) return fail('그 자리에는 업을 내 말이 없어요.');
|
||||
}
|
||||
return planMove(s, sideId, a.throwIndex, a.from, a) ? ok : fail('그 말은 움직일 수 없어요.');
|
||||
}
|
||||
}
|
||||
return fail('알 수 없는 행동이에요.');
|
||||
@@ -721,7 +921,7 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
doThrow(s, rng, events);
|
||||
break;
|
||||
case 'MOVE':
|
||||
doMove(s, act.throwIndex, act.from, events);
|
||||
doMove(s, act, events);
|
||||
break;
|
||||
case 'CONCEDE':
|
||||
doConcede(s, actor, events);
|
||||
@@ -736,11 +936,13 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
const mySide = viewer !== null && s.sideOf[viewer] !== undefined ? s.sideOf[viewer]! : null;
|
||||
const stacks: YutStackView[] = [];
|
||||
for (const x of s.sides) {
|
||||
const byNode = new Map<NodeId, number>();
|
||||
for (const p of x.pieces) if (p.status === 'board') byNode.set(p.node!, (byNode.get(p.node!) ?? 0) + 1);
|
||||
for (const [node, count] of byNode) stacks.push({ node, side: x.id, count });
|
||||
const own = stacksOf(x);
|
||||
for (const g of own) {
|
||||
const apart = own.filter((h) => h.node === g.node).length > 1;
|
||||
stacks.push({ node: g.node, side: x.id, count: g.ids.length, ...(apart ? { piece: g.ids[0]! } : {}) });
|
||||
}
|
||||
}
|
||||
stacks.sort((a, b) => a.node - b.node);
|
||||
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 auto = mine && plans.length ? chooseAuto(s, plans) : null;
|
||||
@@ -773,7 +975,7 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
deadlineAt: s.deadlineAt,
|
||||
away: s.players.filter((p) => (s.timeouts[p] ?? 0) >= AWAY_AFTER),
|
||||
legalMoves: mine ? plans.map(toLegal) : null,
|
||||
suggested: auto ? { throwIndex: auto.throwIndex, from: auto.from } : null,
|
||||
suggested: auto ? (({ type: _t, ...rest }) => rest)(planAction(auto)) : null,
|
||||
log: s.log,
|
||||
stats: s.stats,
|
||||
result: s.final,
|
||||
@@ -824,7 +1026,7 @@ export const yut: GameDefinition<YutState, YutAction, YutView, YutOptions> = {
|
||||
legalActions(s, p) {
|
||||
if (s.phase === 'finished' || p !== s.current) return [];
|
||||
if (s.phase === 'throw') return [{ type: 'THROW' }];
|
||||
return legalPlans(s).map((x) => ({ type: 'MOVE' as const, throwIndex: x.throwIndex, from: x.from }));
|
||||
return legalPlans(s).map(planAction);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user