mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Add a playoff alliances report.
This commit is contained in:
@@ -164,17 +164,17 @@ func createMatchupGraph(
|
||||
|
||||
// Returns the winning alliance ID of the entire bracket, or 0 if it is not yet known.
|
||||
func (bracket *Bracket) Winner() int {
|
||||
return bracket.FinalsMatchup.winner()
|
||||
return bracket.FinalsMatchup.Winner()
|
||||
}
|
||||
|
||||
// Returns the finalist alliance ID of the entire bracket, or 0 if it is not yet known.
|
||||
func (bracket *Bracket) Finalist() int {
|
||||
return bracket.FinalsMatchup.loser()
|
||||
return bracket.FinalsMatchup.Loser()
|
||||
}
|
||||
|
||||
// Returns true if the bracket has been won, and false if it is still to be determined.
|
||||
func (bracket *Bracket) IsComplete() bool {
|
||||
return bracket.FinalsMatchup.isComplete()
|
||||
return bracket.FinalsMatchup.IsComplete()
|
||||
}
|
||||
|
||||
// Returns a slice of all matchups contained within the bracket.
|
||||
@@ -230,12 +230,20 @@ func (bracket *Bracket) Update(database *model.Database, startTime *time.Time) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// Prints out each matchup within the bracket in level order, backwards from finals to earlier rounds, for debugging.
|
||||
func (bracket *Bracket) print() {
|
||||
// Performs a traversal of the bracket in reverse order of rounds and invokes the given function for each visited
|
||||
// matchup.
|
||||
func (bracket *Bracket) ReverseRoundOrderTraversal(visitFunction func(*Matchup)) {
|
||||
matchupQueue := []*Matchup{bracket.FinalsMatchup}
|
||||
for len(matchupQueue) > 0 {
|
||||
// Reorder the queue since graph depth doesn't necessarily equate to round.
|
||||
sort.Slice(matchupQueue, func(i, j int) bool {
|
||||
if matchupQueue[i].Round == matchupQueue[j].Round {
|
||||
return matchupQueue[i].Group < matchupQueue[j].Group
|
||||
}
|
||||
return matchupQueue[i].Round > matchupQueue[j].Round
|
||||
})
|
||||
matchup := matchupQueue[0]
|
||||
fmt.Printf("%+v\n\n", matchup)
|
||||
visitFunction(matchup)
|
||||
matchupQueue = matchupQueue[1:]
|
||||
if matchup != nil {
|
||||
if matchup.redAllianceSourceMatchup != nil && matchup.redAllianceSource.useWinner {
|
||||
@@ -247,3 +255,10 @@ func (bracket *Bracket) print() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prints out each matchup within the bracket in level order, backwards from finals to earlier rounds, for debugging.
|
||||
func (bracket *Bracket) print() {
|
||||
bracket.ReverseRoundOrderTraversal(func(matchup *Matchup) {
|
||||
fmt.Printf("%+v\n\n", matchup)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -209,3 +209,25 @@ func TestBracketGetMatchup(t *testing.T) {
|
||||
}
|
||||
assert.Nil(t, matchup)
|
||||
}
|
||||
|
||||
func TestBracketLevelOrderTraversal(t *testing.T) {
|
||||
database := setupTestDb(t)
|
||||
tournament.CreateTestAlliances(database, 8)
|
||||
bracket, err := NewSingleEliminationBracket(8)
|
||||
assert.Nil(t, err)
|
||||
|
||||
var displayNames []string
|
||||
bracket.ReverseRoundOrderTraversal(func(matchup *Matchup) {
|
||||
displayNames = append(displayNames, matchup.displayName)
|
||||
})
|
||||
assert.Equal(t, []string{"F", "SF1", "SF2", "QF1", "QF2", "QF3", "QF4"}, displayNames)
|
||||
|
||||
bracket, err = NewDoubleEliminationBracket(8)
|
||||
assert.Nil(t, err)
|
||||
|
||||
displayNames = nil
|
||||
bracket.ReverseRoundOrderTraversal(func(matchup *Matchup) {
|
||||
displayNames = append(displayNames, matchup.displayName)
|
||||
})
|
||||
assert.Equal(t, []string{"F", "13", "11", "12", "9", "10", "5", "6", "7", "8", "1", "2", "3", "4"}, displayNames)
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (matchup *Matchup) StatusText() (string, string) {
|
||||
}
|
||||
|
||||
// Returns the winning alliance ID of the matchup, or 0 if it is not yet known.
|
||||
func (matchup *Matchup) winner() int {
|
||||
func (matchup *Matchup) Winner() int {
|
||||
if matchup.RedAllianceWins >= matchup.NumWinsToAdvance {
|
||||
return matchup.RedAllianceId
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func (matchup *Matchup) winner() int {
|
||||
}
|
||||
|
||||
// Returns the losing alliance ID of the matchup, or 0 if it is not yet known.
|
||||
func (matchup *Matchup) loser() int {
|
||||
func (matchup *Matchup) Loser() int {
|
||||
if matchup.RedAllianceWins >= matchup.NumWinsToAdvance {
|
||||
return matchup.BlueAllianceId
|
||||
}
|
||||
@@ -157,8 +157,8 @@ func (matchup *Matchup) loser() int {
|
||||
}
|
||||
|
||||
// Returns true if the matchup has been won, and false if it is still to be determined.
|
||||
func (matchup *Matchup) isComplete() bool {
|
||||
return matchup.winner() > 0
|
||||
func (matchup *Matchup) IsComplete() bool {
|
||||
return matchup.Winner() > 0
|
||||
}
|
||||
|
||||
// Returns true if the matchup represents the final matchup in the bracket.
|
||||
@@ -184,16 +184,16 @@ func (matchup *Matchup) update(database *model.Database) error {
|
||||
// Populate the alliance IDs from the lower matchups (or with a zero value if they are not yet complete).
|
||||
if matchup.redAllianceSourceMatchup != nil {
|
||||
if matchup.redAllianceSource.useWinner {
|
||||
matchup.RedAllianceId = matchup.redAllianceSourceMatchup.winner()
|
||||
matchup.RedAllianceId = matchup.redAllianceSourceMatchup.Winner()
|
||||
} else {
|
||||
matchup.RedAllianceId = matchup.redAllianceSourceMatchup.loser()
|
||||
matchup.RedAllianceId = matchup.redAllianceSourceMatchup.Loser()
|
||||
}
|
||||
}
|
||||
if matchup.blueAllianceSourceMatchup != nil {
|
||||
if matchup.blueAllianceSource.useWinner {
|
||||
matchup.BlueAllianceId = matchup.blueAllianceSourceMatchup.winner()
|
||||
matchup.BlueAllianceId = matchup.blueAllianceSourceMatchup.Winner()
|
||||
} else {
|
||||
matchup.BlueAllianceId = matchup.blueAllianceSourceMatchup.loser()
|
||||
matchup.BlueAllianceId = matchup.blueAllianceSourceMatchup.Loser()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user