package com.jdbernard.teammaker

public abstract class WeightedChooser extends AbstractPlayerChooser {

    int hardLimit = 5

    public Player choose(def players) {
        def choices = []

        // find sitting threshold (longest sat - hard limit)
        int threshold = (player.max { it.gamesSat }) - hardLimit

        // add players, ignoring those past the hard limit
        players.each { player ->
            if (player.gamesSat >= threshold) {
                choices << player
                player.gamesSat.times { choices << player }
            }
        }
        return chooseRandomly(choices)
    }

    public float getOdds(def players, Player player) {
        def playerGames = player.gamesSat + 1
        def totalGames = players.sum { it.gamesSat + 1 }
        return (float) playerGames / (float) totalGames
    }
}
