sim

package
v0.0.0-...-bc49051 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BalancedMatchmaker

type BalancedMatchmaker struct {
	// contains filtered or unexported fields
}

BalancedMatchmaker will try to create "balanced" teams from the players currently in the queue according to average ratings.

func (*BalancedMatchmaker) FormGames

func (bm *BalancedMatchmaker) FormGames(cfg MatchmakerConfig) (out []MatchmakerGame)

func (*BalancedMatchmaker) Init

func (bm *BalancedMatchmaker) Init(r *rand.Rand)

func (*BalancedMatchmaker) Queue

func (bm *BalancedMatchmaker) Queue(players ...*Player)

func (*BalancedMatchmaker) QueueLen

func (bm *BalancedMatchmaker) QueueLen() int

type Clock

type Clock interface {
	Now() time.Time
	Wait(time.Duration)
}

Clock is a source of time

func NewSimulatedClock

func NewSimulatedClock(startAt time.Time) Clock

type ClusteredMatchmaker

type ClusteredMatchmaker struct {
	// contains filtered or unexported fields
}

BalancedMatchmaker will try to create "balanced" teams from the players currently in the queue according to average ratings.

func (*ClusteredMatchmaker) FormGames

func (cm *ClusteredMatchmaker) FormGames(cfg MatchmakerConfig) (out []MatchmakerGame)

func (*ClusteredMatchmaker) Init

func (cm *ClusteredMatchmaker) Init(r *rand.Rand)

func (*ClusteredMatchmaker) Queue

func (cm *ClusteredMatchmaker) Queue(players ...*Player)

func (*ClusteredMatchmaker) QueueLen

func (cm *ClusteredMatchmaker) QueueLen() int

type Game

type Game struct {
	ID          uuid.UUID
	TeamA       PlayerLookup
	RatingTeamA int
	TeamB       PlayerLookup
	RatingTeamB int
	StartedAt   time.Time
	FinishedAt  time.Time
	Outcome     Team
}

func (Game) Done

func (g Game) Done(currentTimestamp time.Time) bool

func (Game) PlayerTeam

func (g Game) PlayerTeam(id uuid.UUID) Team

type KeyProvider

type KeyProvider[K comparable] interface {
	Key() K
}

type Lookup

type Lookup[K comparable, V KeyProvider[K]] map[K]V

Lookup is a helper for maps that constrains the elements to types that can report their own keys.

func NewLookup

func NewLookup[K comparable, V KeyProvider[K]](values []V) Lookup[K, V]

NewLookup returns a new lookup from a given array of elements..

func (Lookup[K, V]) Add

func (l Lookup[K, V]) Add(v V)

func (Lookup[K, V]) Copy

func (l Lookup[K, V]) Copy() Lookup[K, V]

Copy returns a copy of the lookup.

func (Lookup[K, V]) Del

func (l Lookup[K, V]) Del(v V)

func (Lookup[K, V]) Has

func (l Lookup[K, V]) Has(v V) (ok bool)

func (Lookup[K, V]) HasKey

func (l Lookup[K, V]) HasKey(k K) (ok bool)

func (Lookup[K, V]) Keys

func (l Lookup[K, V]) Keys() (out []K)

func (Lookup[K, V]) PopRandom

func (l Lookup[K, V]) PopRandom(_ *rand.Rand) (v V, ok bool)

PopRandom removes a random element from the lookup and returns it.

type Matchmaker

type Matchmaker interface {
	Init(r *rand.Rand)
	Queue(...*Player)
	QueueLen() int
	FormGames(MatchmakerConfig) []MatchmakerGame
}

type MatchmakerConfig

type MatchmakerConfig struct {
	MaxGames int
	TeamSize int
}

type MatchmakerGame

type MatchmakerGame struct {
	TeamA []*Player
	TeamB []*Player
}

type Player

type Player struct {
	ID         uuid.UUID
	IdleAt     time.Time
	QueuedAt   time.Time
	TimedOutAt time.Time

	Rating       int
	NaturalSkill int

	Games int
	Wins  int

	QueuedElapsed []time.Duration
	Recent        *c9s.Queue[*Game]
}

func (Player) IsIdle

func (p Player) IsIdle(ts time.Time) bool

func (Player) IsTimedOut

func (p Player) IsTimedOut(ts time.Time) bool

func (Player) Key

func (p Player) Key() uuid.UUID

func (Player) QueuedElapsedStats

func (p Player) QueuedElapsedStats() (min, mean, max, p50, p75, p95 time.Duration)

func (Player) Winrate

func (p Player) Winrate() float64

func (Player) WinrateRecent

func (p Player) WinrateRecent() float64

type PlayerLookup

type PlayerLookup = Lookup[uuid.UUID, *Player]

Player is an alias to lookup for player.

type Server

type Server struct {
	ID   uuid.UUID
	Game *Game
}

func (Server) Key

func (s Server) Key() uuid.UUID

type ServerLookup

type ServerLookup = Lookup[uuid.UUID, *Server]

ServerLookup is an alias to lookup for server.

type SimpleMatchmaker

type SimpleMatchmaker struct {
	// contains filtered or unexported fields
}

SimpleMatchmaker randomly assigns players once there are enough players to fill both teams.

This can be used as a "control" for how effective more sophisticated mm algorithms might work.

func (*SimpleMatchmaker) FormGames

func (sm *SimpleMatchmaker) FormGames(cfg MatchmakerConfig) (out []MatchmakerGame)

func (*SimpleMatchmaker) Init

func (sm *SimpleMatchmaker) Init(_ *rand.Rand)

func (*SimpleMatchmaker) Queue

func (sm *SimpleMatchmaker) Queue(players ...*Player)

func (*SimpleMatchmaker) QueueLen

func (sm *SimpleMatchmaker) QueueLen() int

type Simulation

type Simulation struct {
	// Config holds configuration options that will
	// be satisfied by defaults if they're not set.
	Config SimulationConfig

	// Clock is the source of time for the simulation.
	//
	// If it's not set, it will be assigned a default.
	Clock      Clock
	Matchmaker Matchmaker
	RandSource rand.Source
	// contains filtered or unexported fields
}

func (*Simulation) Init

func (s *Simulation) Init()

Init sets up internal data stores and resolves dependencies.

You must call `Init` before you call `Simulate`.

func (*Simulation) Simulate

func (s *Simulation) Simulate() SimulationResults

Simulate runs the simulation and returns results.

type SimulationConfig

type SimulationConfig struct {
	SimulationLength time.Duration
	TickInterval     time.Duration
	ServerCount      int
	GameTeamSize     int
	GameDuration     time.Duration

	PlayerCount               int
	PlayerActiveDuration      time.Duration
	PlayerNaturalRatingMedian float64
	PlayerNaturalRatingStdDev float64
	PlayerRatingHistoryLen    int
	PlayerMinimumRating       int
}

SimulationConfig are parameters to the simulation.

func (SimulationConfig) GameDurationOrDefault

func (sc SimulationConfig) GameDurationOrDefault() time.Duration

func (SimulationConfig) GameTeamSizeOrDefault

func (sc SimulationConfig) GameTeamSizeOrDefault() int

func (SimulationConfig) PlayerActiveDurationOrDefault

func (sc SimulationConfig) PlayerActiveDurationOrDefault() time.Duration

func (SimulationConfig) PlayerMinimumRatingOrDefault

func (sc SimulationConfig) PlayerMinimumRatingOrDefault() int

func (SimulationConfig) PlayerNaturalRatingMedianOrDefault

func (sc SimulationConfig) PlayerNaturalRatingMedianOrDefault() float64

func (SimulationConfig) PlayerNaturalRatingStdDevOrDefault

func (sc SimulationConfig) PlayerNaturalRatingStdDevOrDefault() float64

func (SimulationConfig) PlayerRatingHistoryLenOrDefault

func (sc SimulationConfig) PlayerRatingHistoryLenOrDefault() int

func (SimulationConfig) ServerCountOrDefault

func (sc SimulationConfig) ServerCountOrDefault() int

func (SimulationConfig) SimulationLengthOrDefault

func (sc SimulationConfig) SimulationLengthOrDefault() time.Duration

func (SimulationConfig) TickIntervalOrDefault

func (sc SimulationConfig) TickIntervalOrDefault() time.Duration

type SimulationResultState

type SimulationResultState struct {
	// contains filtered or unexported fields
}

SimulationResultState holds mutable simulation result state that will be used for computing final results at the end of the simulation.

type SimulationResults

type SimulationResults struct {
	GamesPlayed   int
	GamesLobsided int
	GamesTied     int

	QueueTimeMean time.Duration
	QueueTimeP95  time.Duration
	WinrateP20    float64
	WinrateMean   float64
	WinrateP80    float64

	PlayerNaturalSkillToRatingCorrelation float64

	Players []*Player

	PlayerTop10    []*Player
	PlayerBottom10 []*Player

	PlayerCountsByRank []Tag
}

type Tag

type Tag struct {
	K string
	V any
}

type Team

type Team int
const (
	TeamUnknown Team = -1
	TeamA       Team = 0
	TeamB       Team = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL