Advertisement
Hydreigon_Lord

Algicosathlon Elimination Simulation

Dec 29th, 2018
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. /**An elimination simulation for Algicosathlon-type competitions.
  2.  * @author Mariobrosaa Productions
  3.  */
  4. public class AlgicosathlonEliminationSimulation {
  5.     public static final String[] NAMES = {
  6.             // add your colors (in order from 1st to last) here
  7.             "Red","Orange","Yellow","Lime","Cyan","Blue","Purple","Magenta"
  8.     };
  9.     public static final double[] SCORES = {
  10.             // add your colors' scores (in order from 1st to last) here
  11.             10,8,6,4,3,2,1,0
  12.     };
  13.     public static final double[] STAKES = {
  14.             // add the next event's scores (in order from 1st to last) here
  15.             15,12,9,6,5,3,2,0
  16.     };
  17.     public static final double MULT = Math.pow(1.5,1);
  18.     public static final int NUM = NAMES.length;
  19.     public static void main(String[] args) {
  20.         if (SCORES.length!=NAMES.length) {
  21.             System.out.println("NAMES length is "+NAMES.length+" but SCORES length is "+SCORES.length);
  22.             System.exit(0);
  23.         }
  24.         if (STAKES.length!=NAMES.length) {
  25.             System.out.println("NAMES length is "+NAMES.length+" but STAKES length is "+STAKES.length);
  26.             System.exit(0);
  27.         }
  28.         double[] elimOdds = new double[NUM];
  29.         double possibilities = 1;
  30.         double lossCount, currLosses;
  31.         double[] scores = new double[NUM];
  32.         double[] oppScores = new double[NUM-1];
  33.         double[] toAdd = new double[NUM];
  34.         double[] oppToAdd = new double[NUM-1];
  35.         double[] failRanks = new double[NUM-1];
  36.         double activeScore, currentScore;
  37.         boolean activeFound;
  38.         int possiblePos;
  39.         /* Calculate the elimination odds */
  40.         for (int i=1;i<=NUM;i++) {
  41.             possibilities*=i;
  42.         }
  43.         for (int i=0;i<NUM;i++) { // For each athlete
  44.             lossCount = 0;
  45.             for (int pos=0;pos<NUM;pos++) { // For each position athlete i can get
  46.                 for (int s=0;s<NUM;s++) {
  47.                     scores[s]=SCORES[s];
  48.                     toAdd[s]=STAKES[s]*MULT;
  49.                 }
  50.                 scores[i]+=toAdd[pos]; // Update athlete's score
  51.                 activeScore=scores[i]; // Store the athlete's score
  52.                 activeFound=false;
  53.                 for (int s=0;s<NUM;s++) { // Remove the active score
  54.                     if (activeFound) {
  55.                         oppScores[s-1]=scores[s];
  56.                     } else if (scores[s]==activeScore) {
  57.                         activeFound=true;
  58.                     } else {
  59.                         oppScores[s]=scores[s];
  60.                     }
  61.                 }
  62.                 activeFound=false;
  63.                 for (int s=0;s<NUM;s++) { // Remove the active toAdd point value
  64.                     if (s>pos) {
  65.                         oppToAdd[s-1]=toAdd[s];
  66.                     } else if (s<pos) {
  67.                         oppToAdd[s]=toAdd[s];
  68.                     }
  69.                 }
  70.                 for (int opp=0;opp<NUM-1;opp++) { // For each opponent
  71.                     currentScore=oppScores[opp];
  72.                     for (int oppPos=0;oppPos<NUM-1;oppPos++) { // For each opponent position
  73.                         if (currentScore+oppToAdd[oppPos]<activeScore) { // Determine best losing position
  74.                             failRanks[opp]=oppPos;
  75.                             break;
  76.                         }
  77.                         if (currentScore+oppToAdd[oppPos]==activeScore) { // Opponent ties
  78.                             failRanks[opp]=oppPos+0.5;
  79.                             break;
  80.                         }
  81.                         if (oppPos==NUM-2) { // Opponent cannot lose
  82.                             failRanks[opp]=NUM-1;
  83.                         }
  84.                     }
  85.                 }
  86.                 currLosses=1;
  87.                 possiblePos=0;
  88.                 for (int l=NUM-2;l>=0;l--) {
  89.                     currLosses*=(failRanks[l]-possiblePos);
  90.                     possiblePos++;
  91.                 }
  92.                 lossCount+=currLosses;
  93.             }
  94.             elimOdds[i]=lossCount/possibilities;
  95.             System.out.println(NAMES[i]+": "+(100*elimOdds[i])+"% (1 in "+(1/elimOdds[i])+")");
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement