루미큐브·다빈치 코드·마작 차례 시간 '무제한' 옵션: 무제한이면 타이머·시간 초과 없음(연결 끊김 처리는 그대로)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,16 +20,16 @@ import {
|
||||
|
||||
export * from './rules';
|
||||
|
||||
const lit = <T extends number>(...vals: T[]) =>
|
||||
const lit = <T extends number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
export const rummikubOptionsSchema = z.object({
|
||||
initialMeldPoints: lit(0, 20, 30, 50)
|
||||
.default(30)
|
||||
.meta({ title: '첫 등록 최소 점수', labels: { 0: '없음', 20: '20점', 30: '30점(공식)', 50: '50점' } }),
|
||||
turnSeconds: lit(60, 90, 120, 180)
|
||||
turnSeconds: lit(60, 90, 120, 180, null)
|
||||
.default(60)
|
||||
.meta({ title: '한 차례 제한 시간', labels: { 60: '1분(공식)', 90: '1분 30초', 120: '2분', 180: '3분' } }),
|
||||
.meta({ title: '한 차례 제한 시간', labels: { 60: '1분(공식)', 90: '1분 30초', 120: '2분', 180: '3분', null: '무제한' } }),
|
||||
timeoutValidDraft: z
|
||||
.enum(['commit', 'revert'])
|
||||
.default('commit')
|
||||
@@ -185,6 +185,7 @@ export interface RummikubView {
|
||||
current: PlayerId | null;
|
||||
turnNo: number;
|
||||
turnStartedAt: number;
|
||||
/** 0 = 무제한. */
|
||||
turnMs: number;
|
||||
poolCount: number;
|
||||
table: TableSet[];
|
||||
@@ -215,6 +216,12 @@ export interface RummikubView {
|
||||
// ---------------------------------------------------------------- helpers
|
||||
|
||||
const AWAY_MS = 3000;
|
||||
|
||||
/** The current turn's time limit; null = 무제한 (a disconnected, auto-played player still gets the short one). */
|
||||
function turnLimitMs(s: RummikubState): number | null {
|
||||
if ((s.timeoutsInRow[s.current] ?? 0) >= 3) return AWAY_MS;
|
||||
return s.options.turnSeconds === null ? null : s.options.turnSeconds * 1000;
|
||||
}
|
||||
const ROUND_END_MS = 30_000;
|
||||
const HISTORY_MAX = 100;
|
||||
|
||||
@@ -712,7 +719,7 @@ export const rummikub: GameDefinition<RummikubState, RummikubAction, RummikubVie
|
||||
current: playing ? s.current : null,
|
||||
turnNo: s.turnNo,
|
||||
turnStartedAt: s.turnStartedAt,
|
||||
turnMs: (s.timeoutsInRow[s.current] ?? 0) >= 3 ? AWAY_MS : s.options.turnSeconds * 1000,
|
||||
turnMs: turnLimitMs(s) ?? 0,
|
||||
poolCount: s.pool.length,
|
||||
table: s.table,
|
||||
lastChanged: s.lastChanged,
|
||||
@@ -748,7 +755,10 @@ export const rummikub: GameDefinition<RummikubState, RummikubAction, RummikubVie
|
||||
},
|
||||
|
||||
deadline(s) {
|
||||
if (s.phase === 'playing') return s.turnStartedAt + ((s.timeoutsInRow[s.current] ?? 0) >= 3 ? AWAY_MS : s.options.turnSeconds * 1000);
|
||||
if (s.phase === 'playing') {
|
||||
const ms = turnLimitMs(s);
|
||||
return ms === null ? null : s.turnStartedAt + ms;
|
||||
}
|
||||
if (s.phase === 'roundEnd') return (s.roundEndAt ?? 0) + ROUND_END_MS;
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -421,6 +421,22 @@ describe('시간 초과 (§5.7, §8.5)', () => {
|
||||
s = act(s, p, { type: 'draw' });
|
||||
expect(s.timeoutsInRow[p]).toBe(0);
|
||||
});
|
||||
|
||||
test('무제한: 차례 마감이 없고(타이머 0), 연결이 끊겨 3번 넘어간 사람만 짧은 마감', () => {
|
||||
let s = mk({ turnSeconds: null }, ['A', 'B'], 2);
|
||||
expect(rummikub.deadline!(s)).toBeNull();
|
||||
expect(rummikub.view(s, null).turnMs).toBe(0);
|
||||
const p = s.current;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
s = act(s, p, { type: 'timeout' });
|
||||
expect(rummikub.deadline!(s)).toBeNull();
|
||||
s = act(s, s.current, { type: 'draw' });
|
||||
}
|
||||
expect(rummikub.deadline!(s)).toBe(s.turnStartedAt + 3000);
|
||||
s = act(s, p, { type: 'draw' });
|
||||
s = act(s, s.current, { type: 'draw' });
|
||||
expect(rummikub.deadline!(s)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- scoring / end
|
||||
|
||||
Reference in New Issue
Block a user