윷놀이 지역 룰 옵션: 말 없을 때 빽도(버림·다시 던지기·날윷), 낙이면 차례 끝, 던진 순서대로, 업기 고르기, 갈림길 고르기
- 엔진: 새 옵션 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:
@@ -357,6 +357,194 @@ describe('던지기와 이동', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- 지역 룰 (§7)
|
||||
|
||||
describe('지역 룰', () => {
|
||||
test('defaults keep the original rules', () => {
|
||||
expect(yut.defaultOptions).toMatchObject({ backdoNoPiece: 'discard', nakRule: 'keep', useOrder: 'free', stacking: 'always', forkRule: 'shortcut' });
|
||||
});
|
||||
|
||||
test('backdoNoPiece = rethrow: a 빽도 that could not be used is not kept and the player throws again', () => {
|
||||
let s = make({ backdoNoPiece: 'rethrow' });
|
||||
const rng = script(['backdo', 'gae']);
|
||||
const r = actE(s, 'A', { type: 'THROW' }, rng);
|
||||
s = r.state;
|
||||
expect(r.events.map((e) => e.type)).toEqual(['thrown', 'backdoRethrow']);
|
||||
expect([s.current, s.phase, s.throwsOwed, s.pending, s.lastThrow?.result]).toEqual(['A', 'throw', 1, [], 'backdo']);
|
||||
expect(s.stats.throws.backdo).toBe(1);
|
||||
s = throwN(s, rng);
|
||||
expect([s.phase, s.pending]).toEqual(['move', ['gae']]);
|
||||
// With a piece on the board (or a forward result to bring one on) the 빽도 is kept as usual.
|
||||
const b = make({ backdoNoPiece: 'rethrow' });
|
||||
put(b, 0, 0, 3, [1, 2, 3]);
|
||||
expect(act(b, 'A', { type: 'THROW' }, script(['backdo'])).pending).toEqual(['backdo']);
|
||||
const y = throwN(make({ backdoNoPiece: 'rethrow' }), script(['yut', 'backdo']), 2);
|
||||
expect([y.phase, y.pending]).toEqual(['move', ['yut', 'backdo']]);
|
||||
});
|
||||
|
||||
test('backdoNoPiece = enter: with nothing on the board a 빽도 puts a new piece on 날윷(19); 개 from there finishes', () => {
|
||||
let s = moving(make({ backdoNoPiece: 'enter' }), ['backdo', 'gae']);
|
||||
expect(yut.view(s, 'A').legalMoves!.map((m) => [m.throw, m.from, m.to])).toEqual([
|
||||
['backdo', 'home', 19],
|
||||
['gae', 'home', 2],
|
||||
]);
|
||||
s = act(s, 'A', mv(0, 'home'));
|
||||
expect(piece(s, 0, 0)).toMatchObject({ status: 'board', node: 19, trail: [19], lapped: false });
|
||||
s = act(s, 'A', mv(0, 19));
|
||||
expect(piece(s, 0, 0).status).toBe('done');
|
||||
// 도 stops on 참먹이 (pass) — the piece counts as lapped there.
|
||||
let d = moving(make({ backdoNoPiece: 'enter' }), ['backdo', 'do']);
|
||||
d = use(use(d, 'backdo', 'home'), 'do', 19);
|
||||
expect(piece(d, 0, 0)).toMatchObject({ node: 0, lapped: true });
|
||||
// Only while no own piece is on the board; an enemy on 19 is caught.
|
||||
const busy = make({ backdoNoPiece: 'enter' });
|
||||
put(busy, 0, 0, 3, [1, 2, 3]);
|
||||
expect(reject(moving(busy, ['backdo']), 'A', mv(0, 'home'))).toBe('판에 내 말이 있으면 빽도는 판 위의 말에 써야 해요.');
|
||||
expect(reject(moving(make(), ['backdo']), 'A', mv(0, 'home'))).toBe('빽도로는 새 말을 올릴 수 없어요.');
|
||||
const cap = make({ backdoNoPiece: 'enter' });
|
||||
put(cap, 1, 0, 19, [16, 17, 18, 19]);
|
||||
const c = act(moving(cap, ['backdo']), 'A', mv(0, 'home'));
|
||||
expect([piece(c, 1, 0).status, c.phase]).toEqual(['home', 'throw']);
|
||||
});
|
||||
|
||||
test('nakRule = lose: a 낙 ends the turn and the collected results are lost; keep (default) keeps them', () => {
|
||||
let s = make({ nakPercent: 10, nakRule: 'lose' });
|
||||
const rng = script(['yut', 'nak'], true);
|
||||
s = throwN(s, rng);
|
||||
const r = actE(s, 'A', { type: 'THROW' }, rng);
|
||||
s = r.state;
|
||||
expect(r.events.find((e) => e.type === 'nak')).toMatchObject({ endsTurn: true });
|
||||
expect(r.events.find((e) => e.type === 'discarded')).toMatchObject({ throws: ['yut'] });
|
||||
expect([s.current, s.phase, s.pending]).toEqual(['B', 'throw', []]);
|
||||
// Also on a capture-bonus throw: earlier unused results go too.
|
||||
let b = make({ nakPercent: 10, nakRule: 'lose' });
|
||||
put(b, 0, 0, 2, [1, 2]);
|
||||
put(b, 1, 0, 4, [1, 2, 3, 4]);
|
||||
b = use(moving(b, ['gae', 'geol']), 'gae', 2);
|
||||
b = act(b, 'A', { type: 'THROW' }, script(['nak'], true));
|
||||
expect([b.current, b.pending]).toEqual(['B', []]);
|
||||
expect(piece(b, 0, 0).node).toBe(4);
|
||||
});
|
||||
|
||||
test('useOrder = thrown: only the first result can be used; an unusable first result is dropped', () => {
|
||||
let s = moving(make({ useOrder: 'thrown' }), ['yut', 'mo', 'geol']);
|
||||
expect(new Set(yut.legalActions!(s, 'A').map((a) => (a as { throwIndex: number }).throwIndex))).toEqual(new Set([0]));
|
||||
expect(reject(s, 'A', mv(1, 'home'))).toBe('이 방은 던진 순서대로 써요. 맨 앞의 결과부터 써 주세요.');
|
||||
s = act(s, 'A', mv(0, 'home'));
|
||||
expect([piece(s, 0, 0).node, s.pending]).toEqual([4, ['mo', 'geol']]);
|
||||
// Free order (default) may start with 모.
|
||||
expect(yut.validate(moving(make(), ['yut', 'mo', 'geol']), 'A', mv(1, 'home')).ok).toBe(true);
|
||||
// [걸, 빽도, 개] with the only board piece finishing on 걸: the 빽도 has nowhere to go and is dropped, 개 stays.
|
||||
let d = make({ useOrder: 'thrown' });
|
||||
put(d, 0, 0, 18, [16, 17, 18]);
|
||||
const r = actE(moving(d, ['geol', 'backdo', 'gae']), 'A', mv(0, 18));
|
||||
d = r.state;
|
||||
expect(piece(d, 0, 0).status).toBe('done');
|
||||
expect(r.events.find((e) => e.type === 'discarded')).toMatchObject({ throws: ['backdo'] });
|
||||
expect([d.phase, d.pending, d.current]).toEqual(['move', ['gae'], 'A']);
|
||||
});
|
||||
|
||||
test('stacking = choose: stop next to own pieces apart, move each stack on its own, both get caught together', () => {
|
||||
let s = make({ stacking: 'choose' });
|
||||
put(s, 0, 0, 3, [1, 2, 3]);
|
||||
s = moving(s, ['geol', 'gae', 'do']);
|
||||
const lm = yut.view(s, 'A').legalMoves!.filter((m) => m.throw === 'geol' && m.from === 'home');
|
||||
expect(lm.map((m) => [m.to, m.stacks, m.stack])).toEqual([
|
||||
[3, true, undefined],
|
||||
[3, false, false],
|
||||
]);
|
||||
s = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 'home', stack: false });
|
||||
expect(piece(s, 0, 1)).toMatchObject({ node: 3, group: 1 });
|
||||
expect(s.lastMove).toMatchObject({ stacked: false, apart: true });
|
||||
expect(yut.view(s, 'A').stacks).toEqual([
|
||||
{ node: 3, side: 0, count: 1, piece: 0 },
|
||||
{ node: 3, side: 0, count: 1, piece: 1 },
|
||||
]);
|
||||
const from3 = yut.legalActions!(s, 'A').filter((a) => a.type === 'MOVE' && a.from === 3);
|
||||
expect(from3).toContainEqual({ type: 'MOVE', throwIndex: 0, from: 3, piece: 0 });
|
||||
expect(from3).toContainEqual({ type: 'MOVE', throwIndex: 0, from: 3, piece: 1 });
|
||||
s = act(s, 'A', { type: 'MOVE', throwIndex: 0, from: 3, piece: 1 }); // 개: only piece 1 → 5
|
||||
expect([piece(s, 0, 0).node, piece(s, 0, 1).node]).toEqual([3, 5]);
|
||||
expect(piece(s, 0, 1).group).toBeUndefined();
|
||||
// Stacking onto a node that holds two stacks apart merges all of them.
|
||||
let m = make({ stacking: 'choose' });
|
||||
put(m, 0, 0, 4, [1, 2, 3, 4]);
|
||||
put(m, 0, 1, 4, [2, 3, 4]);
|
||||
m.sides[0]!.pieces[1]!.group = 1;
|
||||
put(m, 0, 2, 2, [1, 2]);
|
||||
m = act(moving(m, ['gae']), 'A', mv(0, 2));
|
||||
expect(yut.view(m, 'A').stacks).toEqual([{ node: 4, side: 0, count: 3 }]);
|
||||
expect(m.sides[0]!.pieces.map((p) => p.group)).toEqual([undefined, undefined, undefined, undefined]);
|
||||
// An enemy landing there catches every own piece on the node.
|
||||
let c = make({ stacking: 'choose' });
|
||||
put(c, 1, 0, 3, [1, 2, 3]);
|
||||
put(c, 1, 1, 3, [1, 2, 3]);
|
||||
c.sides[1]!.pieces[1]!.group = 1;
|
||||
const cr = actE(moving(c, ['geol']), 'A', mv(0, 'home'));
|
||||
expect(cr.events.find((e) => e.type === 'captured')).toMatchObject({ count: 2 });
|
||||
expect([piece(cr.state, 1, 0).status, piece(cr.state, 1, 1).status, piece(cr.state, 1, 1).group]).toEqual(['home', 'home', undefined]);
|
||||
});
|
||||
|
||||
test('stacking: validation (always = no choice; apart needs own pieces there; piece must stand on from)', () => {
|
||||
const a = make();
|
||||
put(a, 0, 0, 3, [1, 2, 3]);
|
||||
expect(reject(moving(a, ['geol']), 'A', { type: 'MOVE', throwIndex: 0, from: 'home', stack: false })).toBe('이 방은 내 말이 있는 자리에 멈추면 무조건 업어요.');
|
||||
expect(yut.view(moving(a, ['geol']), 'A').legalMoves!.every((m) => m.stack === undefined)).toBe(true);
|
||||
const c = make({ stacking: 'choose' });
|
||||
put(c, 0, 0, 3, [1, 2, 3]);
|
||||
expect(reject(moving(c, ['gae']), 'A', { type: 'MOVE', throwIndex: 0, from: 'home', stack: false })).toBe('그 자리에는 업을 내 말이 없어요.');
|
||||
expect(reject(moving(c, ['gae']), 'A', { type: 'MOVE', throwIndex: 0, from: 3, piece: 2 })).toBe('그 말은 움직일 수 없어요.');
|
||||
});
|
||||
|
||||
test('forkRule = choose: a piece that stopped on 모 / 뒷모 / 방 may take the other road', () => {
|
||||
const at = (node: NodeId, trail: NodeId[], t: Throw) => {
|
||||
const s = make({ forkRule: 'choose' });
|
||||
put(s, 0, 0, node, trail);
|
||||
return moving(s, [t]);
|
||||
};
|
||||
const roads = (s: YutState) => yut.view(s, 'A').legalMoves!.filter((m) => m.from !== 'home').map((m) => [m.to, m.alt ?? false]);
|
||||
expect(roads(at(5, [1, 2, 3, 4, 5], 'geol'))).toEqual([[22, false], [8, true]]);
|
||||
expect(roads(at(10, [6, 7, 8, 9, 10], 'gae'))).toEqual([[26, false], [12, true]]);
|
||||
expect(roads(at(22, [20, 21, 22], 'do'))).toEqual([[27, false], [23, true]]);
|
||||
expect(roads(at(3, [1, 2, 3], 'do'))).toEqual([[4, false]]);
|
||||
expect(roads(at(5, [4, 5], 'backdo'))).toEqual([[4, false]]);
|
||||
let s = act(at(5, [1, 2, 3, 4, 5], 'geol'), 'A', { type: 'MOVE', throwIndex: 0, from: 5, alt: true });
|
||||
expect(piece(s, 0, 0)).toMatchObject({ node: 8, trail: [1, 2, 3, 4, 5, 6, 7, 8] });
|
||||
expect(s.lastMove).toMatchObject({ alt: true, path: [6, 7, 8] });
|
||||
// 빽도 afterwards walks the recorded road back.
|
||||
s.turnSide = 0;
|
||||
s.current = 'A';
|
||||
s = act(moving(s, ['backdo']), 'A', mv(0, 8));
|
||||
expect(piece(s, 0, 0).node).toBe(7);
|
||||
// Passing a fork is unchanged: 4 + 걸 → 7.
|
||||
expect(roads(at(4, [1, 2, 3, 4], 'geol'))).toEqual([[7, false]]);
|
||||
// The other road can catch.
|
||||
const cap = at(5, [1, 2, 3, 4, 5], 'gae');
|
||||
put(cap, 1, 0, 7, [6, 7]);
|
||||
const c = act(cap, 'A', { type: 'MOVE', throwIndex: 0, from: 5, alt: true });
|
||||
expect([piece(c, 1, 0).status, c.phase]).toEqual(['home', 'throw']);
|
||||
});
|
||||
|
||||
test('forkRule: validation', () => {
|
||||
const s = make();
|
||||
put(s, 0, 0, 5, [1, 2, 3, 4, 5]);
|
||||
expect(reject(moving(s, ['geol']), 'A', { type: 'MOVE', throwIndex: 0, from: 5, alt: true })).toBe('이 방은 갈 길을 고르지 않아요. 모서리·방에 멈췄던 말은 늘 지름길로 가요.');
|
||||
const c = make({ forkRule: 'choose' });
|
||||
put(c, 0, 0, 5, [4, 5]);
|
||||
put(c, 0, 1, 3, [1, 2, 3]);
|
||||
expect(reject(moving(c, ['geol']), 'A', { type: 'MOVE', throwIndex: 0, from: 3, alt: true })).toBe('모서리나 방에 멈춰 있던 말이 앞으로 갈 때만 길을 고를 수 있어요.');
|
||||
expect(reject(moving(c, ['backdo']), 'A', { type: 'MOVE', throwIndex: 0, from: 5, alt: true })).toBe('모서리나 방에 멈춰 있던 말이 앞으로 갈 때만 길을 고를 수 있어요.');
|
||||
expect(reject(moving(c, ['geol']), 'A', { type: 'MOVE', throwIndex: 0, from: 'home', alt: true })).toBe('모서리나 방에 멈춰 있던 말이 앞으로 갈 때만 길을 고를 수 있어요.');
|
||||
});
|
||||
|
||||
test('timeouts pick the ordinary move first (shortcut, stacking)', () => {
|
||||
const s = make({ forkRule: 'choose', stacking: 'choose' });
|
||||
put(s, 0, 0, 5, [1, 2, 3, 4, 5]);
|
||||
put(s, 0, 1, 20, [20]);
|
||||
expect(autoAction(moving(s, ['do']))).toEqual({ type: 'MOVE', throwIndex: 0, from: 5 });
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- turns, teams, ranking
|
||||
|
||||
describe('차례·팀전·순위', () => {
|
||||
@@ -618,6 +806,12 @@ const CONFIGS: Config[] = [
|
||||
{ opts: { mode: 'team', pieces: 5, backdo: false, nakPercent: 3 }, n: 8 },
|
||||
{ opts: { pieces: 5, ranking: 'all', finishRule: 'reach', stickModel: 'fair' }, n: 3 },
|
||||
{ opts: { pieces: 2, nakPercent: 5, turnSeconds: null }, n: 2 },
|
||||
// 지역 룰
|
||||
{ opts: { stacking: 'choose', forkRule: 'choose' }, n: 2 },
|
||||
{ opts: { backdoNoPiece: 'rethrow', useOrder: 'thrown', nakPercent: 10, nakRule: 'lose' }, n: 3 },
|
||||
{ opts: { backdoNoPiece: 'enter', stacking: 'choose', stickModel: 'fair', finishRule: 'reach' }, n: 4 },
|
||||
{ opts: { mode: 'team', forkRule: 'choose', useOrder: 'thrown', backdoNoPiece: 'enter', pieces: 5 }, n: 4 },
|
||||
{ opts: { stacking: 'choose', forkRule: 'choose', backdoNoPiece: 'rethrow', nakPercent: 3, nakRule: 'lose', ranking: 'all', pieces: 5 }, n: 4 },
|
||||
];
|
||||
|
||||
/** Per-step invariants: piece count, one side per node, trail ends on the node, phase consistency, onTimeout legal. */
|
||||
@@ -636,12 +830,21 @@ function invariant(st: unknown): void {
|
||||
occupied.set(p.node, x.id);
|
||||
} else if (p.node !== null || p.trail.length) throw new Error('off-board piece keeps a position');
|
||||
}
|
||||
const stacked = new Map<number, string>();
|
||||
const stacked = new Map<string, string>();
|
||||
for (const p of x.pieces) {
|
||||
if (p.status !== 'board') continue;
|
||||
if (p.status !== 'board') {
|
||||
if (p.group !== undefined) throw new Error('off-board piece keeps a stack key');
|
||||
continue;
|
||||
}
|
||||
if (p.group !== undefined) {
|
||||
if (s.options.stacking !== 'choose') throw new Error('stack key without stacking = choose');
|
||||
const lead = x.pieces[p.group];
|
||||
if (!lead || lead.status !== 'board' || lead.node !== p.node || lead.group !== p.group) throw new Error('stack key without its lead piece');
|
||||
}
|
||||
const k = `${p.node}:${p.group ?? -1}`;
|
||||
const key = JSON.stringify(p.trail);
|
||||
if (stacked.has(p.node!) && stacked.get(p.node!) !== key) throw new Error('stack with different trails');
|
||||
stacked.set(p.node!, key);
|
||||
if (stacked.has(k) && stacked.get(k) !== key) throw new Error('stack with different trails');
|
||||
stacked.set(k, key);
|
||||
}
|
||||
if (x.finishedRank !== null && x.pieces.some((p) => p.status !== 'done')) throw new Error('finished side with pieces left');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user