avalon

package
v0.0.0-...-b7ca9ae Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoyalServant    Role = "servant"
	Merlin               = "merlin"
	Percival             = "percival"
	Morgana              = "morgana"
	Assassin             = "assassin"
	MinionOfMordred      = "minion"
	Mordred              = "mordred"
	Oberon               = "oberon"
)

Variables

View Source
var TimeNow = time.Now

Export for faking

Functions

This section is empty.

Types

type GameId

type GameId string

id types

type GameImpl

type GameImpl struct {
	Id             GameId
	Winner         Team
	RoleByPlayerId map[PlayerId]Role
	CreatedAt      time.Time

	// Keep a static snapshot of players so the game calculation is repeatable
	PlayersById map[PlayerId]*PlayerImpl
	// contains filtered or unexported fields
}

func NewGame

func NewGame(
	playersById map[PlayerId]*PlayerImpl,
	roleByPlayerId map[PlayerId]Role,
) *GameImpl

Creates a new game

func (*GameImpl) GetNewRatingForPlayer

func (g *GameImpl) GetNewRatingForPlayer(
	playerId PlayerId,
) (rating float64, err error)

Given a game, return what the update should be for that player

func (*GameImpl) GetTeam

func (g *GameImpl) GetTeam(
	team Team,
) (players []*PlayerImpl, err error)

Returns a list of players on a team

func (*GameImpl) GetTeamRating

func (g *GameImpl) GetTeamRating(
	team Team,
) (rating float64, err error)

Returns the arthmetic average team rating for a team in the game

func (*GameImpl) GetWinPercentage

func (g *GameImpl) GetWinPercentage(
	team Team,
) (winRate float64, err error)

Returns the expectation of the team winning, which is:

1/(1 + 10 ** ((r_other - r_team)/400))

cached via teamWinPercentages in game

func (*GameImpl) SetWinner

func (g *GameImpl) SetWinner(team Team)

func (*GameImpl) UpdatePlayersAfterGame

func (g *GameImpl) UpdatePlayersAfterGame() (updatedPlayers []*PlayerImpl, err error)

Returns a list of updated players for when the game is finished

The list of players is deep copied to preserve the game's state

type PlayerId

type PlayerId string

id types

func NewPlayerId

func NewPlayerId() PlayerId

type PlayerImpl

type PlayerImpl struct {
	Id       PlayerId
	Name     string
	Rating   float64
	NumGames int
}

func NewPlayer

func NewPlayer(name string) *PlayerImpl

func (*PlayerImpl) GetUpdateConstant

func (p *PlayerImpl) GetUpdateConstant() float64

type Role

type Role string

type Team

type Team string
const (
	NoTeam Team = "no_team"
	Blue   Team = "blue_team"
	Red    Team = "red_team"
)

func (Team) OtherTeam

func (t Team) OtherTeam() Team

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

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