Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math/rand"
- )
- // Seed each player 0 through 15
- // Play round 1 and advance winners to round 2
- // Repeat until you have a winner in round 4
- // Count the number of times each player ended in each top 2 spots.
- // How to seed?
- // First tournament is seeded in no particular order.
- // Next tournament is seeded based on results of last tournament, ties broken by coin flip.
- // Finals are best of 5, the rest best of 3
- func main() {
- ratings := getRatings()
- names := getNames()
- initSeed := make([]string, 0)
- for player := range ratings {
- initSeed = append(initSeed, player)
- }
- wins := make(map[string][]int64) // 1st and 2nd place finishes
- for player := range ratings {
- wins[player] = []int64{0, 0}
- }
- seeds := getTournamentResults(ratings, initSeed)
- // Simulation
- for i := 1; true; i++ {
- results := getTournamentResults(ratings, seeds)
- wins[results[0]][0]++
- wins[results[1]][1]++
- if i%100000 == 0 {
- fmt.Println("Iteration ", i)
- for _, name := range names {
- fmt.Printf("%.6f %.6f %v\n", float64(wins[name][0])/float64(i), float64(wins[name][1])/float64(i), name)
- }
- }
- seeds = results
- }
- }
- func getTournamentResults(ratings map[string]float64, seeds []string) []string {
- results := make([]string, len(ratings))
- rankIndex := len(results) - 1
- // Round 1
- round2Contestants := make([]string, 0)
- playAndPlace(0, 15, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(1, 14, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(2, 13, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(3, 12, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(4, 11, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(5, 10, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(6, 9, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- playAndPlace(7, 8, 3, ratings, seeds, &rankIndex, &round2Contestants, &results)
- // Round 2
- round3Contestants := make([]string, 0)
- playAndPlace(0, 1, 5, ratings, round2Contestants, &rankIndex, &round3Contestants, &results)
- playAndPlace(2, 3, 5, ratings, round2Contestants, &rankIndex, &round3Contestants, &results)
- playAndPlace(4, 5, 5, ratings, round2Contestants, &rankIndex, &round3Contestants, &results)
- playAndPlace(6, 7, 5, ratings, round2Contestants, &rankIndex, &round3Contestants, &results)
- // Round 3
- round4Contestants := make([]string, 0)
- playAndPlace(0, 1, 5, ratings, round3Contestants, &rankIndex, &round4Contestants, &results)
- playAndPlace(2, 3, 5, ratings, round3Contestants, &rankIndex, &round4Contestants, &results)
- // Round 4
- winner := make([]string, 0)
- playAndPlace(0, 1, 5, ratings, round4Contestants, &rankIndex, &winner, &results)
- results[0] = winner[0]
- return results
- }
- func playAndPlace(seedA, seedB, numGames int, ratings map[string]float64, seeds []string, rankIndex *int, nextRoundContestants *[]string, results *[]string) {
- if wonMatch(numGames, ratings[seeds[seedA]], ratings[seeds[seedB]]) {
- // fmt.Printf("%v beat %v\n", seeds[seedA], seeds[seedB])
- *nextRoundContestants = append(*nextRoundContestants, seeds[seedA])
- (*results)[*rankIndex] = seeds[seedB]
- } else {
- *nextRoundContestants = append(*nextRoundContestants, seeds[seedB])
- (*results)[*rankIndex] = seeds[seedA]
- // fmt.Printf("%v beat %v\n", seeds[seedB], seeds[seedA])
- }
- *rankIndex--
- }
- // Returns true if player a beats player b in a match of n games
- func wonMatch(n int, a, b float64) bool {
- var wins int
- for i := 0; i < n; i++ {
- if getWin(a, b) {
- wins++
- }
- }
- return wins > n/2
- }
- // The true if a defeats b, based on their elo difference
- func getWin(a, b float64) bool {
- chance := a / (a + b)
- return chance >= rand.Float64()
- }
- func getRatings() map[string]float64 {
- return map[string]float64{
- "Joseph_S": 583.6006,
- "Jonas_N": 506.0191,
- "Green_T": 413.6078,
- "Harry_H": 396.8535,
- "Koryan": 387.0532,
- "DanQZ": 357.6342,
- "Alex_K": 314.4253,
- "Quaid": 302.3414,
- "Svavar_G": 272.5940,
- "Eli_M": 263.8913,
- "Noztrom": 249.9731,
- "Jeff_M": 232.0740,
- "Matt_B": 229.9798,
- "Bo_S": 192.5092,
- "Beastinshen": 188.4295,
- "Shakil_A": 180.4603,
- }
- }
- func getNames() []string {
- return []string{
- "Joseph_S",
- "Jonas_N",
- "Green_T",
- "Harry_H",
- "Koryan",
- "DanQZ",
- "Alex_K",
- "Quaid",
- "Svavar_G",
- "Eli_M",
- "Noztrom",
- "Jeff_M",
- "Matt_B",
- "Bo_S",
- "Beastinshen",
- "Shakil_A",
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement