루미큐브·다빈치 코드·마작 차례 시간 '무제한' 옵션: 무제한이면 타이머·시간 초과 없음(연결 끊김 처리는 그대로)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -409,7 +409,7 @@ function openWindow(s: MahjongState, source: ClaimWindow['source'], tile: TileId
|
||||
winning,
|
||||
responses: eligible.map(() => null),
|
||||
openedAt: ctx.now,
|
||||
deadline: ctx.now + s.options.claimSeconds * 1000,
|
||||
deadline: unlimited(s) ? null : ctx.now + s.options.claimSeconds * 1000,
|
||||
minUntil: ctx.now + MIN_CLAIM_MS,
|
||||
decided: false,
|
||||
riichiPending,
|
||||
@@ -1017,8 +1017,13 @@ function riichiOk(s: MahjongState, seat: Seat, tile: TileId): boolean {
|
||||
|
||||
// ---------------------------------------------------------------- timers
|
||||
|
||||
function turnLimitMs(s: MahjongState, seat: Seat): number {
|
||||
return s.autoPilot[seat] ? AUTO_MS : s.options.turnSeconds * 1000 + s.timeBank[seat]!;
|
||||
/** turnSeconds 0 = 무제한: no discard clock, no time bank, claim windows wait for every answer. */
|
||||
const unlimited = (s: MahjongState) => s.options.turnSeconds === 0;
|
||||
|
||||
/** null = 무제한 (an auto-piloted seat still gets the short clock). */
|
||||
function turnLimitMs(s: MahjongState, seat: Seat): number | null {
|
||||
if (s.autoPilot[seat]) return AUTO_MS;
|
||||
return unlimited(s) ? null : s.options.turnSeconds * 1000 + s.timeBank[seat]!;
|
||||
}
|
||||
|
||||
function deadlineAt(s: MahjongState): number | null {
|
||||
@@ -1026,7 +1031,10 @@ function deadlineAt(s: MahjongState): number | null {
|
||||
if (s.phase === 'handResult') return s.resultAt + RESULT_MS;
|
||||
const h = H(s);
|
||||
if (h.stage === 'claim') return h.claim!.decided ? h.claim!.minUntil : h.claim!.deadline;
|
||||
if (h.stage === 'afterDraw' || h.stage === 'afterCall') return h.turnStartedAt + turnLimitMs(s, h.turn);
|
||||
if (h.stage === 'afterDraw' || h.stage === 'afterCall') {
|
||||
const ms = turnLimitMs(s, h.turn);
|
||||
return ms === null ? null : h.turnStartedAt + ms;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1336,7 +1344,7 @@ function buildView(s: MahjongState, viewer: PlayerId | null): MahjongView {
|
||||
// Eligible players get their own countdown in `my.claim`.
|
||||
let total = 0;
|
||||
if (s.phase === 'handResult') total = RESULT_MS;
|
||||
else if (live && h.stage !== 'claim') total = turnLimitMs(s, h.turn);
|
||||
else if (live && h.stage !== 'claim') total = turnLimitMs(s, h.turn) ?? 0;
|
||||
return {
|
||||
mode: s.mode,
|
||||
n,
|
||||
@@ -1454,7 +1462,9 @@ export const mahjong: GameDefinition<MahjongState, MahjongAction, MahjongView, M
|
||||
const h = s.hand;
|
||||
// Time bank use for own-turn decisions.
|
||||
if (h && s.phase === 'playing' && h.turn === seat && (h.stage === 'afterDraw' || h.stage === 'afterCall') && a.type !== 'setPref' && a.type !== 'leave') {
|
||||
if (a.type === 'timeout') s.timeBank[seat] = s.autoPilot[seat] ? s.timeBank[seat]! : 0;
|
||||
if (unlimited(s)) {
|
||||
// No clock, nothing to spend.
|
||||
} else if (a.type === 'timeout') s.timeBank[seat] = s.autoPilot[seat] ? s.timeBank[seat]! : 0;
|
||||
else {
|
||||
const over = now - h.turnStartedAt - s.options.turnSeconds * 1000;
|
||||
if (over > 0) s.timeBank[seat] = Math.max(0, s.timeBank[seat]! - over);
|
||||
@@ -1498,7 +1508,7 @@ export const mahjong: GameDefinition<MahjongState, MahjongAction, MahjongView, M
|
||||
const due = c.decided ? c.minUntil : c.deadline;
|
||||
// The discarder's timer only runs once the outcome is settled; it closes the window (also early, when the
|
||||
// server fires it for a disconnected discarder — otherwise that timer would fire again and again).
|
||||
if (now >= due || (c.decided && seat === c.from)) {
|
||||
if ((due !== null && now >= due) || (c.decided && seat === c.from)) {
|
||||
c.eligible.forEach((e, i) => {
|
||||
if (e && !c.responses[i]) {
|
||||
c.responses[i] = { type: 'pass' };
|
||||
|
||||
@@ -1029,6 +1029,23 @@ describe('시간 초과 §8.5', () => {
|
||||
expect(s.timeoutsInRow[1]).toBe(1);
|
||||
expect(s.hand!.turn).toBe(1);
|
||||
});
|
||||
test('무제한(turnSeconds 0): 타패·응답 창 마감 없음, 예비 시간 그대로; 연결 끊긴 응답자는 서버 타이머로 패스', () => {
|
||||
expect(mahjong.optionsSchema.safeParse({ turnSeconds: 0 }).success).toBe(true);
|
||||
expect(mahjong.optionsSchema.safeParse({ turnSeconds: 3 }).success).toBe(false);
|
||||
let s = rig(make(4, { turnSeconds: 0 }), { hands: ['*', T2, '*', '*'], drawn: '5m' });
|
||||
expect(mahjong.deadline!(s)).toBeNull();
|
||||
expect(view(s, 0).deadlineTotalMs).toBe(0);
|
||||
s = act(s, 0, { type: 'discard', tile: codeIn(s, 0, '5m') }, 500_000);
|
||||
expect(s.timeBank[0]).toBe(60_000);
|
||||
expect(s.hand!.stage).toBe('claim');
|
||||
expect(claimOf(s, 1)!.ron).toBe(true);
|
||||
expect(claimOf(s, 1)!.deadline).toBeNull();
|
||||
expect(mahjong.deadline!(s)).toBeNull();
|
||||
// B is disconnected: the room fires B's timeout after the grace period → pass.
|
||||
s = act(s, 1, { type: 'timeout' }, 600_000);
|
||||
expect(s.hand!.turn).toBe(1);
|
||||
expect(s.timeoutsInRow[1]).toBe(1);
|
||||
});
|
||||
test('예비 시간: 기본 시간을 넘긴 만큼 깎이고, 다음 국에 5초 충전', () => {
|
||||
let s = rig(make(4), { hands: ['*', '*', '*', '*'], drawn: '5s' });
|
||||
s = act(s, 0, { type: 'discard', tile: codeIn(s, 0, '5s') }, 25_000);
|
||||
|
||||
@@ -46,7 +46,14 @@ export const mahjongOptionsSchema = z.object({
|
||||
sanmaTsumo: z.enum(['tsumoLoss', 'northBisection']).default('tsumoLoss').meta({ title: '(3인) 쯔모 지불', labels: { tsumoLoss: '쯔모손(북가 몫 없음)', northBisection: '북가 몫을 둘이 반씩' } }),
|
||||
sanmaHonba: lit(200, 300, 1000).default(200).meta({ title: '(3인) 본장 1개당 점수', labels: { 200: '200점', 300: '300점', 1000: '1,000점' } }),
|
||||
sanmaNotenPool: lit(2000, 3000).default(2000).meta({ title: '(3인) 유국 텐파이료 합계', labels: { 2000: '2,000점', 3000: '3,000점' } }),
|
||||
turnSeconds: z.number().int().min(5).max(60).default(15).meta({ title: '타패 제한 시간(초, 5~60)' }),
|
||||
turnSeconds: z
|
||||
.number()
|
||||
.int()
|
||||
.min(0)
|
||||
.max(60)
|
||||
.refine((v) => v === 0 || v >= 5, '5~60초 또는 0(무제한)이어야 해요.')
|
||||
.default(15)
|
||||
.meta({ title: '타패 제한 시간(초, 5~60, 0 = 무제한: 울기·론 응답도 기다려요)' }),
|
||||
claimSeconds: z.number().int().min(3).max(20).default(8).meta({ title: '울기·론 응답 시간(초, 3~20)' }),
|
||||
timeBankSeconds: z.number().int().min(0).max(300).default(60).meta({ title: '개인 예비 시간(초, 0~300)' }),
|
||||
beginnerMode: z.boolean().default(true).meta({ title: '초보 모드 허용(대기패·역 힌트)' }),
|
||||
@@ -118,7 +125,8 @@ export interface ClaimWindow {
|
||||
winning: boolean[];
|
||||
responses: (ClaimResponse | null)[];
|
||||
openedAt: number;
|
||||
deadline: number;
|
||||
/** null = 무제한 (waits for every eligible answer). */
|
||||
deadline: number | null;
|
||||
/** The window never closes before this (information-leak mitigation, §5.3.2). */
|
||||
minUntil: number;
|
||||
/** The outcome is settled; only the minimum delay is left. */
|
||||
@@ -306,7 +314,7 @@ export interface MyView {
|
||||
kakan: string[];
|
||||
canKita: boolean;
|
||||
canKyuushu: boolean;
|
||||
claim: { tile: string; source: ClaimWindow['source']; ron: boolean; pon: string[][]; kan: string[][]; chi: string[][]; responded: boolean; deadline: number; totalMs: number } | null;
|
||||
claim: { tile: string; source: ClaimWindow['source']; ron: boolean; pon: string[][]; kan: string[][]; chi: string[][]; responded: boolean; deadline: number | null; totalMs: number } | null;
|
||||
riichi: boolean;
|
||||
furiten: boolean;
|
||||
/** Current waits (13-tile state), with tiles left from what I can see. */
|
||||
|
||||
Reference in New Issue
Block a user