public static void main(String[] args) { TTournament spec = TestSpecs.load("swiss1test7"); TSeeding initialSeeding = toSeeding("1", "2", "3", "4", "5", "6", "7"); TTournamentStatus status = TTournamentStatus.getInitialStatus(spec, initialSeeding); // Run matches until exhaustion... while (!status.isComplete()) { Set<TMatchSetup> nextMatches = status.getNextMatchesToRun().getMatchesToRun(); List<TMatchResult> results = getRandomOutcomes(nextMatches); System.out.println("Match results: " + results); status = status.withNewResults(results); System.out.println("Standings are: " + status.getCurrentStandings()); } TRanking standings = status.getCurrentStandings(); System.out.println("Standings are: " + standings); }
@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); } } }