Created
January 16, 2014 00:23
-
-
Save xperimental/8447511 to your computer and use it in GitHub Desktop.
ELO scoring in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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