VincentOostelbos

Lives left simulation extended

Jul 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package livesPredictor;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. public class LivesPredictor {
  7.     static Random rnd;
  8.     static double winProb;
  9.    
  10.     public static void main(String[] args) {
  11.         rnd = new Random();
  12.         ArrayList<Double> probs = new ArrayList<Double>();
  13.         ArrayList<Integer> lives = new ArrayList<Integer>();
  14.         double p;
  15.        
  16.         probs.add(0.5); // Win chance per game against boss 1
  17.         probs.add(0.8); // Win chance per game against boss 2
  18.         probs.add(0.9); // Win chance per game against boss 3
  19.         probs.add(0.4); // Win chance per game against boss 4
  20.        
  21.         for(int i=0; i<4; i++) lives.add(0); // Counts for 0 lives left, 1 life left, 2 lives left, 3 lives left; each start at 0
  22.        
  23.         for(int t=0; t<1000000; t++) {
  24.             int l = 3;
  25.             for(int b=1; b<probs.size()+1; b++) { // b stands for the boss number
  26.                 p = rnd.nextDouble();
  27.                
  28.                 while(p > probs.get(b-1) && l > 0) { // While losing against boss b and still lives left to lose, roll a new probability
  29.                     l--;
  30.                     p = rnd.nextDouble();
  31.                 }
  32.             }
  33.            
  34.             int count = lives.get(l);
  35.             lives.set(l, count+1); // Increment lives left at end
  36.         }
  37.        
  38.         for(int i=0; i<4; i++) {
  39.             System.out.println("Times with " + i + " lives left: " + lives.get(i) + ".");
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment