use of jskills.Player 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.Player in project faf-java-server by FAForever.
the class RatingService method calculateQuality.
public double calculateQuality(Rating left, Rating right) {
jskills.Rating leftRating = ofNullable(left).map(rating -> new jskills.Rating(left.getMean(), left.getDeviation())).orElse(gameInfo.getDefaultRating());
jskills.Rating rightRating = ofNullable(left).map(rating -> new jskills.Rating(right.getMean(), right.getDeviation())).orElse(gameInfo.getDefaultRating());
Collection<ITeam> teams = Arrays.asList(new Team(new Player<>(1), leftRating), new Team(new Player<>(2), rightRating));
return TrueSkillCalculator.calculateMatchQuality(gameInfo, teams);
}
use of jskills.Player in project faf-java-server by FAForever.
the class RatingService method updateRatings.
/**
* Updates the ratings of all players in {@code playerStats} as well as their global/ladder1v1 rating,
* according to the outcome of the game <strong> without persisting the results</strong>.
*
* @param noTeamId ID of the "no team" team
*/
@SuppressWarnings("unchecked")
public void updateRatings(Collection<GamePlayerStats> playerStats, int noTeamId, RatingType ratingType) {
Map<Integer, GamePlayerStats> playerStatsByPlayerId = playerStats.stream().collect(Collectors.toMap(stats -> stats.getPlayer().getId(), Function.identity()));
Map<Integer, ScoredTeam> teamsById = teamsById(playerStats, noTeamId);
List<ScoredTeam> teamsSortedByScore = new ArrayList<>(teamsById.values());
teamsSortedByScore.sort(Comparator.comparingInt(o -> ((ScoredTeam) o).getScore().intValue()).reversed());
int[] teamRanks = calculateTeamRanks(teamsSortedByScore);
// New ArrayList is needed because the JSkill API doesn't handle subclass type parameters
TrueSkillCalculator.calculateNewRatings(gameInfo, new ArrayList<>(teamsSortedByScore), teamRanks).entrySet().forEach(entry -> {
Player<Integer> player = (Player<Integer>) entry.getKey();
GamePlayerStats stats = playerStatsByPlayerId.get(player.getId());
updatePlayerStats(entry, stats);
updateRating(ratingType, stats);
});
}
Aggregations