diff --git a/docs/games/yut-augmented.md b/docs/games/yut-augmented.md index 9b8856f..d82d504 100644 --- a/docs/games/yut-augmented.md +++ b/docs/games/yut-augmented.md @@ -151,7 +151,7 @@ | `double` | 곱빼기 | 사용·1회 | 갖고 있는 윷 결과 하나를 하나 더 받아요. | | | `gamble` | 올인 | 사용·1회 | 반반 확률로 던지기 3번을 더 받거나, 모아 둔 결과를 모두 잃고 차례가 끝나요. | | | `curse` | 저주 인형 | 사용·1회 | 한 사람을 골라요. 그 사람은 다음 차례에 던질 때마다 도만 나와요. | 던진 차례가 끝나면 풀려요(건너뛴 차례는 세지 않음). 손은 눈보다 빠르다는 저주보다 먼저예요. | -| `freeze` | 얼음! | 사용·1회 | 다른 사람 말뭉치 하나를 2라운드 동안 얼려 못 움직이게 해요. | | +| `freeze` | 얼음! | 사용·1회 | 다른 사람 말뭉치 하나를 2라운드 동안 얼려 못 움직이게 해요. | 같은 칸에 따로 선 말뭉치가 여럿이면 고른 하나만 얼어요(대상은 `target` + `targetPiece`). | | `magnet` | 자석 | 사용·1회 | 내 말뭉치 하나를 골라요. 바로 옆 칸(선으로 이어진 칸)에 있는 다른 사람 말을 모두 끌어와 잡아요. | 잡아도 한 번 더 던지지는 않아요. | | `pushback` | 뒤로 돌아 | 사용·1회 | 다른 사람 말뭉치 하나를 뒤로 3칸 보내요. | 밀려난 칸에 다른 말이 있으면 마녀 모자 함정처럼 그 말을 잡아요. 참먹이를 넘어 뒤로 가게 되는 말뭉치는 고를 수 없어요. | | `underdog` | 꼴찌의 반란 | 규칙 | 내 차례가 시작될 때 내가 혼자 꼴찌면 한 번 더 던져요. | 난 말이 가장 적고, 같으면 남은 거리가 가장 먼 사람이 꼴찌예요. | @@ -180,7 +180,7 @@ 관리자 화면에서 기본값·잠금을 정할 수 있다(`augOff`는 체크 목록). ## 6. 액션 -`THROW {pick?: 'do'|'gae'}`(개돼지), `MOVE {piece?}`(대기 특수 말은 `from:'home', piece`), `AUG_PICK {aug, target?}`(명탐정·배달 대상), `AUG_ANSWER {choice}`(계획대로는 순서 배열), `AUG_USE {uid, piece?, node?, node2?, target?, result?, angle?, power?}`, `SPECIAL {piece, to}`(도깨비·포). +`THROW {pick?: 'do'|'gae'}`(개돼지), `MOVE {piece?}`(대기 특수 말은 `from:'home', piece`), `AUG_PICK {aug, target?}`(명탐정·배달 대상), `AUG_ANSWER {choice}`(계획대로는 순서 배열), `AUG_USE {uid, piece?, node?, node2?, target?, targetPiece?, result?, angle?, power?}`(`targetPiece`: 얼음!·뒤로 돌아·자리 바꾸기의 상대 말뭉치), `SPECIAL {piece, to}`(도깨비·포). ## 7. 화면 - 오른쪽 위 라운드 막대: "N라운드 · 다음 증강 선택 M라운드", 메아리·안개·취소 표시. diff --git a/packages/games/src/yut/aug-bot.ts b/packages/games/src/yut/aug-bot.ts index 44749af..7b1463a 100644 --- a/packages/games/src/yut/aug-bot.ts +++ b/packages/games/src/yut/aug-bot.ts @@ -81,7 +81,7 @@ export function augBotAction(view: YutView, legal: A[], random: () => number): A } // ---- my turn: abilities before throwing / moving const uses = has('AUG_USE') as Extract[]; - const opt = (a: Extract) => 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 opt = (a: Extract) => 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.targetPiece === a.targetPiece && u.action.result === a.result); const idOf = (a: Extract) => 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) => { diff --git a/packages/games/src/yut/aug.test.ts b/packages/games/src/yut/aug.test.ts index 755c315..92c5364 100644 --- a/packages/games/src/yut/aug.test.ts +++ b/packages/games/src/yut/aug.test.ts @@ -772,11 +772,28 @@ describe('증강 윷놀이: 이 사이트 추가 증강', () => { const s = make(); give(s, 0, 'freeze'); put(s, 1, 0, 9); - const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'freeze'), target: 1, node: 9 }); + const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'freeze'), target: 1, node: 9, targetPiece: 0 }); expect(t.sides[1]!.pieces[0]!.frozenUntil).toBe(t.aug!.round + 2); expect(yut.view(t, 'B').stacks.find((st) => st.side === 1)).toMatchObject({ node: 9, frozen: true }); }); + test('얼음! and 뒤로 돌아 hit only the chosen stack when two stand apart on one node', () => { + const s = make(2, { stacking: 'choose' }); + give(s, 0, 'freeze'); + give(s, 0, 'pushback'); + put(s, 1, 0, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]); + put(s, 1, 1, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]); + s.sides[1]!.pieces[1]!.group = 1; // standing apart from piece 0 + const v = yut.view(s, 'A').aug!.uses; + expect(v.filter((u) => u.id === 'freeze').map((u) => u.action.targetPiece)).toEqual([0, 1]); + expect(v.filter((u) => u.id === 'pushback').map((u) => u.action.targetPiece)).toEqual([0, 1]); + let t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'freeze'), target: 1, node: 9, targetPiece: 1 }); + expect(t.sides[1]!.pieces[0]!.frozenUntil).toBeUndefined(); + expect(t.sides[1]!.pieces[1]!.frozenUntil).toBe(t.aug!.round + 2); + t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'pushback'), target: 1, node: 9, targetPiece: 1 }); + expect(nodesOf(t, 1).slice(0, 2)).toEqual([9, 6]); + }); + test('자석 catches the enemy pieces next to my stack', () => { const s = make(); give(s, 0, 'magnet'); @@ -798,7 +815,7 @@ describe('증강 윷놀이: 이 사이트 추가 증강', () => { put(s, 0, 0, 6); const opts = yut.view(s, 'A').aug!.uses.filter((u) => u.id === 'pushback'); expect(opts.map((u) => u.action.node)).toEqual([9]); - const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'pushback'), target: 1, node: 9 }); + const t = act(s, 'A', { type: 'AUG_USE', uid: uidOf(s, 0, 'pushback'), target: 1, node: 9, targetPiece: 0 }); expect(nodesOf(t, 1)[0]).toBe(6); expect(nodesOf(t, 0)[0]).toBe('home'); }); diff --git a/packages/games/src/yut/aug.ts b/packages/games/src/yut/aug.ts index 85cc60e..1d2fbd2 100644 --- a/packages/games/src/yut/aug.ts +++ b/packages/games/src/yut/aug.ts @@ -181,6 +181,8 @@ export type AugUse = { node?: number; node2?: number; target?: number; + /** A piece in the other player's target stack (several stacks may share a node). */ + targetPiece?: number; result?: Throw; angle?: number; power?: number; @@ -2467,7 +2469,7 @@ export function useOptions(s: YutState, side: SideId): AugUseOption[] { for (const g of stacks) for (const y of s.sides) { if (y.id === side || !sideActive(y)) continue; - for (const h of stacksAug(y)) if (h.node !== g.node) add({ piece: g.ids[0]!, target: y.id, node: h.node }, `${pieceLabel(s, side, g.ps)} ↔ ${nm(y.id)} ${nodeKo(h.node)}`); + for (const h of stacksAug(y)) if (h.node !== g.node) add({ piece: g.ids[0]!, target: y.id, node: h.node, targetPiece: h.ids[0]! }, `${pieceLabel(s, side, g.ps)} ↔ ${nm(y.id)} ${pieceLabel(s, y.id, y.pieces.filter((p) => h.ids.includes(p.id)))}`); } break; case 'reroll': @@ -2486,17 +2488,14 @@ export function useOptions(s: YutState, side: SideId): AugUseOption[] { case 'pushback': for (const y of s.sides) { if (y.id === side || !sideActive(y)) continue; - const seen = new Set(); for (const h of stacksAug(y)) { - if (seen.has(h.node)) continue; - seen.add(h.node); const ps = y.pieces.filter((p) => h.ids.includes(p.id)); if (o.id === 'freeze') { - if (!ps.every((p) => frozen(s, p))) add({ target: y.id, node: h.node }, `${nm(y.id)} ${pieceLabel(s, y.id, ps)}`); + if (!ps.every((p) => frozen(s, p))) add({ target: y.id, node: h.node, targetPiece: h.ids[0]! }, `${nm(y.id)} ${pieceLabel(s, y.id, ps)}`); } else { const b = walkBack(s, y.id, h.node, ps[0]!.trail, 3); // never past 참먹이 (that would put the stack next to the finish) - if (b.to !== GOAL && !b.path.includes(0)) add({ target: y.id, node: h.node }, `${nm(y.id)} ${pieceLabel(s, y.id, ps)} → ${nodeKo(b.to)}`, previewKills(s, y.id, b.to, h.ids, true)); + if (b.to !== GOAL && !b.path.includes(0)) add({ target: y.id, node: h.node, targetPiece: h.ids[0]! }, `${nm(y.id)} ${pieceLabel(s, y.id, ps)} → ${nodeKo(b.to)}`, previewKills(s, y.id, b.to, h.ids, true)); } } } @@ -2517,7 +2516,7 @@ export function useOptions(s: YutState, side: SideId): AugUseOption[] { } function sameUse(a: Omit, b: Omit): boolean { - const keys: (keyof AugUse)[] = ['uid', 'piece', 'node', 'node2', 'target', 'result']; + const keys: (keyof AugUse)[] = ['uid', 'piece', 'node', 'node2', 'target', 'targetPiece', 'result']; return keys.every((k) => a[k as keyof typeof a] === b[k as keyof typeof b]); } @@ -2724,8 +2723,7 @@ function applyUse(s: YutState, ctx: Ctx, side: SideId, act: AugUse): void { case 'swap': { const mine = stackOf(act.piece!); const y = s.sides[act.target!]!; - const g = stacksAug(y).find((h) => h.node === act.node!)!; - const theirs = y.pieces.filter((p) => g.ids.includes(p.id)); + const theirs = stackOfPiece(y, act.targetPiece!); const myNode = mine[0]!.node!; for (const p of mine) relocate(p, act.node!); for (const p of theirs) relocate(p, myNode); @@ -2763,14 +2761,13 @@ function applyUse(s: YutState, ctx: Ctx, side: SideId, act: AugUse): void { break; case 'freeze': { const y = s.sides[act.target!]!; - for (const p of y.pieces) if (p.status === 'board' && p.node === act.node) p.frozenUntil = Math.max(p.frozenUntil ?? 0, a.round + 2); + for (const p of stackOfPiece(y, act.targetPiece!)) p.frozenUntil = Math.max(p.frozenUntil ?? 0, a.round + 2); say(`얼음! ${nm(y.id)}의 ${nodeKo(act.node!)} 말이 2라운드 동안 얼었어요`); break; } case 'pushback': { const y = s.sides[act.target!]!; - const g = stacksAug(y).find((h) => h.node === act.node!)!; - const ps = y.pieces.filter((p) => g.ids.includes(p.id)); + const ps = stackOfPiece(y, act.targetPiece!); const b = walkBack(s, y.id, act.node!, ps[0]!.trail, 3); say(`뒤로 돌아: ${nm(y.id)}의 ${nodeKo(act.node!)} 말이 ${nodeKo(b.to as NodeId)}까지 밀려났어요`); shiftStack(s, ctx, y.id, ps, b.to, b.trail); diff --git a/packages/games/src/yut/index.ts b/packages/games/src/yut/index.ts index cbe0e0d..ec5df9d 100644 --- a/packages/games/src/yut/index.ts +++ b/packages/games/src/yut/index.ts @@ -146,6 +146,8 @@ export const yutActionSchema = z.discriminatedUnion('type', [ node: NODE_NO.optional(), node2: NODE_NO.optional(), target: z.number().int().min(0).max(7).optional(), + /** Another player's stack (any piece id in it): 얼음!, 뒤로 돌아, 자리 바꾸기. */ + targetPiece: PIECE_NO.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(),