Documentation
¶
Index ¶
- Constants
- func AsRoundrobin(ratings map[Element]rating.Rating, scores map[Element]float64) error
- type ApplyStrategy
- type Clock
- type Config
- type Element
- type Match
- func (m *Match) Add(element Element, score float64) error
- func (m *Match) Apply(scoresAt time.Time, config *Config) error
- func (m *Match) Ratings() map[Element]rating.Rating
- func (m *Match) Reset()
- func (m *Match) Scores() map[Element]float64
- func (m *Match) String() string
- func (m *Match) WinProbs() map[Element]float64
- type Player
- type Players
- type Service
- func (s *Service) Apply(match *Match) error
- func (s *Service) ApplyWithTime(match *Match, outcomeAt time.Time) error
- func (s *Service) NewDefaultPlayer(name string) *Player
- func (s *Service) NewMatch(elements ...Element) (*Match, error)
- func (s *Service) NewPlayer(name string, fixed rating.Rating, fixedAt time.Time) *Player
- func (s *Service) NewTeam(name string, members Players) *Team
- type Team
Examples ¶
Constants ¶
const ( PeriodDay time.Duration = 24 * time.Hour PeriodWeek = 7 * PeriodDay PeriodMonth = 30 * PeriodDay PeriodYear = 365 * PeriodDay )
RatingPeriod constants can multiple float64
PeriodDay * 3.0 => 3 days
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ApplyStrategy ¶
ApplyStrategy is an alias for a function. This function shows how to reflect in a multiplayer game when reflecting the result of Match in Rating.
type Config ¶
type Config struct { //Service Clock Clock Tau float64 //RatingPeriod is the fixed interval of Rating. //All matches played between this interval are considered to occur simultaneously and are calculated. //In RatingPeriod, the period in which the players play about 15 times is good. RatingPeriod time.Duration //It will return to the initial deviation if you have not played for about this period. //This period is a guideline, and the time to return to the actual initial deviation is determined by the player's Volatility here. //And initial Volatility is calculated based on this period. PeriodToResetDeviation time.Duration //Fighting prosperity strategy uses round robin by default DefaultApplyStrategy ApplyStrategy }
Config is service configuration
func (*Config) InitialVolatility ¶
InitialVolatility calculates the initial rating fluctuation according to the setting
func (*Config) WithApplyStrategy ¶
func (c *Config) WithApplyStrategy(strategy ApplyStrategy) *Config
WithApplyStrategy is set DefaultApplyStrategy to config
func (*Config) WithRatingPeriod ¶
WithRatingPeriod is set RatingPeriod to config
type Element ¶
type Element interface { Name() string Rating() rating.Rating ApplyMatch(rating.Rating, float64) error Prepare(time.Time, *Config) error }
Element is an interface of Team/Player
type Match ¶
type Match struct {
// contains filtered or unexported fields
}
Match is a model that represents multiple Team / Player battles
func (*Match) Apply ¶
Apply function determines the current score and reflects it on Team / Player's Rating.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player is rating resouse
func (*Player) ApplyMatch ¶
ApplyMatch reflects match results between players.
type Service ¶
type Service struct {
*Config
}
Service is usecase
Example ¶
package main import ( "fmt" "github.com/mashiike/rating" "github.com/mashiike/rating/ratingutil" ) func main() { //for example, Tag battle svc := ratingutil.New(ratingutil.NewConfig()) team1 := svc.NewTeam( "bovidae", ratingutil.Players{ svc.NewPlayer( "sheep", rating.New(1700.0, 50.0, svc.Config.InitialVolatility()), svc.Config.Now(), ), svc.NewDefaultPlayer("goat"), }, ) team2 := svc.NewTeam( "equidae", ratingutil.Players{ svc.NewPlayer( "donkey", rating.New(1400.0, 50.0, svc.Config.InitialVolatility()), svc.Config.Now(), ), svc.NewDefaultPlayer("zebra"), }, ) match, _ := svc.NewMatch(team1, team2) fmt.Println(match) match.Add(team1, 1.0) match.Add(team2, 0.0) err := svc.Apply(match) if err != nil { fmt.Println(err.Error()) } fmt.Println("=== after match ===") fmt.Println(match) }
Output: [ bovidae:{ sheep:1700.0p-138.6 goat:1500.0p-700.0 }(0.66) equidae:{ donkey:1400.0p-138.6 zebra:1500.0p-700.0 }(0.34) ] === after match === [ bovidae:{ sheep:1705.2p-137.2 goat:1654.5p-530.9 }(0.81) equidae:{ donkey:1393.7p-137.0 zebra:1364.1p-536.3 }(0.19) ]
func (*Service) ApplyWithTime ¶
ApplyWithTime is a function for apply Match for Team/Player outcome.
func (*Service) NewDefaultPlayer ¶
NewDefaultPlayer is factory of default player
type Team ¶
type Team struct {
// contains filtered or unexported fields
}
Team is multiple player http://rhetoricstudios.com/downloads/AbstractingGlicko2ForTeamGames.pdf
func (*Team) ApplyMatch ¶
ApplyMatch reflects match results between teams.