diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/tournament/SwissPairingMechanismTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/tournament/SwissPairingMechanismTest.java index 5cf66bd13..07558159b 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/tournament/SwissPairingMechanismTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/tournament/SwissPairingMechanismTest.java @@ -5,9 +5,17 @@ import com.gempukku.lotro.competitive.PlayerStanding; import org.apache.commons.lang.StringUtils; import org.junit.Test; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; public class SwissPairingMechanismTest { // @Test @@ -20,6 +28,99 @@ public class SwissPairingMechanismTest { // } // } + public void calculateSallyJackChances() { + // 10 Sallys and 250 Jacks play in a tournament with 9 rounds of Swiss and Top 8. + // Sally has 66% chance of winning a game against Jack and 50% against anotherSally, Jack has 50% of winning + // a game against another Jack + + int repeatCount = 10000; + int playerCount = 260; + int roundCount = 9; + + int betterPlayerWin =0; + + for (int repeat = 0; repeat < repeatCount; repeat++) { + Set players = new HashSet(); + for (int i = 0; i < playerCount; i++) + players.add(String.valueOf(i)); + + Set droppedPlayers = new HashSet(); + Map byes = new HashMap(); + + Set matches = new HashSet(); + Map> previouslyPaired = new HashMap>(); + for (String player : players) + previouslyPaired.put(player, new HashSet()); + + SwissPairingMechanism pairing = new SwissPairingMechanism("swiss"); + for (int i = 1; i <= roundCount; i++) { + if (!pairing.isFinished(i - 1, players, droppedPlayers)) { + List standings = BestOfOneStandingsProducer.produceStandings(players, matches, 3, 0, byes); + + Map newPairings = new LinkedHashMap(); + Set newByes = new HashSet(); + + pairing.pairPlayers(i, players, droppedPlayers, byes, standings, previouslyPaired, newPairings, newByes); + if (newByes.size() > 0) { + for (String newBye : newByes) { + byes.put(newBye, 1); + } + } + + for (Map.Entry newPairing : newPairings.entrySet()) { + String playerOne = newPairing.getKey(); + String playerTwo = newPairing.getValue(); + + String winner = getWinner(playerOne, playerTwo); + + previouslyPaired.get(playerOne).add(playerTwo); + previouslyPaired.get(playerTwo).add(playerOne); + + matches.add(new TournamentMatch(playerOne, playerTwo, winner, i)); + } + } + } + List standings = BestOfOneStandingsProducer.produceStandings(players, matches, 1, 0, byes); + + String firstSemi = getWinner(standings.get(0).getPlayerName(), standings.get(7).getPlayerName()); + String secondSemi = getWinner(standings.get(1).getPlayerName(), standings.get(6).getPlayerName()); + String thirdSemi = getWinner(standings.get(2).getPlayerName(), standings.get(5).getPlayerName()); + String fourthSemi = getWinner(standings.get(3).getPlayerName(), standings.get(4).getPlayerName()); + + String firstFinalist = getWinner(firstSemi, fourthSemi); + String secondFinalist = getWinner(secondSemi, thirdSemi); + + String winner = getWinner(firstFinalist, secondFinalist); + + if (Integer.parseInt(winner)<10) + betterPlayerWin++; + } + + System.out.println(betterPlayerWin); + } + + private String getWinner(String playerOne, String playerTwo) { + int playerOneNo = Integer.parseInt(playerOne); + int playerTwoNo = Integer.parseInt(playerTwo); + + if (playerOneNo < 10 && playerTwoNo >= 10) { + if (new Random().nextFloat() < 0.66f) + return playerOne; + else + return playerTwo; + } else if (playerTwoNo < 10 && playerOneNo >= 10) { + if (new Random().nextFloat() < 0.66f) + return playerTwo; + else + return playerOne; + } else { + if (new Random().nextBoolean()) + return playerOne; + else + return playerTwo; + } + } + @Test public void testPairingSmallTournament() { int repeatCount = 10; @@ -70,7 +171,7 @@ public class SwissPairingMechanismTest { List standings = BestOfOneStandingsProducer.produceStandings(players, matches, 1, 0, byes); for (PlayerStanding standing : standings) { String player = standing.getPlayerName(); - log(player +" points - "+standing.getPoints() + " played against: "+ StringUtils.join(previouslyPaired.get(player), ",")); + log(player + " points - " + standing.getPoints() + " played against: " + StringUtils.join(previouslyPaired.get(player), ",")); } Map newPairings = new LinkedHashMap(); @@ -97,7 +198,7 @@ public class SwissPairingMechanismTest { System.out.println("Paired " + playerOne + " against " + playerTwo + " points - " + getPlayerPoints(standings, playerOne) + " vs " + getPlayerPoints(standings, playerTwo)); String winner = new Random().nextBoolean() ? playerOne : playerTwo; - log("Winner - "+winner); + log("Winner - " + winner); previouslyPaired.get(playerOne).add(playerTwo); previouslyPaired.get(playerTwo).add(playerOne);