Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**An elimination simulation for Algicosathlon-type competitions.
- * @author Mariobrosaa Productions
- */
- public class AlgicosathlonEliminationSimulation {
- public static final String[] NAMES = {
- // add your colors (in order from 1st to last) here
- "Red","Orange","Yellow","Lime","Cyan","Blue","Purple","Magenta"
- };
- public static final double[] SCORES = {
- // add your colors' scores (in order from 1st to last) here
- 10,8,6,4,3,2,1,0
- };
- public static final double[] STAKES = {
- // add the next event's scores (in order from 1st to last) here
- 15,12,9,6,5,3,2,0
- };
- public static final double MULT = Math.pow(1.5,1);
- public static final int NUM = NAMES.length;
- public static void main(String[] args) {
- if (SCORES.length!=NAMES.length) {
- System.out.println("NAMES length is "+NAMES.length+" but SCORES length is "+SCORES.length);
- System.exit(0);
- }
- if (STAKES.length!=NAMES.length) {
- System.out.println("NAMES length is "+NAMES.length+" but STAKES length is "+STAKES.length);
- System.exit(0);
- }
- double[] elimOdds = new double[NUM];
- double possibilities = 1;
- double lossCount, currLosses;
- double[] scores = new double[NUM];
- double[] oppScores = new double[NUM-1];
- double[] toAdd = new double[NUM];
- double[] oppToAdd = new double[NUM-1];
- double[] failRanks = new double[NUM-1];
- double activeScore, currentScore;
- boolean activeFound;
- int possiblePos;
- /* Calculate the elimination odds */
- for (int i=1;i<=NUM;i++) {
- possibilities*=i;
- }
- for (int i=0;i<NUM;i++) { // For each athlete
- lossCount = 0;
- for (int pos=0;pos<NUM;pos++) { // For each position athlete i can get
- for (int s=0;s<NUM;s++) {
- scores[s]=SCORES[s];
- toAdd[s]=STAKES[s]*MULT;
- }
- scores[i]+=toAdd[pos]; // Update athlete's score
- activeScore=scores[i]; // Store the athlete's score
- activeFound=false;
- for (int s=0;s<NUM;s++) { // Remove the active score
- if (activeFound) {
- oppScores[s-1]=scores[s];
- } else if (scores[s]==activeScore) {
- activeFound=true;
- } else {
- oppScores[s]=scores[s];
- }
- }
- activeFound=false;
- for (int s=0;s<NUM;s++) { // Remove the active toAdd point value
- if (s>pos) {
- oppToAdd[s-1]=toAdd[s];
- } else if (s<pos) {
- oppToAdd[s]=toAdd[s];
- }
- }
- for (int opp=0;opp<NUM-1;opp++) { // For each opponent
- currentScore=oppScores[opp];
- for (int oppPos=0;oppPos<NUM-1;oppPos++) { // For each opponent position
- if (currentScore+oppToAdd[oppPos]<activeScore) { // Determine best losing position
- failRanks[opp]=oppPos;
- break;
- }
- if (currentScore+oppToAdd[oppPos]==activeScore) { // Opponent ties
- failRanks[opp]=oppPos+0.5;
- break;
- }
- if (oppPos==NUM-2) { // Opponent cannot lose
- failRanks[opp]=NUM-1;
- }
- }
- }
- currLosses=1;
- possiblePos=0;
- for (int l=NUM-2;l>=0;l--) {
- currLosses*=(failRanks[l]-possiblePos);
- possiblePos++;
- }
- lossCount+=currLosses;
- }
- elimOdds[i]=lossCount/possibilities;
- System.out.println(NAMES[i]+": "+(100*elimOdds[i])+"% (1 in "+(1/elimOdds[i])+")");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement