토너먼트 준비

This commit is contained in:
2026-01-23 16:45:36 +00:00
parent 835886c7a9
commit 2d87cf881e
19 changed files with 744 additions and 4 deletions
+37
View File
@@ -0,0 +1,37 @@
import { LiteHashDRBG } from './LiteHashDRBG.js';
import { RandUtil } from './RandUtil.js';
export interface TournamentRngContext {
openYear: number;
openMonth: number;
stage: number;
phase: number;
matchIndex: number;
participantIndex: number;
gameIndex?: number;
extraSeed?: string | number;
}
const buildTournamentSeedKey = (baseSeed: string, context: TournamentRngContext): string => {
const gameIndex = context.gameIndex !== undefined ? `|game:${context.gameIndex}` : '';
const extraSeed = context.extraSeed !== undefined ? `|extra:${context.extraSeed}` : '';
return [
'Tournament',
`open:${context.openYear}-${context.openMonth}`,
`stage:${context.stage}`,
`phase:${context.phase}`,
`match:${context.matchIndex}`,
`participant:${context.participantIndex}`,
gameIndex,
extraSeed,
`seed:${baseSeed}`,
]
.filter((value) => value.length > 0)
.join('|');
};
export const createTournamentRng = (baseSeed: string, context: TournamentRngContext): RandUtil =>
new RandUtil(LiteHashDRBG.build(buildTournamentSeedKey(baseSeed, context)));
export const createTournamentSeedKey = (baseSeed: string, context: TournamentRngContext): string =>
buildTournamentSeedKey(baseSeed, context);