# Check for grand finals reset if is_grand_finals(match) and match.bracket == "losers": if winner_id == lb_champion and wb_champion_exists: create_reset_match() class DoubleElimGenerator constructor(players) this.players = players; this.wbMatches = []; this.lbMatches = []; this.gfMatch = null; this.resetMatch = null; this.generate(); generate() let size = 1; while (size < this.players.length) size <<= 1; const padded = [...this.players, ...Array(size - this.players.length).fill(null)];

# Also send loser to losers bracket loser_id = get_loser(match) lb_match = get_loser_bracket_match(match) set_player_in_match(lb_match, next_free_slot(lb_match), loser_id)

def report_winner(match_id, winner_id): match = get_match(match_id) match.winner_id = winner_id if match.bracket == "winners": next_match = match.next_match slot = match.next_match_slot # "player1" or "player2" set_player_in_match(next_match, slot, winner_id)