diff --git a/libs/go/challonge/challonge.go b/libs/go/challonge/challonge.go index 21f3b77..2359f27 100644 --- a/libs/go/challonge/challonge.go +++ b/libs/go/challonge/challonge.go @@ -337,7 +337,7 @@ func (c *Challonge) getNextMatchForTable(table int) (*Match, error) { } // set race for a/b side - if match.IsOnASide() { + if c.Tournament.matchIsDoubleDip(match) || (!c.Tournament.matchIsDoubleDip(match) && match.IsOnASide()) { if err := c.tables[table].Game.SetRaceTo(c.Settings.ASideRaceTo); err != nil { return nil, err } diff --git a/libs/go/challonge/tournament.go b/libs/go/challonge/tournament.go index eeddeaa..2c670a5 100644 --- a/libs/go/challonge/tournament.go +++ b/libs/go/challonge/tournament.go @@ -28,14 +28,15 @@ type ParticipantsResp []struct { // Tournament is a tournament bracket on the Challonge account. type Tournament struct { - ID int `json:"id"` - Name string `json:"name"` - URL string `json:"url"` - TournamentType string `json:"tournament_type"` - Rounds int `json:"rounds"` - Matches []*Match `json:"matches"` - CreatedAt time.Time `json:"created_at"` - CompletedAt *time.Time `json:"completed_at"` + ID int `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + TournamentType string `json:"tournament_type"` + ParticipantsCount int `json:"participants_count"` + Rounds int `json:"rounds"` + Matches []*Match `json:"matches"` + CreatedAt time.Time `json:"created_at"` + CompletedAt *time.Time `json:"completed_at"` Participants []*Participant `json:"participants"` } @@ -265,6 +266,21 @@ func (t *Tournament) getParticipants(username, apiKey string) error { return nil } +// Returns if the match is the last possible match in the tournament +func (t *Tournament) matchIsDoubleDip(match *Match) bool { + if t.TournamentType == "double elimination" && match.SuggestedPlayOrder == t.getTotalMatchCount() { + return true + } + + return false +} + +// Returns the total number of matches possible, including the double dip +func (t *Tournament) getTotalMatchCount() int { + // TODO: handle single elimination here + return ((t.ParticipantsCount - 1) * 2) + 1 +} + func (t *Tournament) getMatchesByPlayOrder() []*Match { sortedMatches := make([]*Match, len(t.Matches)) copy(sortedMatches, t.Matches) @@ -304,7 +320,7 @@ func getLatestTournaments(username, apiKey string) ([]*Tournament, error) { for _, tournament := range tournamentsResp { currentTournament := tournament.Tournament - if currentTournament.CompletedAt == nil { + if currentTournament.CompletedAt == nil { tournaments = append(tournaments, ¤tTournament) } }