Make playoff round ordering sequential and increasing.

This commit is contained in:
Patrick Fairbank
2022-08-16 20:03:51 -07:00
parent b6050d8cfc
commit 037df786b7
4 changed files with 80 additions and 84 deletions

View File

@@ -18,7 +18,7 @@ type Bracket struct {
const ElimMatchSpacingSec = 600
// Creates an unpopulated bracket with a format that is defined by the given matchup templates and number of alliances.
func newBracket(matchupTemplates []matchupTemplate, numAlliances int) (*Bracket, error) {
func newBracket(matchupTemplates []matchupTemplate, finalsMatchupKey matchupKey, numAlliances int) (*Bracket, error) {
// Create a map of matchup templates by key for easy lookup while creating the bracket.
matchupTemplateMap := make(map[matchupKey]matchupTemplate, len(matchupTemplates))
for _, matchupTemplate := range matchupTemplates {
@@ -27,11 +27,7 @@ func newBracket(matchupTemplates []matchupTemplate, numAlliances int) (*Bracket,
// Recursively build the bracket, starting with the finals matchup.
finalsMatchup, _, err := createMatchupGraph(
newMatchupKey(1, 1),
true,
matchupTemplateMap,
numAlliances,
make(map[matchupKey]*Matchup),
finalsMatchupKey, true, matchupTemplateMap, numAlliances, make(map[matchupKey]*Matchup),
)
if err != nil {
return nil, err

View File

@@ -12,9 +12,9 @@ import (
)
func TestNewBracketErrors(t *testing.T) {
_, err := newBracket([]matchupTemplate{}, 8)
_, err := newBracket([]matchupTemplate{}, newMatchupKey(33, 12), 8)
if assert.NotNil(t, err) {
assert.Equal(t, "could not find template for matchup {round:1 group:1} in the list of templates", err.Error())
assert.Equal(t, "could not find template for matchup {round:33 group:12} in the list of templates", err.Error())
}
matchTemplate := matchupTemplate{
@@ -22,7 +22,7 @@ func TestNewBracketErrors(t *testing.T) {
redAllianceSource: allianceSource{allianceId: 1},
blueAllianceSource: newWinnerAllianceSource(2, 2),
}
_, err = newBracket([]matchupTemplate{matchTemplate}, 8)
_, err = newBracket([]matchupTemplate{matchTemplate}, newMatchupKey(1, 1), 8)
if assert.NotNil(t, err) {
assert.Equal(t, "both alliances must be populated either from selection or a lower round", err.Error())
}
@@ -33,17 +33,24 @@ func TestNewBracketInverseSeeding(t *testing.T) {
matchupTemplates := []matchupTemplate{
{
matchupKey: newMatchupKey(1, 1),
displayNameFormat: "F-${instance}",
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(2, 1),
blueAllianceSource: newWinnerAllianceSource(2, 2),
redAllianceSource: allianceSource{allianceId: 8},
blueAllianceSource: allianceSource{allianceId: 1},
},
{
matchupKey: newMatchupKey(1, 2),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 5},
blueAllianceSource: allianceSource{allianceId: 4},
},
{
matchupKey: newMatchupKey(2, 1),
displayNameFormat: "SF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(4, 2),
blueAllianceSource: newWinnerAllianceSource(4, 1),
redAllianceSource: newWinnerAllianceSource(1, 2),
blueAllianceSource: newWinnerAllianceSource(1, 1),
},
{
matchupKey: newMatchupKey(2, 2),
@@ -53,23 +60,16 @@ func TestNewBracketInverseSeeding(t *testing.T) {
blueAllianceSource: allianceSource{allianceId: 2},
},
{
matchupKey: newMatchupKey(4, 1),
displayNameFormat: "SF${group}-${instance}",
matchupKey: newMatchupKey(3, 1),
displayNameFormat: "F-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 8},
blueAllianceSource: allianceSource{allianceId: 1},
},
{
matchupKey: newMatchupKey(4, 2),
displayNameFormat: "SF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 5},
blueAllianceSource: allianceSource{allianceId: 4},
redAllianceSource: newWinnerAllianceSource(2, 1),
blueAllianceSource: newWinnerAllianceSource(2, 2),
},
}
tournament.CreateTestAlliances(database, 2)
bracket, err := newBracket(matchupTemplates, 2)
bracket, err := newBracket(matchupTemplates, newMatchupKey(3, 1), 2)
assert.Nil(t, err)
assert.Nil(t, bracket.Update(database, &dummyStartTime))
matches, err := database.GetMatchesByType("elimination")

View File

@@ -16,113 +16,113 @@ func NewSingleEliminationBracket(numAlliances int) (*Bracket, error) {
if numAlliances > 16 {
return nil, fmt.Errorf("Must have at most 16 alliances")
}
return newBracket(singleEliminationBracketMatchupTemplates, numAlliances)
return newBracket(singleEliminationBracketMatchupTemplates, newMatchupKey(4, 1), numAlliances)
}
var singleEliminationBracketMatchupTemplates = []matchupTemplate{
{
matchupKey: newMatchupKey(1, 1),
displayNameFormat: "F-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(2, 1),
blueAllianceSource: newWinnerAllianceSource(2, 2),
},
{
matchupKey: newMatchupKey(2, 1),
displayNameFormat: "SF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(4, 1),
blueAllianceSource: newWinnerAllianceSource(4, 2),
},
{
matchupKey: newMatchupKey(2, 2),
displayNameFormat: "SF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(4, 3),
blueAllianceSource: newWinnerAllianceSource(4, 4),
},
{
matchupKey: newMatchupKey(4, 1),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(8, 1),
blueAllianceSource: newWinnerAllianceSource(8, 2),
},
{
matchupKey: newMatchupKey(4, 2),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(8, 3),
blueAllianceSource: newWinnerAllianceSource(8, 4),
},
{
matchupKey: newMatchupKey(4, 3),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(8, 5),
blueAllianceSource: newWinnerAllianceSource(8, 6),
},
{
matchupKey: newMatchupKey(4, 4),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(8, 7),
blueAllianceSource: newWinnerAllianceSource(8, 8),
},
{
matchupKey: newMatchupKey(8, 1),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 1},
blueAllianceSource: allianceSource{allianceId: 16},
},
{
matchupKey: newMatchupKey(8, 2),
matchupKey: newMatchupKey(1, 2),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 8},
blueAllianceSource: allianceSource{allianceId: 9},
},
{
matchupKey: newMatchupKey(8, 3),
matchupKey: newMatchupKey(1, 3),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 4},
blueAllianceSource: allianceSource{allianceId: 13},
},
{
matchupKey: newMatchupKey(8, 4),
matchupKey: newMatchupKey(1, 4),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 5},
blueAllianceSource: allianceSource{allianceId: 12},
},
{
matchupKey: newMatchupKey(8, 5),
matchupKey: newMatchupKey(1, 5),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 2},
blueAllianceSource: allianceSource{allianceId: 15},
},
{
matchupKey: newMatchupKey(8, 6),
matchupKey: newMatchupKey(1, 6),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 7},
blueAllianceSource: allianceSource{allianceId: 10},
},
{
matchupKey: newMatchupKey(8, 7),
matchupKey: newMatchupKey(1, 7),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 3},
blueAllianceSource: allianceSource{allianceId: 14},
},
{
matchupKey: newMatchupKey(8, 8),
matchupKey: newMatchupKey(1, 8),
displayNameFormat: "EF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: allianceSource{allianceId: 6},
blueAllianceSource: allianceSource{allianceId: 11},
},
{
matchupKey: newMatchupKey(2, 1),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(1, 1),
blueAllianceSource: newWinnerAllianceSource(1, 2),
},
{
matchupKey: newMatchupKey(2, 2),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(1, 3),
blueAllianceSource: newWinnerAllianceSource(1, 4),
},
{
matchupKey: newMatchupKey(2, 3),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(1, 5),
blueAllianceSource: newWinnerAllianceSource(1, 6),
},
{
matchupKey: newMatchupKey(2, 4),
displayNameFormat: "QF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(1, 7),
blueAllianceSource: newWinnerAllianceSource(1, 8),
},
{
matchupKey: newMatchupKey(3, 1),
displayNameFormat: "SF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(2, 1),
blueAllianceSource: newWinnerAllianceSource(2, 2),
},
{
matchupKey: newMatchupKey(3, 2),
displayNameFormat: "SF${group}-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(2, 3),
blueAllianceSource: newWinnerAllianceSource(2, 4),
},
{
matchupKey: newMatchupKey(4, 1),
displayNameFormat: "F-${instance}",
numWinsToAdvance: 2,
redAllianceSource: newWinnerAllianceSource(3, 1),
blueAllianceSource: newWinnerAllianceSource(3, 2),
},
}

View File

@@ -122,7 +122,7 @@ func (database *Database) GetMatchesByType(matchType string) ([]Match, error) {
}
return matchingMatches[i].ElimInstance < matchingMatches[j].ElimInstance
}
return matchingMatches[i].ElimRound > matchingMatches[j].ElimRound
return matchingMatches[i].ElimRound < matchingMatches[j].ElimRound
})
return matchingMatches, nil
}