Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class MutationSimulation
- {
- private int[] perfectSet;
- private int[] pickedMuts;
- private int picks;
- private int levels;
- private int amount;
- private int destiny;
- private int isHorror;
- private Random RNGesus;
- public MutationSimulation(int mutations, int horror)
- {
- this.perfectSet = new int[Math.max(6,mutations)];
- this.perfectSet[0] = 1;
- this.perfectSet[1] = 3;
- this.perfectSet[2] = 13;
- this.perfectSet[3] = 22;
- this.perfectSet[4] = 23;
- this.perfectSet[5] = 27;
- if(mutations>=7) this.perfectSet[6] = 11;
- if(mutations>=8) this.perfectSet[7] = 7;
- if(mutations>=9) this.perfectSet[8] = 17;
- this.pickedMuts = new int[20];
- this.picks = 0;
- this.levels = 0; // Needs to be defined separately from the amount of picks, since destiny and rerolls are free extra mutations.
- this.amount = 0;
- this.destiny = 0;
- this.isHorror = horror;
- RNGesus = new Random();
- }
- // Main function of the simulation. Simulates getting a set of four (or more) mutations, comparing them to the mutations in the perfect set, and choosing them if so.
- public void getMutation(boolean ultraDestiny)
- {
- int mutPick = 0;
- boolean wish = false;
- boolean patience = false;
- boolean goForDestiny = false;
- int[] thisSet = new int[4+this.isHorror]; // Build an array of the mutations in this set
- for(int i=0; i<4+this.isHorror; i++)
- {
- boolean picked = false;
- while(!picked)
- {
- int mut = (int) (Math.ceil(Math.random()*28)); // Amount of mutations in the game
- picked = true;
- for(int j=0; j<this.pickedMuts.length; j++)
- {
- for(int h=0; h<thisSet.length; h++)
- if(mut == this.pickedMuts[j] || mut == thisSet[h]) // Check against already chosen mutations this run (and this set)
- {
- picked = false;
- }
- }
- if(picked)
- {
- mutPick = mut;
- thisSet[i] = mut;
- if(mut == 18) wish = true;
- if(mut == 25) patience = true; // Note if a reroll mutation came up, which will be picked after generating the last mutation if nothing in the perfect set is found.
- }
- }
- // For destiny at ultra, only one mutation will be rolled, so the loop immediately ends after the subsequent check of whether or not it is perfect.
- if(ultraDestiny) i = 10;
- for(int k=0; k<this.perfectSet.length; k++)
- {
- // If something in the perfect set was found
- if(mutPick == this.perfectSet[k])
- {
- // Adds the mutation rolled into the list of picked mutations, so it can't be rolled again. Also increments the amount of total perfect mutations.
- this.pickedMuts[this.picks] = mutPick;
- this.picks++;
- this.levels++;
- this.amount++;
- if(goForDestiny)
- {
- // If the set was continued rolling after a possible destiny play, take destiny, decrease the level by one to represent a free mutation, and end the loop.
- this.destiny++;
- this.levels--;
- i = 10;
- }
- if(i <= 0+this.isHorror && this.destiny == 0 && (this.levels==4||this.levels==5||this.isHorror>0))
- {
- // If this is the first mutation in the set, destiny was not picked yet, and the player is level 5 or 6 (or Horror), keep rolling the rest of set for another possible perfect mutation.
- goForDestiny = true;
- }
- else
- {
- // If it isn't the first mutation of the set (and the first mutation was not perfect either), stop rolling, and end the loop choosing this mutation.
- i = 10;
- }
- }
- }
- // If nothing in the perfect set was found
- if(i == 3+this.isHorror)
- {
- this.picks++;
- if(wish && !goForDestiny) mutPick = 18;
- if(patience && !goForDestiny) mutPick = 25; // If a set was put on hold due to possible destiny, prohibit also getting a reroll from that set later on.
- this.pickedMuts[this.picks] = mutPick; // The chosen mutation will be whichever was rolled last, since nothing was good.
- if(mutPick != 18 && mutPick != 25) this.levels++; // If a reroll was chosen, total mutation counter isn't incremented.
- }
- }
- }
- // Simulates an entire run worth of mutations.
- public int pickAllMuts()
- {
- // Picks eight regular mutations (i.e. anything except rerolls and destiny).
- while(this.levels<8)
- {
- getMutation(false);
- }
- // If Destiny was never taken during the run, take it at ultra if you got a cursed weapon that run (which is what the 70% probability check is for).
- if(this.destiny == 0 && Math.random()<0.7)
- {
- getMutation(true);
- }
- return this.amount; // To be compared with the overall target number of perfect mutations in the main function.
- }
- public static void main(String[] args)
- {
- int perfectSets = 0;
- for(int i=0; i<100000; i++)
- {
- /* User instructions:
- This can simulate trying to get a perfect 6, 7, 8, or 9, by editing the first parameter of MutationSimulation and the check value of the if statement.
- It can also simulate playing Horror, by editing the second parameter of MutationSimulation. (Also supports multiple Horrors in co-op.)
- */
- MutationSimulation mutant = new MutationSimulation(7,0);
- int number = mutant.pickAllMuts();
- if(number>=7) perfectSets++;
- }
- System.out.print("Got "+perfectSets+" perfect sets out of 100000.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement