Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package livesPredictor;
- import java.util.ArrayList;
- import java.util.Random;
- public class LivesPredictor {
- static Random rnd;
- static double winProb;
- public static void main(String[] args) {
- rnd = new Random();
- ArrayList<Double> probs = new ArrayList<Double>();
- ArrayList<Integer> lives = new ArrayList<Integer>();
- double p;
- probs.add(0.5); // Win chance per game against boss 1
- probs.add(0.8); // Win chance per game against boss 2
- probs.add(0.9); // Win chance per game against boss 3
- probs.add(0.4); // Win chance per game against boss 4
- 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
- for(int t=0; t<1000000; t++) {
- int l = 3;
- for(int b=1; b<probs.size()+1; b++) { // b stands for the boss number
- p = rnd.nextDouble();
- while(p > probs.get(b-1) && l > 0) { // While losing against boss b and still lives left to lose, roll a new probability
- l--;
- p = rnd.nextDouble();
- }
- }
- int count = lives.get(l);
- lives.set(l, count+1); // Increment lives left at end
- }
- for(int i=0; i<4; i++) {
- System.out.println("Times with " + i + " lives left: " + lives.get(i) + ".");
- }
- }
- }
Add Comment
Please, Sign In to add comment