Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyExists = errors.New("player already exists") ErrPoolClosed = errors.New("pool is closed") )
Functions ¶
This section is empty.
Types ¶
type CalcOpt ¶ added in v1.0.0
type CalcOpt func(*Calculator)
func WithKFactor ¶ added in v1.0.0
WithKFactor adds one more range that uses a different K-factor.
type Calculator ¶ added in v1.0.0
type Calculator struct {
// contains filtered or unexported fields
}
Calculator holds options for calculations. Use
elgo.NewCalc(...)
to create a new calculator.
func NewCalc ¶ added in v1.0.0
func NewCalc(k float64, opts ...CalcOpt) *Calculator
NewCalc creates a new calculator for rating changes. k is used as a default option and you can pass multiple k factors that will be applied depending on players' rating. Thus:
NewCalc(5, WithKFactor(1000, 20), WithKFactor(1500, 30))
will be used as:
rating > 0 && rating < 1000, k = 5 rating >= 1000 && rating < 1500, k = 20 rating >= 1500, k = 30
There's no option to add max value for rating ranges, it's either infinite or next factor's min value.
type Identifier ¶
type Identifier interface { // Identify should returns any kind of a unique identifier between players. Identify() string }
Identifier is an interface that helps identify players.
type Player ¶
type Player interface { Identifier Ratinger }
Player is an interface that implements Identifier and Ratinger.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a main struct for matchmaking pool. Use NewPool(options...) to create a new pool.
func NewPool ¶
NewPool creates a new pool for players. Pools aren't connected to each other so creating multiple of them is safe. To close a pool use pool.Close().
func (*Pool) AddPlayer ¶
AddPlayer returns a queue channel to send new players to. ErrAlreadyExists is returned if identifier is already taken. ErrPoolClosed is returned if the pool is closed.
func (*Pool) Close ¶
Close closes the pool and return players that are still in the queue. It's safe to call Close() multiple times, but in that case nil will be returned.
type PoolOpt ¶
type PoolOpt func(*Pool)
func WithGlobalRetryInterval ¶
WithGlobalRetryInterval sets a duration of how much time a pool should wait between iterations if not a single match was found.
func WithIncreasePlayerBorderBy ¶
WithIncreasePlayerBorderBy sets an amount of points that will be added on a new search, if no opponent was found previously.
func WithPlayerRetryInterval ¶
WithPlayerRetryInterval sets a duration of how much time a player should wait before a pool would try and find a match for them again.