All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.wakingrufus.elo.EloLeague.kt Maven / Gradle / Ivy

Go to download

A library which performs ELO calculations for a game league (such as chess)

There is a newer version: 0.4.0
Show newest version
package com.github.wakingrufus.elo

fun calculateNewLeague(league: League, games: List): LeagueState {
    var leagueState = LeagueState(league = league)
    games.stream()
            .sorted({ g1: Game, g2: Game -> (g2.entryDate.epochSecond - g1.entryDate.epochSecond).toInt() })
            .forEach { leagueState = addGameToLeague(leagueState, it) }
    return leagueState
}

fun addGameToLeague(leagueState: LeagueState, game: Game): LeagueState {
    var newLeagueState = leagueState.copy(
            players = addNewPlayers(
                    existingPlayers = leagueState.players,
                    game = game,
                    startingRating = leagueState.league.startingRating))
    val changes = calculateChanges(
            league = newLeagueState.league,
            players = newLeagueState.players,
            game = game)
    newLeagueState = newLeagueState.copy(players = applyChanges(players = newLeagueState.players, changes = changes))
    newLeagueState = newLeagueState.copy(history = leagueState.history + changes)
    return newLeagueState
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy