2022-08-03 20:53:16 -07:00
|
|
|
// Copyright 2022 Team 254. All Rights Reserved.
|
|
|
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
|
//
|
|
|
|
|
// Defines the tournament structure for a single-elimination, best-of-three bracket.
|
|
|
|
|
|
|
|
|
|
package bracket
|
|
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
|
|
// Creates an unpopulated single-elimination bracket containing only the required matchups for the given number of
|
|
|
|
|
// alliances.
|
|
|
|
|
func NewSingleEliminationBracket(numAlliances int) (*Bracket, error) {
|
|
|
|
|
if numAlliances < 2 {
|
|
|
|
|
return nil, fmt.Errorf("Must have at least 2 alliances")
|
|
|
|
|
}
|
|
|
|
|
if numAlliances > 16 {
|
|
|
|
|
return nil, fmt.Errorf("Must have at most 16 alliances")
|
|
|
|
|
}
|
2022-08-16 20:03:51 -07:00
|
|
|
return newBracket(singleEliminationBracketMatchupTemplates, newMatchupKey(4, 1), numAlliances)
|
2022-08-03 20:53:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var singleEliminationBracketMatchupTemplates = []matchupTemplate{
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(1, 1),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF1",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 1},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 16},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 2),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF2",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 8},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 9},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 3),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF3",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 4},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 13},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 4),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF4",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 5},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 12},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 5),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF5",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 2},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 15},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 6),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF6",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 7},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 10},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 7),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF7",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 3},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 14},
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-16 20:03:51 -07:00
|
|
|
matchupKey: newMatchupKey(1, 8),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "EF8",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-03 20:53:16 -07:00
|
|
|
redAllianceSource: allianceSource{allianceId: 6},
|
|
|
|
|
blueAllianceSource: allianceSource{allianceId: 11},
|
|
|
|
|
},
|
2022-08-16 20:03:51 -07:00
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(2, 1),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "QF1",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(1, 1),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(1, 2),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(2, 2),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "QF2",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(1, 3),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(1, 4),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(2, 3),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "QF3",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(1, 5),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(1, 6),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(2, 4),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "QF4",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(1, 7),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(1, 8),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(3, 1),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "SF1",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(2, 1),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(2, 2),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(3, 2),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "SF2",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(2, 3),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(2, 4),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
matchupKey: newMatchupKey(4, 1),
|
2022-08-20 16:01:54 -07:00
|
|
|
displayName: "F",
|
2022-08-17 18:36:21 -07:00
|
|
|
NumWinsToAdvance: 2,
|
2022-08-16 20:03:51 -07:00
|
|
|
redAllianceSource: newWinnerAllianceSource(3, 1),
|
|
|
|
|
blueAllianceSource: newWinnerAllianceSource(3, 2),
|
|
|
|
|
},
|
2022-08-03 20:53:16 -07:00
|
|
|
}
|