feat: tournament engine with single-elimination brackets

Create, join, seed by Elo, generate bracket matches with byes,
advance rounds on fight completion, finish tournament on champion.
Wire into orchestrator fight finalization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 20:57:23 +00:00
co-authored by Claude Opus 4.6
parent 4dfa49c036
commit c0978ba4c8
2 changed files with 381 additions and 0 deletions
+4
View File
@@ -13,6 +13,7 @@ import { payWinner, refundEntry, ENTRY_FEE_SATS } from './payments.js'
import { settleBets, lockBets } from './betting.js'
import { publishFightResult } from './nostr-publish.js'
import { getCurrentSeason } from './seasons.js'
import { onFightFinished as onTournamentFightFinished } from './tournaments.js'
interface BotRecord {
id: string
@@ -514,6 +515,9 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
finalize()
// Advance tournament bracket if this was a tournament match
try { onTournamentFightFinished(fightId, winnerId ?? null) } catch { /* not a tournament fight */ }
emit(fightId, 'fight_end', {
winnerId,
winnerName,