Documentation ¶
Index ¶
- func DivideRoundDown(a int, b int) int
- func DivideRoundUp(a int, b int) int
- func NumberOfGamesForEliminationTournament(teamCount int) int
- func NumberOfGamesForGroupTournament(teamCount int, groupCount int, meetCount int) int
- func PrintGroupTournamentStats(teamStats []TeamStatsInterface) string
- func WinnerChanged(oldGame GameInterface, newGame GameInterface) bool
- type Game
- func (g *Game) GetAwayScore() ScoreInterface
- func (g *Game) GetAwayTeam() TeamInterface
- func (g *Game) GetHomeScore() ScoreInterface
- func (g *Game) GetHomeTeam() TeamInterface
- func (g *Game) GetID() int
- func (g *Game) GetParentIDs() []int
- func (g *Game) GetScores() []ScoreInterface
- func (g *Game) GetTeams() []TeamInterface
- func (g *Game) Print() string
- func (g *Game) SetAwayTeam(t TeamInterface)
- func (g *Game) SetHomeTeam(t TeamInterface)
- func (g *Game) SetScore(homeScore float64, awayScore float64)
- type GameInterface
- type Group
- func (t *Group) AppendGame(game GameInterface)
- func (t *Group) AppendGames(games []GameInterface)
- func (t *Group) AppendTeam(team TeamInterface)
- func (t *Group) AppendTeams(teams []TeamInterface)
- func (t *Group) GetGames() *[]GameInterface
- func (t *Group) GetID() int
- func (t *Group) GetTeams() *[]TeamInterface
- func (t *Group) Print() string
- func (t *Group) RemoveGame(game GameInterface)
- type GroupInterface
- type Score
- type ScoreInterface
- type Team
- type TeamInterface
- type TeamStats
- func (t *TeamStats) AddPoints(points int)
- func (t *TeamStats) GetDiff() float64
- func (t *TeamStats) GetGroup() GroupInterface
- func (t *TeamStats) GetLosses() int
- func (t *TeamStats) GetPlayed() int
- func (t *TeamStats) GetPoints() int
- func (t *TeamStats) GetPointsAgainst() float64
- func (t *TeamStats) GetPointsFor() float64
- func (t *TeamStats) GetTeam() TeamInterface
- func (t *TeamStats) GetTies() int
- func (t *TeamStats) GetWins() int
- func (t *TeamStats) Print() string
- type TeamStatsInterface
- func GetGroupStats(group GroupInterface, winPoints int, lossPoints int, tiePoints int) []TeamStatsInterface
- func GetGroupTournamentStats(t TournamentInterface, winPoints int, lossPoints int, tiePoints int) ([]TeamStatsInterface, error)
- func SortTournamentStats(stats []TeamStatsInterface) []TeamStatsInterface
- type Tournament
- func (t *Tournament) AppendGame(game GameInterface)
- func (t *Tournament) GetEliminatedTeams() []TeamInterface
- func (t *Tournament) GetGameByID(id int) GameInterface
- func (t *Tournament) GetGameDepth(game GameInterface) int
- func (t *Tournament) GetGameFirstAncestorID(game GameInterface) int
- func (t *Tournament) GetGameLastDescendantID(game GameInterface) int
- func (t *Tournament) GetGames() []GameInterface
- func (t *Tournament) GetGamesAtDepth(depth int) (games []GameInterface)
- func (t *Tournament) GetGroups() []GroupInterface
- func (t *Tournament) GetRemainingTeams() []TeamInterface
- func (t *Tournament) GetTeams() []TeamInterface
- func (t *Tournament) GetType() int
- func (t *Tournament) GetTypeString() string
- func (t *Tournament) IsDepthFull(depth int) bool
- func (t *Tournament) MakeTeamEliminated(team TeamInterface)
- func (t *Tournament) MakeTeamRemain(team TeamInterface)
- func (t *Tournament) Print() string
- func (t *Tournament) SetGame(game GameInterface) error
- func (t *Tournament) SetGameScore(game GameInterface, homeScore float64, awayScore float64) error
- func (t *Tournament) SetGames(games []GameInterface)
- type TournamentInterface
- func CreateEliminationTournamentFromTeams(teams []TeamInterface) TournamentInterface
- func CreateGroupTournamentFromGroups(groups []GroupInterface, meetCount int) TournamentInterface
- func CreateGroupTournamentFromTeams(teams []TeamInterface, groupCount int, meetCount int) TournamentInterface
- func CreateTournament(teamCount int, meetCount int, groupCount int, tournamentType int) TournamentInterface
- func CreateTournamentFromTeams(teams []TeamInterface, meetCount int, groupCount int, tournamentType int) TournamentInterface
- type TournamentType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DivideRoundDown ¶
DivideRoundDown takes two ints, divides them and rounds the result up to the nearest int
func DivideRoundUp ¶
DivideRoundUp takes two ints, divides them and rounds the result up to the nearest int
func NumberOfGamesForEliminationTournament ¶
NumberOfGamesForEliminationTournament Calculates the number of games in a elimination tournament based on the number of teams
func NumberOfGamesForGroupTournament ¶
NumberOfGamesForGroupTournament Calculates the number of games in a group tournament based on number of teams, groups and unique encounters. This is unreliable with uneven numbers.
func PrintGroupTournamentStats ¶
func PrintGroupTournamentStats(teamStats []TeamStatsInterface) string
PrintGroupTournamentStats takes an array of team stats and returns them as a single string with a new line for each team
func WinnerChanged ¶
func WinnerChanged(oldGame GameInterface, newGame GameInterface) bool
Types ¶
type Game ¶
type Game struct { ID int ParentIDs []int Scores []ScoreInterface Teams []TeamInterface }
Game is a default struct used as an example of how structs can be implemented for tournify
func (*Game) GetAwayScore ¶
func (g *Game) GetAwayScore() ScoreInterface
GetAwayScore returns the second score in the Scores slice
func (*Game) GetAwayTeam ¶
func (g *Game) GetAwayTeam() TeamInterface
GetAwayTeam returns the second team in the Teams slice
func (*Game) GetHomeScore ¶
func (g *Game) GetHomeScore() ScoreInterface
GetHomeScore returns the first score in the Scores slice
func (*Game) GetHomeTeam ¶
func (g *Game) GetHomeTeam() TeamInterface
GetHomeTeam returns the first team in the Teams slice
func (*Game) GetParentIDs ¶
GetParentIDs gets the ids of any games that caused this game to be generated, typically this is used in Elimination games
func (*Game) GetScores ¶
func (g *Game) GetScores() []ScoreInterface
GetScores returns a slice of Score
func (*Game) SetAwayTeam ¶
func (g *Game) SetAwayTeam(t TeamInterface)
SetAwayTeam sets the second team of the game and adds a placeholder home team if it's not already there
func (*Game) SetHomeTeam ¶
func (g *Game) SetHomeTeam(t TeamInterface)
SetHomeTeam sets the first team of the game
type GameInterface ¶
type GameInterface interface { GetID() int GetParentIDs() []int GetHomeTeam() TeamInterface GetAwayTeam() TeamInterface SetHomeTeam(t TeamInterface) SetAwayTeam(t TeamInterface) GetHomeScore() ScoreInterface GetAwayScore() ScoreInterface GetTeams() []TeamInterface // For games that can have any number of teams GetScores() []ScoreInterface // For games that can have any number of scores SetScore(homeScore float64, awayScore float64) Print() string }
GameInterface defines the needed methods for games used in the library. A Game is a flexible entity and conforms to what you might typically find in Soccer where you have a home and away team and a score for each team but the interface also tries to allow for other types of games where the number of teams and scores is not limited to 2
type Group ¶
type Group struct { ID int Teams []TeamInterface Games []GameInterface }
Group is for group tournaments only
func (*Group) AppendGame ¶
func (t *Group) AppendGame(game GameInterface)
AppendGame takes a single game and appends it to the Games slice
func (*Group) AppendGames ¶
func (t *Group) AppendGames(games []GameInterface)
AppendGames adds a slice of games to the Games slice
func (*Group) AppendTeam ¶
func (t *Group) AppendTeam(team TeamInterface)
AppendTeam takes a single team and appends it to the Teams slice
func (*Group) AppendTeams ¶
func (t *Group) AppendTeams(teams []TeamInterface)
AppendTeams adds a slice of teams to the Teams slice
func (*Group) GetGames ¶
func (t *Group) GetGames() *[]GameInterface
GetGames returns the slice of games belonging to the group
func (*Group) GetTeams ¶
func (t *Group) GetTeams() *[]TeamInterface
GetTeams returns a slice of teams belonging to the group
func (*Group) RemoveGame ¶
func (t *Group) RemoveGame(game GameInterface)
RemoveGame takes a single game and removes it to the Games slice
type GroupInterface ¶
type GroupInterface interface { GetID() int GetTeams() *[]TeamInterface GetGames() *[]GameInterface AppendGames(games []GameInterface) AppendGame(game GameInterface) RemoveGame(game GameInterface) AppendTeams(teams []TeamInterface) AppendTeam(team TeamInterface) Print() string }
GroupInterface defines the interface of tournament groups used for group tournaments
type Score ¶
type Score struct { ID int Points float64 // We want to support any type of game where points can be very high or even just decimals }
Score is a default struct used as an example of how structs can be implemented for tournify
type ScoreInterface ¶
ScoreInterface defines how scores should be defined. Scores hold points defined as a float. Using a float64 should allow this library to be used for any type of game.
type Team ¶
Team is a default struct used as an example of how structs can be implemented for tournify
func (*Team) GetEliminatedCount ¶
GetEliminatedCount gets the number of times the team has been eliminated in a knockout tournament
func (*Team) SetEliminatedCount ¶
SetEliminatedCount sets the number of times the team has been eliminated in a knockout tournament
type TeamInterface ¶
type TeamInterface interface { GetID() int GetEliminatedCount() int SetEliminatedCount(i int) Print() string }
TeamInterface defines the methods for teams. Teams are used to create tournaments and generate games. Teams can have games
func GetLoserTeam ¶
func GetLoserTeam(g GameInterface) TeamInterface
func GetWinnerTeam ¶
func GetWinnerTeam(g GameInterface) TeamInterface
type TeamStats ¶
type TeamStats struct { Tournament TournamentInterface Group GroupInterface Team TeamInterface Played int Wins int Losses int Ties int PointsFor float64 PointsAgainst float64 Points int }
TeamStats is a default struct used as an example of how structs can be implemented for tournify
func (*TeamStats) GetGroup ¶
func (t *TeamStats) GetGroup() GroupInterface
GetGroup returns the Group that the statistics were generated for, stats are directly related to a team and the group they are in.
func (*TeamStats) GetPoints ¶
GetPoints returns the number of points the team has based on wins, losses or ties
func (*TeamStats) GetPointsAgainst ¶
GetPointsAgainst returns the number of goals or points that other teams have made against this team
func (*TeamStats) GetPointsFor ¶
GetPointsFor returns the number of goals or points that this team has made
func (*TeamStats) GetTeam ¶
func (t *TeamStats) GetTeam() TeamInterface
GetTeam returns the Team that the statistics were generated for, stats are directly related to a team and the group they are in.
type TeamStatsInterface ¶
type TeamStatsInterface interface { GetGroup() GroupInterface GetTeam() TeamInterface GetPlayed() int GetWins() int GetLosses() int GetTies() int GetPointsFor() float64 GetPointsAgainst() float64 GetDiff() float64 GetPoints() int AddPoints(points int) Print() string }
TeamStatsInterface is used to show team statistics. Currently this is specifically made for group tournaments where there is a need to rank teams.
func GetGroupStats ¶
func GetGroupStats(group GroupInterface, winPoints int, lossPoints int, tiePoints int) []TeamStatsInterface
GetGroupStats returns the current stats for all the teams in a single group
func GetGroupTournamentStats ¶
func GetGroupTournamentStats(t TournamentInterface, winPoints int, lossPoints int, tiePoints int) ([]TeamStatsInterface, error)
GetGroupTournamentStats takes 4 inputs. The first input is the tournament itself. The other three input defines how many points a team should get for a win, loss or tie. The standard is 3, 0, 1 but it can vary depending on the tournament.
func SortTournamentStats ¶
func SortTournamentStats(stats []TeamStatsInterface) []TeamStatsInterface
SortTournamentStats sorts the statistics by points, diff and finally scored goals against other teams
type Tournament ¶
type Tournament struct { Type TournamentType // Is it elimination or group or ladder or poker? What is a type? Teams []TeamInterface Groups []GroupInterface Games []GameInterface }
Tournament is a default struct used as an example of how structs can be implemented for tournify
func (*Tournament) AppendGame ¶
func (t *Tournament) AppendGame(game GameInterface)
AppendGame appends a game to the tournament game slice
func (*Tournament) GetEliminatedTeams ¶
func (t *Tournament) GetEliminatedTeams() []TeamInterface
GetEliminatedTeams gets all teams that have been eliminated at least one time in an elimination tournament
func (*Tournament) GetGameByID ¶
func (t *Tournament) GetGameByID(id int) GameInterface
GetGameByID takes an int and returns a game with that id if it exists in the tournament
func (*Tournament) GetGameDepth ¶
func (t *Tournament) GetGameDepth(game GameInterface) int
GetGameDepth gets the depth of the game in a tournament such as an elimination tournament. It is the same as counting how many games each team had to win in order to get to this game (a team which is by itself in a game automatically wins).
func (*Tournament) GetGameFirstAncestorID ¶
func (t *Tournament) GetGameFirstAncestorID(game GameInterface) int
GetGameFirstAncestorID gets the lowest game id with a depth of 0 which this game is a descendant of
func (*Tournament) GetGameLastDescendantID ¶
func (t *Tournament) GetGameLastDescendantID(game GameInterface) int
GetGameLastDescendantID gets the id of the last game that has been generated off of the provided game
func (*Tournament) GetGames ¶
func (t *Tournament) GetGames() []GameInterface
GetGames returns the game slice
func (*Tournament) GetGamesAtDepth ¶
func (t *Tournament) GetGamesAtDepth(depth int) (games []GameInterface)
GetGamesAtDepth takes an int for depth and returns any games at the depth as a slice
func (*Tournament) GetGroups ¶
func (t *Tournament) GetGroups() []GroupInterface
GetGroups returns the group slice
func (*Tournament) GetRemainingTeams ¶
func (t *Tournament) GetRemainingTeams() []TeamInterface
GetRemainingTeams gets all teams that have not been eliminated in an elimination tournament
func (*Tournament) GetTeams ¶
func (t *Tournament) GetTeams() []TeamInterface
GetTeams returns the team slice
func (*Tournament) GetType ¶
func (t *Tournament) GetType() int
GetType returns the type of tournament as an int
func (*Tournament) GetTypeString ¶
func (t *Tournament) GetTypeString() string
GetTypeString returns the type of tournament as a string
func (*Tournament) IsDepthFull ¶
func (t *Tournament) IsDepthFull(depth int) bool
IsDepthFull checks if the expected numbers of games have been filled for a depth in an elimination tournament
func (*Tournament) MakeTeamEliminated ¶
func (t *Tournament) MakeTeamEliminated(team TeamInterface)
func (*Tournament) MakeTeamRemain ¶
func (t *Tournament) MakeTeamRemain(team TeamInterface)
func (*Tournament) Print ¶
func (t *Tournament) Print() string
Print writes the full tournament details to a string
func (*Tournament) SetGame ¶
func (t *Tournament) SetGame(game GameInterface) error
SetGame overwrites any game with the same id
func (*Tournament) SetGameScore ¶
func (t *Tournament) SetGameScore(game GameInterface, homeScore float64, awayScore float64) error
func (*Tournament) SetGames ¶
func (t *Tournament) SetGames(games []GameInterface)
SetGames sets the tournaments games slice
type TournamentInterface ¶
type TournamentInterface interface { GetType() int GetTypeString() string GetTeams() []TeamInterface GetEliminatedTeams() []TeamInterface // For elimination style tournaments GetRemainingTeams() []TeamInterface // For elimination style tournaments GetGroups() []GroupInterface GetGames() []GameInterface AppendGame(game GameInterface) SetGame(game GameInterface) error SetGameScore(game GameInterface, homeScore float64, awayScore float64) error Print() string }
TournamentInterface defines the methods needed to handle tournaments.
func CreateEliminationTournamentFromTeams ¶
func CreateEliminationTournamentFromTeams(teams []TeamInterface) TournamentInterface
CreateEliminationTournamentFromTeams takes a slice of teams and generates a elimination tournament The ID used for games are very important for elimination tournaments as it is used to determine the home or away team in later games
func CreateGroupTournamentFromGroups ¶
func CreateGroupTournamentFromGroups(groups []GroupInterface, meetCount int) TournamentInterface
CreateGroupTournamentFromGroups takes a slice of groups that contain teams and returns a group tournament TODO simplify and break down this function in to smaller chunks? TODO this method currently uses cross matching for games but other types of matching could be supported
func CreateGroupTournamentFromTeams ¶
func CreateGroupTournamentFromTeams(teams []TeamInterface, groupCount int, meetCount int) TournamentInterface
CreateGroupTournamentFromTeams takes a slice of teams and generates a group tournament
func CreateTournament ¶
func CreateTournament(teamCount int, meetCount int, groupCount int, tournamentType int) TournamentInterface
CreateTournament creates a tournament with the simplest input. It is recommended to create a slice with specific use via CreateTournamentFromTeams as this method will generate it's own Teams as a sort of placeholder.
func CreateTournamentFromTeams ¶
func CreateTournamentFromTeams(teams []TeamInterface, meetCount int, groupCount int, tournamentType int) TournamentInterface
CreateTournamentFromTeams takes a slice of teams and generates a tournament of the specified type
type TournamentType ¶
type TournamentType int
TournamentType defines the type of tournament TODO is this a good way of defining tournament types?
How can this be extended by others who want to build on this code without modifying the library?
const ( // TournamentTypeGroup is for group tournaments TournamentTypeGroup TournamentType = 0 // TournamentTypeSeries is similar to group tournaments but only has one group, usually this would be used when playing in a soccer league for example TournamentTypeSeries TournamentType = 1 // TournamentTypeElimination is for elimination or knockout tournaments TournamentTypeElimination TournamentType = 2 // TournamentTypeDoubleElimination is the same as TournamentTypeElimination // but teams to get knocked out early get a second chance to come back and win TournamentTypeDoubleElimination TournamentType = 3 )
func (TournamentType) String ¶
func (tournamentType TournamentType) String() string