multielo

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 11 Imported by: 0

README

Multiplayer Elo Rating System

This is a simple implementation of the Elo rating system for multiplayer games. The system is based on the Elo rating system which is a method for calculating the relative skill levels of players in two-player games such as chess. The system is used in many games and sports to rank players based on their performance.

Go Report Card

Installation

go get github.com/distrobyte/multielo

Usage

package main

import (
    "fmt"
    elo "github.com/distrobyte/multielo"
)

func main() {
    // Create a new league
    league := elo.NewLeague()

    // Add players to the league
    league.AddPlayer("player1")
    league.AddPlayer("player2")

    // Get the ELO of a player
    player := league.GetPlayer("player1")
    fmt.Println(player.ELO)
}

Documentation

Index

Constants

View Source
const (
	InitialELO = 1000
)

Variables

View Source
var (
	ErrPlayerAlreadyExists = errors.New("player already exists")
	ErrPlayerNotFound      = errors.New("player not found")
	ErrMatchNotFound       = errors.New("match not found")
	ErrInvalidMatch        = errors.New("invalid match")
	ErrInvalidELOChange    = errors.New("invalid elo change")
	ErrInvalidPlayer       = errors.New("invalid player")
	ErrInvalidPlayerStats  = errors.New("invalid player stats")
	ErrInvalidLeague       = errors.New("invalid league")
	ErrNoPlayers           = errors.New("no players")
)

Functions

This section is empty.

Types

type ELOTicker

type ELOTicker struct{}

func (ELOTicker) Ticks

func (t ELOTicker) Ticks(min, max float64) []plot.Tick

type League

type League struct {
	Players []*Player
	Matches []Match
}

func NewLeague

func NewLeague() *League

func (*League) AddMatch

func (l *League) AddMatch(results []*MatchResult) ([]MatchDiff, error)

func (*League) AddPlayer

func (l *League) AddPlayer(name string) error

func (*League) GenerateGraph

func (l *League) GenerateGraph() (string, error)

func (*League) GetMatches

func (l *League) GetMatches() []Match

func (*League) GetPlayer

func (l *League) GetPlayer(name string) (*Player, error)

func (*League) GetPlayerELO

func (l *League) GetPlayerELO(name string) (int, error)

func (*League) GetPlayerStats

func (l *League) GetPlayerStats(name string) (*PlayerStats, error)

func (*League) GetPlayers

func (l *League) GetPlayers() []*Player

func (*League) RemovePlayer

func (l *League) RemovePlayer(name string) error

func (*League) ResetMatches added in v0.0.3

func (l *League) ResetMatches()

func (*League) ResetPlayers

func (l *League) ResetPlayers()

type Match

type Match struct {
	Results []*MatchResult
	Date    time.Time
}

type MatchDiff

type MatchDiff struct {
	Player *Player
	Diff   int
}

type MatchResult

type MatchResult struct {
	Position int
	Player   *Player
}

type Player

type Player struct {
	Name      string
	ELO       int
	ELOChange int
	Stats     *PlayerStats
}

type PlayerStats

type PlayerStats struct {
	MatchesPlayed       int
	MatchesWon          int
	AllTimeAveragePlace float64
	Last5Finish         []int
	PeakELO             int
}

type RaceTicker

type RaceTicker struct{}

func (RaceTicker) Ticks

func (t RaceTicker) Ticks(min, max float64) []plot.Tick

Jump to

Keyboard shortcuts

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