Refactor playoff bracket logic to more easily support alternative formats.

This commit is contained in:
Patrick Fairbank
2022-08-03 20:53:16 -07:00
parent 737972f494
commit bfc5e56fc9
15 changed files with 995 additions and 530 deletions

View File

@@ -8,7 +8,6 @@ package web
import (
"fmt"
"github.com/Team254/cheesy-arena-lite/model"
"github.com/Team254/cheesy-arena-lite/tournament"
"net/http"
"strconv"
"time"
@@ -159,6 +158,12 @@ func (web *Web) allianceSelectionResetHandler(w http.ResponseWriter, r *http.Req
return
}
// Replace the current in-memory bracket if it was populated with teams.
if err = web.arena.CreatePlayoffBracket(); err != nil {
handleWebErr(w, err)
return
}
web.arena.AllianceSelectionAlliances = []model.Alliance{}
cachedRankedTeams = []*RankedTeam{}
web.arena.AllianceSelectionNotifier.Notify()
@@ -209,8 +214,11 @@ func (web *Web) allianceSelectionFinalizeHandler(w http.ResponseWriter, r *http.
}
// Generate the first round of elimination matches.
_, err = tournament.UpdateEliminationSchedule(web.arena.Database, startTime)
if err != nil {
if err = web.arena.CreatePlayoffBracket(); err != nil {
handleWebErr(w, err)
return
}
if err = web.arena.UpdatePlayoffBracket(&startTime); err != nil {
handleWebErr(w, err)
return
}