Skip to content

Instantly share code, notes, and snippets.

@xperimental
Created January 16, 2014 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperimental/8447511 to your computer and use it in GitHub Desktop.
Save xperimental/8447511 to your computer and use it in GitHub Desktop.
ELO scoring in Go
package main
import (
"fmt"
"math"
)
const (
ScoreFactor = 10
)
func main() {
result := 1
scoreA := 2806
scoreB := 2577
fmt.Printf("result: %d\nscoreA: %d\nscoreB: %d\n", result, scoreA, scoreB)
scoreDiff := (float64)(scoreB - scoreA)
expectedA := 1 / (1 + math.Pow(10, scoreDiff / 400))
expectedB := 1 - expectedA
fmt.Printf("scoreDiff: %f\nexpectedA: %f\nexpectedB: %f\n", scoreDiff, expectedA, expectedB)
var resultA, resultB float64
switch {
case result > 0:
resultA = 1
resultB = 0
case result < 0:
resultA = 0
resultB = 1
case result == 0:
resultA = 0.5
resultB = 0.5
}
fmt.Printf("resultA: %f\nresultB: %f\n", resultA, resultB)
diffA := ScoreFactor * (resultA - expectedA)
diffB := ScoreFactor * (resultB - expectedB)
fmt.Printf("diffA: %f\ndiffB: %f\n", diffA, diffB)
scoreA = (int)((float64)(scoreA) + diffA)
scoreB = (int)((float64)(scoreB) + diffB)
fmt.Printf("scoreA: %d\nscoreB: %d\n", scoreA, scoreB)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment