Adding chances calculation for Swiss tournament.
This commit is contained in:
@@ -33,16 +33,32 @@ public class SwissPairingMechanismTest {
|
|||||||
// Sally has 66% chance of winning a game against Jack and 50% against anotherSally, Jack has 50% of winning
|
// Sally has 66% chance of winning a game against Jack and 50% against anotherSally, Jack has 50% of winning
|
||||||
// a game against another Jack
|
// a game against another Jack
|
||||||
|
|
||||||
int repeatCount = 10000;
|
int repeatCount = 100000;
|
||||||
int playerCount = 260;
|
|
||||||
int roundCount = 9;
|
int roundCount = 9;
|
||||||
|
|
||||||
int betterPlayerWin =0;
|
int betterPlayerCount = 10;
|
||||||
|
int worsePlayerCount = 250;
|
||||||
|
float chanceToWin = 0.66666f;
|
||||||
|
|
||||||
|
int playerCount = betterPlayerCount+worsePlayerCount;
|
||||||
|
|
||||||
|
int betterPlayerWins =0;
|
||||||
|
|
||||||
|
Set<String> betterPlayers = new HashSet<String>();
|
||||||
|
Set<String> worsePlayers = new HashSet<String>();
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
for (int repeat = 0; repeat < repeatCount; repeat++) {
|
for (int repeat = 0; repeat < repeatCount; repeat++) {
|
||||||
Set<String> players = new HashSet<String>();
|
Set<String> players = new HashSet<String>();
|
||||||
for (int i = 0; i < playerCount; i++)
|
for (int i = 0; i < playerCount; i++) {
|
||||||
players.add(String.valueOf(i));
|
String playerName = String.valueOf(i);
|
||||||
|
players.add(playerName);
|
||||||
|
if (i<betterPlayerCount)
|
||||||
|
betterPlayers.add(playerName);
|
||||||
|
else
|
||||||
|
worsePlayers.add(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> droppedPlayers = new HashSet<String>();
|
Set<String> droppedPlayers = new HashSet<String>();
|
||||||
Map<String, Integer> byes = new HashMap<String, Integer>();
|
Map<String, Integer> byes = new HashMap<String, Integer>();
|
||||||
@@ -71,7 +87,7 @@ public class SwissPairingMechanismTest {
|
|||||||
String playerOne = newPairing.getKey();
|
String playerOne = newPairing.getKey();
|
||||||
String playerTwo = newPairing.getValue();
|
String playerTwo = newPairing.getValue();
|
||||||
|
|
||||||
String winner = getWinner(playerOne, playerTwo);
|
String winner = getWinner(rnd, betterPlayers, worsePlayers, playerOne, playerTwo, chanceToWin);
|
||||||
|
|
||||||
previouslyPaired.get(playerOne).add(playerTwo);
|
previouslyPaired.get(playerOne).add(playerTwo);
|
||||||
previouslyPaired.get(playerTwo).add(playerOne);
|
previouslyPaired.get(playerTwo).add(playerOne);
|
||||||
@@ -82,39 +98,36 @@ public class SwissPairingMechanismTest {
|
|||||||
}
|
}
|
||||||
List<PlayerStanding> standings = BestOfOneStandingsProducer.produceStandings(players, matches, 1, 0, byes);
|
List<PlayerStanding> standings = BestOfOneStandingsProducer.produceStandings(players, matches, 1, 0, byes);
|
||||||
|
|
||||||
String firstSemi = getWinner(standings.get(0).getPlayerName(), standings.get(7).getPlayerName());
|
String firstSemi = getWinner(rnd, betterPlayers, worsePlayers, standings.get(0).getPlayerName(), standings.get(7).getPlayerName(), chanceToWin);
|
||||||
String secondSemi = getWinner(standings.get(1).getPlayerName(), standings.get(6).getPlayerName());
|
String secondSemi = getWinner(rnd, betterPlayers, worsePlayers, standings.get(1).getPlayerName(), standings.get(6).getPlayerName(), chanceToWin);
|
||||||
String thirdSemi = getWinner(standings.get(2).getPlayerName(), standings.get(5).getPlayerName());
|
String thirdSemi = getWinner(rnd, betterPlayers, worsePlayers, standings.get(2).getPlayerName(), standings.get(5).getPlayerName(), chanceToWin);
|
||||||
String fourthSemi = getWinner(standings.get(3).getPlayerName(), standings.get(4).getPlayerName());
|
String fourthSemi = getWinner(rnd, betterPlayers, worsePlayers, standings.get(3).getPlayerName(), standings.get(4).getPlayerName(), chanceToWin);
|
||||||
|
|
||||||
String firstFinalist = getWinner(firstSemi, fourthSemi);
|
String firstFinalist = getWinner(rnd, betterPlayers, worsePlayers, firstSemi, fourthSemi, chanceToWin);
|
||||||
String secondFinalist = getWinner(secondSemi, thirdSemi);
|
String secondFinalist = getWinner(rnd, betterPlayers, worsePlayers, secondSemi, thirdSemi, chanceToWin);
|
||||||
|
|
||||||
String winner = getWinner(firstFinalist, secondFinalist);
|
String winner = getWinner(rnd, betterPlayers, worsePlayers, firstFinalist, secondFinalist, chanceToWin);
|
||||||
|
|
||||||
if (Integer.parseInt(winner)<10)
|
if (betterPlayers.contains(winner))
|
||||||
betterPlayerWin++;
|
betterPlayerWins++;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(betterPlayerWin);
|
System.out.println(betterPlayerWins);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getWinner(String playerOne, String playerTwo) {
|
private String getWinner(Random rnd, Set<String> betterPlayers, Set<String> worsePlayers, String playerOne, String playerTwo, float winChance) {
|
||||||
int playerOneNo = Integer.parseInt(playerOne);
|
if (betterPlayers.contains(playerOne) && worsePlayers.contains(playerTwo)) {
|
||||||
int playerTwoNo = Integer.parseInt(playerTwo);
|
if (rnd.nextFloat() < winChance)
|
||||||
|
|
||||||
if (playerOneNo < 10 && playerTwoNo >= 10) {
|
|
||||||
if (new Random().nextFloat() < 0.66f)
|
|
||||||
return playerOne;
|
return playerOne;
|
||||||
else
|
else
|
||||||
return playerTwo;
|
return playerTwo;
|
||||||
} else if (playerTwoNo < 10 && playerOneNo >= 10) {
|
} else if (betterPlayers.contains(playerTwo) && worsePlayers.contains(playerOne)) {
|
||||||
if (new Random().nextFloat() < 0.66f)
|
if (rnd.nextFloat() < winChance)
|
||||||
return playerTwo;
|
return playerTwo;
|
||||||
else
|
else
|
||||||
return playerOne;
|
return playerOne;
|
||||||
} else {
|
} else {
|
||||||
if (new Random().nextBoolean())
|
if (rnd.nextBoolean())
|
||||||
return playerOne;
|
return playerOne;
|
||||||
else
|
else
|
||||||
return playerTwo;
|
return playerTwo;
|
||||||
|
|||||||
Reference in New Issue
Block a user