Ejemplo n.º 1
0
 public static StandardRanking createForSeeding(TSeeding initialSeeding) {
   List<TPlayerScore> scores = Lists.newArrayList();
   ImmutableList<TPlayer> players = initialSeeding.getPlayersBestFirst();
   for (int i = 0; i < players.size(); i++) {
     TPlayer player = players.get(i);
     scores.add(TPlayerScore.create(player, EmptyScore.create(), i));
   }
   return StandardRanking.create(scores);
 }
Ejemplo n.º 2
0
  @Test
  public void testNonLosingPlayerAlwaysWins() {
    TTournament spec = TestSpecs.load(testSpec);
    for (long seed = 0L; seed < 100L; seed++) {
      try {
        Random random = new Random(seed);
        TSeeding initialSeeding = FuzzTests.createRandomSeeding(random, numPlayers);
        TTournamentStatus status = TTournamentStatus.getInitialStatus(spec, initialSeeding);
        Set<TPlayer> playersInRound = Sets.newHashSet();
        boolean nonFixedSumGamePlayed = false;
        TRanking standings = status.getCurrentStandings();
        while (true) {
          Set<TMatchSetup> nextMatches = status.getNextMatchesToRun().getMatchesToRun();
          if (nextMatches.isEmpty()) {
            break;
          }

          // To keep this deterministic, we need to go through the matches in sorted order
          SortedSet<TMatchSetup> sortedMatches =
              ImmutableSortedSet.copyOf(MatchSetups.COMPARATOR, nextMatches);
          List<TMatchResult> results = Lists.newArrayList();
          for (TMatchSetup match : sortedMatches) {
            playersInRound.addAll(match.getPlayers());
            nonFixedSumGamePlayed |= !match.getGame().isFixedSum();

            results.add(FuzzTests.getResult(random, match));
          }

          status = status.withNewResults(results);

          // Standings change when the round shifts
          TRanking newStandings = status.getCurrentStandings();
          if (!standings.equals(newStandings)) {
            // Check that players with byes didn't go down in the rankings
            // if it was a fixed-sum game
            if (!nonFixedSumGamePlayed) {
              for (TPlayer player : initialSeeding.getPlayersBestFirst()) {
                if (!playersInRound.contains(player)) {
                  int oldPosition = standings.getPosition(player);
                  int newPosition = newStandings.getPosition(player);
                  // Lower numbers are better
                  if (newPosition > oldPosition) {
                    fail(
                        "Player "
                            + player
                            + " fell from "
                            + oldPosition
                            + " to "
                            + newPosition
                            + " despite having a bye");
                  }
                }
              }
            }

            // Reset the players we examine
            nonFixedSumGamePlayed = false;
            playersInRound.clear();
            standings = newStandings;
          }
        }

      } catch (Exception | AssertionError e) {
        throw new RuntimeException("Seed was " + seed, e);
      }
    }
  }