Search in sources :

Example 1 with IPlayer

use of jskills.IPlayer in project faf-java-server by FAForever.

the class RatingService method teamsById.

private Map<Integer, ScoredTeam> teamsById(Collection<GamePlayerStats> playerStats, int noTeamId) {
    int highestTeamId = playerStats.stream().map(GamePlayerStats::getTeam).max(Integer::compareTo).orElse(noTeamId);
    Map<Integer, ScoredTeam> teamsById = new HashMap<>();
    for (GamePlayerStats playerStat : playerStats) {
        IPlayer player = new Player<>(playerStat.getPlayer().getId());
        jskills.Rating rating = new jskills.Rating(playerStat.getMean(), playerStat.getDeviation());
        int teamId = playerStat.getTeam();
        if (teamId == noTeamId) {
            // If a player is in the "no team" team, assign him to his own team
            teamId = playerStat.getPlayer().getId() + highestTeamId;
        }
        teamsById.computeIfAbsent(teamId, ScoredTeam::new).addPlayer(player, rating);
        teamsById.get(teamId).getScore().updateAndGet(score -> score + playerStat.getScore());
    }
    return teamsById;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IPlayer(jskills.IPlayer) Player(jskills.Player) IPlayer(jskills.IPlayer) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) HashMap(java.util.HashMap) Rating(com.faforever.server.entity.Rating) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) GlobalRating(com.faforever.server.entity.GlobalRating)

Example 2 with IPlayer

use of jskills.IPlayer in project ACManager by kun368.

the class PlayerPriorValuesToSkillsLayer method buildLayer.

@Override
public void buildLayer() {
    for (ITeam currentTeam : teams) {
        List<KeyedVariable<IPlayer, GaussianDistribution>> currentTeamSkills = new ArrayList<>();
        for (Entry<IPlayer, Rating> currentTeamPlayer : currentTeam.entrySet()) {
            KeyedVariable<IPlayer, GaussianDistribution> playerSkill = createSkillOutputVariable(currentTeamPlayer.getKey());
            AddLayerFactor(createPriorFactor(currentTeamPlayer.getKey(), currentTeamPlayer.getValue(), playerSkill));
            currentTeamSkills.add(playerSkill);
        }
        addOutputVariableGroup(currentTeamSkills);
    }
}
Also used : IPlayer(jskills.IPlayer) GaussianDistribution(jskills.numerics.GaussianDistribution) Rating(jskills.Rating) ArrayList(java.util.ArrayList) ITeam(jskills.ITeam)

Example 3 with IPlayer

use of jskills.IPlayer in project ACManager by kun368.

the class TrueSkillFactorGraph method getUpdatedRatings.

public Map<IPlayer, Rating> getUpdatedRatings() {
    Map<IPlayer, Rating> result = new HashMap<>();
    for (List<KeyedVariable<IPlayer, GaussianDistribution>> currentTeam : priorLayer.getOutputVariablesGroups()) {
        for (KeyedVariable<IPlayer, GaussianDistribution> currentPlayer : currentTeam) {
            final Rating rating = new Rating(currentPlayer.getValue().getMean(), currentPlayer.getValue().getStandardDeviation());
            result.put(currentPlayer.getKey(), rating);
        }
    }
    return result;
}
Also used : IPlayer(jskills.IPlayer) GaussianDistribution(jskills.numerics.GaussianDistribution) Rating(jskills.Rating)

Example 4 with IPlayer

use of jskills.IPlayer in project VoxelGamesLibv2 by VoxelGamesLib.

the class EloHandler method update.

private void update(@Nonnull Game game, @Nonnull Map<IPlayer, Rating> newRatings) {
    for (IPlayer iPlayer : newRatings.keySet()) {
        if (!(iPlayer instanceof User)) {
            log.warning("WTF");
            continue;
        }
        User user = (User) iPlayer;
        user.saveRating(game.getGameMode(), newRatings.get(iPlayer));
        // TODO fixme
        log.info("New Rating for " + user.getRawDisplayName() + " is " + newRatings.get(iPlayer).getMean() + "(" + newRatings.get(iPlayer).getStandardDeviation() + ")");
    }
}
Also used : IPlayer(jskills.IPlayer) User(com.voxelgameslib.voxelgameslib.user.User)

Example 5 with IPlayer

use of jskills.IPlayer in project VoxelGamesLibv2 by VoxelGamesLib.

the class EloHandler method handleGameEnd.

/**
 * Handles the elo calculation for generic games
 *
 * @param game  the game that ended
 * @param users the users which played this game, in order, first = winner
 */
public void handleGameEnd(@Nonnull Game game, @Nonnull User... users) {
    List<ITeam> teams = new ArrayList<>();
    for (User user : users) {
        teams.add(new jskills.Team(user, user.getRating(game.getGameMode())));
    }
    Map<IPlayer, Rating> newRatings = calculator.calculateNewRatings(game.getGameMode(), teams, IntStream.of(users.length).toArray());
    update(game, newRatings);
}
Also used : IPlayer(jskills.IPlayer) User(com.voxelgameslib.voxelgameslib.user.User) Rating(jskills.Rating) ArrayList(java.util.ArrayList) ITeam(jskills.ITeam)

Aggregations

IPlayer (jskills.IPlayer)5 Rating (jskills.Rating)3 User (com.voxelgameslib.voxelgameslib.user.User)2 ArrayList (java.util.ArrayList)2 ITeam (jskills.ITeam)2 GaussianDistribution (jskills.numerics.GaussianDistribution)2 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)1 GlobalRating (com.faforever.server.entity.GlobalRating)1 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)1 Rating (com.faforever.server.entity.Rating)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Player (jskills.Player)1