LucidSigma

Chance of Elimination (Processing 3.0.1)

Apr 3rd, 2016
1,564
2
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 2 0
  1. /*The only things that need to be changed are the lines followed by comments*/
  2. int simulations = 10000000;
  3.  
  4. int numberOfAthletes = 16; //Number of athletes left
  5. int[] originalScores = {100, 75, 60, 50, 40, 30, 25, 20, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1}; //Initial scores
  6.  
  7. float increaser = 1.5;
  8. int eventNumber = 2; //Number of the current event (excluding team events)
  9. int powerEventNumber = eventNumber - 1;
  10. float multiplyFactor = pow(increaser, powerEventNumber);
  11.  
  12. float[] loseCount = new float[numberOfAthletes];
  13.  
  14. void setup() {
  15.   for (int i = 0; i < numberOfAthletes; i++) {
  16.     loseCount[i] = 0;
  17.   }
  18.  
  19.   for (int i = 0; i < simulations; i++) {
  20.     int[] swap = new int[numberOfAthletes];
  21.     boolean[] taken = new boolean[numberOfAthletes];
  22.     int[] currentScores = {158, 119, 112, 110, 95, 90, 78, 77, 55, 53, 50, 45, 43, 35, 24, 12}; //Athlete's current scores
  23.  
  24.     for (int j = 0; j < numberOfAthletes; j++) {
  25.       swap[j] = -1;
  26.       taken[j] = false;
  27.     }
  28.  
  29.     for (int j = 0; j < numberOfAthletes; j++) {
  30.       while (swap[j] == -1 || taken[swap[j]]) {
  31.         swap[j] = int(random(0, numberOfAthletes));
  32.       }
  33.  
  34.       taken[swap[j]] = true;
  35.       currentScores[j] += round(originalScores[swap[j]] * multiplyFactor);
  36.     }
  37.  
  38.     int lowestScore = 10000000;
  39.     int eliminatedAthlete = 0;
  40.  
  41.     for (int j = 0; j < numberOfAthletes; j++) {
  42.       if (currentScores[j] < lowestScore) {
  43.         lowestScore = currentScores[j];
  44.         eliminatedAthlete = j;
  45.       }
  46.     }
  47.  
  48.     loseCount[eliminatedAthlete]++;
  49.   }
  50.  
  51.   for (int i = 0; i < numberOfAthletes; i++) {
  52.     loseCount[i] = loseCount[i] / (float(simulations) / 100.0);
  53.     println("Athlete " + (i + 1) + "'s percentage: " + loseCount[i] + "%");
  54.   }
  55. }
Add Comment
Please, Sign In to add comment