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;
}
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);
}
}
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;
}
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() + ")");
}
}
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);
}
Aggregations