토너먼트 준비

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
+1
View File
@@ -8,6 +8,7 @@ export * from './util/JosaUtil.js';
export * from './util/RNG.js';
export * from './util/RandUtil.js';
export * from './util/TestRNG.js';
export * from './util/TournamentRNG.js';
export * from './util/sha512.js';
export * from './util/parse.js';
export * from './turnDaemon/types.js';
+26 -2
View File
@@ -85,7 +85,17 @@ export type TurnDaemonCommand =
destGeneralId: number;
destCityId: number;
officerLevel: number;
};
}
| {
type: 'tournamentRefund';
requestId?: string;
bettingId?: number;
reason?: string;
refunds: Array<{
generalId: number;
amount: number;
}>;
};
export type TurnDaemonCommandResult =
| {
@@ -132,7 +142,21 @@ export type TurnDaemonCommandResult =
| { type: 'dropItem'; ok: boolean; generalId: number; reason?: string }
| { type: 'changePermission'; ok: boolean; generalId: number; reason?: string }
| { type: 'kick'; ok: boolean; generalId: number; reason?: string }
| { type: 'appoint'; ok: boolean; generalId: number; reason?: string };
| { type: 'appoint'; ok: boolean; generalId: number; reason?: string }
| {
type: 'tournamentRefund';
ok: true;
bettingId?: number;
processed: number;
missing: number;
totalRefund: number;
}
| {
type: 'tournamentRefund';
ok: false;
bettingId?: number;
reason: string;
};
export type TurnDaemonEvent =
| { type: 'status'; requestId?: string; status: TurnDaemonStatus }
+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);