Search in sources :

Example 1 with Ladder1v1Rating

use of com.faforever.server.entity.Ladder1v1Rating in project faf-java-server by FAForever.

the class MatchMakerServiceTest method submitSearchTwoPlayersDontMatchIfRatingsTooFarApart.

/**
 * Tests whether two players whose ratings are too far apart don't get matched.
 */
@Test
public void submitSearchTwoPlayersDontMatchIfRatingsTooFarApart() throws Exception {
    Player player1 = (Player) new Player().setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(300d).setDeviation(50d)).setLogin(LOGIN_PLAYER_1).setId(1);
    Player player2 = (Player) new Player().setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(1300d).setDeviation(50d)).setLogin(LOGIN_PLAYER_2).setId(2);
    instance.submitSearch(player1, Faction.CYBRAN, QUEUE_NAME);
    instance.submitSearch(player2, Faction.AEON, QUEUE_NAME);
    instance.processPools();
    verify(gameService, never()).createGame(any(), any(), any(), any(), any(), anyInt(), anyInt(), any());
    verify(gameService, never()).joinGame(anyInt(), eq(null), any());
}
Also used : Player(com.faforever.server.entity.Player) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Test(org.junit.Test)

Example 2 with Ladder1v1Rating

use of com.faforever.server.entity.Ladder1v1Rating in project faf-java-server by FAForever.

the class RatingServiceTest method updateLadder1v1Ratings.

@Test
public void updateLadder1v1Ratings() throws Exception {
    Player player1 = (Player) new Player().setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(1500d).setDeviation(500d)).setId(1);
    Player player2 = (Player) new Player().setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(1500d).setDeviation(500d)).setId(2);
    List<GamePlayerStats> playerStats = Arrays.asList(new GamePlayerStats().setPlayer(player1).setTeam(NO_TEAM_ID).setMean(player1.getLadder1v1Rating().getMean()).setDeviation(player1.getLadder1v1Rating().getDeviation()).setScore(10), new GamePlayerStats().setPlayer(player2).setTeam(NO_TEAM_ID).setMean(player2.getLadder1v1Rating().getMean()).setDeviation(player2.getLadder1v1Rating().getDeviation()).setScore(-1));
    instance.updateRatings(playerStats, NO_TEAM_ID, RatingType.LADDER_1V1);
    assertThat(player1.getLadder1v1Rating().getMean(), is(1765.511882354831));
    assertThat(player1.getLadder1v1Rating().getDeviation(), is(429.1918779825801));
    assertThat(player2.getLadder1v1Rating().getMean(), is(1234.4881176451688));
    assertThat(player2.getLadder1v1Rating().getDeviation(), is(429.1918779825801));
    assertThat(player1.getGlobalRating(), is(nullValue()));
    assertThat(player2.getGlobalRating(), is(nullValue()));
}
Also used : Player(com.faforever.server.entity.Player) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Test(org.junit.Test)

Example 3 with Ladder1v1Rating

use of com.faforever.server.entity.Ladder1v1Rating in project faf-java-server by FAForever.

the class MatchMakerService method findMatch.

/**
 * Tries to find the best match for a {@code search}. The minimum quality required for a match depends on the outcome
 * of {@link #passesMinimumQuality(Match)}.
 */
private Optional<Match> findMatch(MatchMakerSearch leftSearch, Set<MatchMakerSearch> alreadyChecked) {
    Ladder1v1Rating defaultRating = (Ladder1v1Rating) new Ladder1v1Rating().setMean(properties.getTrueSkill().getInitialStandardDeviation()).setDeviation(properties.getTrueSkill().getInitialStandardDeviation());
    String poolName = leftSearch.poolName;
    synchronized (searchesByPoolName) {
        return getPool(poolName).values().stream().filter(otherSearch -> !alreadyChecked.contains(otherSearch)).map(rightSearch -> {
            alreadyChecked.add(rightSearch);
            return new Match(leftSearch, rightSearch, ratingService.calculateQuality(Optional.ofNullable(leftSearch.player.getLadder1v1Rating()).orElse(defaultRating), Optional.ofNullable(rightSearch.player.getLadder1v1Rating()).orElse(defaultRating)));
        }).filter(this::passesMinimumQuality).max(Comparator.comparingDouble(value -> value.quality));
    }
}
Also used : ModService(com.faforever.server.mod.ModService) PlayerService(com.faforever.server.player.PlayerService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) GameVisibility(com.faforever.server.game.GameVisibility) Scheduled(org.springframework.scheduling.annotation.Scheduled) FeaturedMod(com.faforever.server.entity.FeaturedMod) Value(lombok.Value) Player(com.faforever.server.entity.Player) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ServerProperties(com.faforever.server.config.ServerProperties) ClientService(com.faforever.server.client.ClientService) ConnectionAware(com.faforever.server.client.ConnectionAware) RatingService(com.faforever.server.rating.RatingService) Set(java.util.Set) ErrorCode(com.faforever.server.error.ErrorCode) Faction(com.faforever.server.game.Faction) GameService(com.faforever.server.game.GameService) UUID(java.util.UUID) EqualsAndHashCode(lombok.EqualsAndHashCode) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MapService(com.faforever.server.map.MapService) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Requests(com.faforever.server.error.Requests) Game(com.faforever.server.entity.Game) MapVersion(com.faforever.server.entity.MapVersion) Optional(java.util.Optional) RequestException(com.faforever.server.error.RequestException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating)

Example 4 with Ladder1v1Rating

use of com.faforever.server.entity.Ladder1v1Rating in project faf-java-server by FAForever.

the class ClientServiceTest method sendUserDetails.

@Test
public void sendUserDetails() throws Exception {
    Avatar avatar = new Avatar().setUrl("http://example.com").setDescription("Tooltip");
    player.setAvailableAvatars(Collections.singletonList(new AvatarAssociation().setAvatar(avatar).setPlayer(player).setSelected(true))).setGlobalRating((GlobalRating) new GlobalRating().setNumGames(12).setMean(1100d).setDeviation(100d)).setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(900d).setDeviation(50d)).setClanMemberships(Collections.singletonList(new ClanMembership().setClan(new Clan().setTag("FOO")))).setCountry("CH").setLogin("JUnit").setId(5);
    instance.sendLoginDetails(player, player);
    ArgumentCaptor<PlayerResponse> captor = ArgumentCaptor.forClass(PlayerResponse.class);
    verify(clientGateway).send(captor.capture(), any());
    PlayerResponse response = captor.getValue();
    assertThat(response.getPlayerId(), is(5));
    assertThat(response.getUsername(), is("JUnit"));
    assertThat(response.getPlayer().getAvatar().getDescription(), is("Tooltip"));
    assertThat(response.getPlayer().getAvatar().getUrl(), is("http://example.com"));
    assertThat(response.getPlayer().getGlobalRating().getMean(), is(1100d));
    assertThat(response.getPlayer().getGlobalRating().getDeviation(), is(100d));
    assertThat(response.getPlayer().getLadder1v1Rating().getMean(), is(900d));
    assertThat(response.getPlayer().getLadder1v1Rating().getDeviation(), is(50d));
    assertThat(response.getPlayer().getNumberOfGames(), is(12));
    assertThat(response.getPlayer().getClanTag(), is("FOO"));
    assertThat(response.getCountry(), is("CH"));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Clan(com.faforever.server.entity.Clan) GlobalRating(com.faforever.server.entity.GlobalRating) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) ClanMembership(com.faforever.server.entity.ClanMembership) AvatarAssociation(com.faforever.server.entity.AvatarAssociation) Avatar(com.faforever.server.entity.Avatar) Test(org.junit.Test)

Example 5 with Ladder1v1Rating

use of com.faforever.server.entity.Ladder1v1Rating in project faf-java-server by FAForever.

the class GameService method updateGamePlayerStatsRating.

private void updateGamePlayerStatsRating(GamePlayerStats gamePlayerStats, Player player) {
    Game game = player.getCurrentGame();
    if (modService.isLadder1v1(game.getFeaturedMod())) {
        if (player.getLadder1v1Rating() == null) {
            ratingService.initLadder1v1Rating(player);
        }
        Assert.state(Optional.ofNullable(player.getLadder1v1Rating()).isPresent(), "Ladder1v1 rating not properly initialized");
        Ladder1v1Rating ladder1v1Rating = player.getLadder1v1Rating();
        gamePlayerStats.setDeviation(ladder1v1Rating.getDeviation());
        gamePlayerStats.setMean(ladder1v1Rating.getMean());
    } else {
        if (player.getGlobalRating() == null) {
            ratingService.initGlobalRating(player);
        }
        Assert.state(Optional.ofNullable(player.getGlobalRating()).isPresent(), "Global rating not properly initialized");
        GlobalRating globalRating = player.getGlobalRating();
        gamePlayerStats.setDeviation(globalRating.getDeviation());
        gamePlayerStats.setMean(globalRating.getMean());
    }
}
Also used : Game(com.faforever.server.entity.Game) GlobalRating(com.faforever.server.entity.GlobalRating) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating)

Aggregations

Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)7 GlobalRating (com.faforever.server.entity.GlobalRating)3 Player (com.faforever.server.entity.Player)3 Test (org.junit.Test)3 Game (com.faforever.server.entity.Game)2 ClientService (com.faforever.server.client.ClientService)1 ConnectionAware (com.faforever.server.client.ConnectionAware)1 ServerProperties (com.faforever.server.config.ServerProperties)1 Avatar (com.faforever.server.entity.Avatar)1 AvatarAssociation (com.faforever.server.entity.AvatarAssociation)1 Clan (com.faforever.server.entity.Clan)1 ClanMembership (com.faforever.server.entity.ClanMembership)1 FeaturedMod (com.faforever.server.entity.FeaturedMod)1 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)1 MapVersion (com.faforever.server.entity.MapVersion)1 Rating (com.faforever.server.entity.Rating)1 ErrorCode (com.faforever.server.error.ErrorCode)1 ProgrammingError (com.faforever.server.error.ProgrammingError)1 RequestException (com.faforever.server.error.RequestException)1 Requests (com.faforever.server.error.Requests)1