Advertisement
Guest User

MutationSimulation Mk. 2

a guest
Dec 27th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.94 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class MutationSimulation
  4. {
  5.     private int[] perfectSet;
  6.     private int[] pickedMuts;
  7.     private int picks;
  8.     private int levels;
  9.     private int amount;
  10.     private int destiny;
  11.     private int isHorror;
  12.     private Random RNGesus;
  13.  
  14.     public MutationSimulation(int mutations, int horror)
  15.     {
  16.       this.perfectSet = new int[Math.max(6,mutations)];
  17.       this.perfectSet[0] = 1;
  18.       this.perfectSet[1] = 3;
  19.       this.perfectSet[2] = 13;
  20.       this.perfectSet[3] = 22;
  21.       this.perfectSet[4] = 23;
  22.       this.perfectSet[5] = 27;
  23.       if(mutations>=7) this.perfectSet[6] = 11;
  24.       if(mutations>=8) this.perfectSet[7] = 7;
  25.       if(mutations>=9) this.perfectSet[8] = 17;
  26.       this.pickedMuts = new int[20];
  27.       this.picks = 0;
  28.       this.levels = 0; // Needs to be defined separately from the amount of picks, since destiny and rerolls are free extra mutations.
  29.       this.amount = 0;
  30.       this.destiny = 0;
  31.       this.isHorror = horror;
  32.       RNGesus = new Random();
  33.     }
  34.  
  35.     // 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.
  36.     public void getMutation(boolean ultraDestiny)
  37.     {
  38.       int mutPick = 0;
  39.       boolean wish = false;
  40.       boolean patience = false;
  41.       boolean goForDestiny = false;
  42.      
  43.       int[] thisSet = new int[4+this.isHorror]; // Build an array of the mutations in this set
  44.      
  45.       for(int i=0; i<4+this.isHorror; i++)
  46.       {
  47.         boolean picked = false;
  48.         while(!picked)
  49.         {
  50.           int mut = (int) (Math.ceil(Math.random()*28)); // Amount of mutations in the game
  51.           picked = true;
  52.           for(int j=0; j<this.pickedMuts.length; j++)
  53.           {
  54.             for(int h=0; h<thisSet.length; h++)
  55.             if(mut == this.pickedMuts[j] || mut == thisSet[h]) // Check against already chosen mutations this run (and this set)
  56.             {
  57.               picked = false;
  58.             }
  59.           }
  60.           if(picked)
  61.           {
  62.             mutPick = mut;
  63.             thisSet[i] = mut;
  64.             if(mut == 18) wish = true;
  65.             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.
  66.           }
  67.         }
  68.          
  69.         // 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.
  70.         if(ultraDestiny) i = 10;
  71.          
  72.         for(int k=0; k<this.perfectSet.length; k++)
  73.         {
  74.           // If something in the perfect set was found
  75.           if(mutPick == this.perfectSet[k])
  76.           {
  77.             // 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.
  78.             this.pickedMuts[this.picks] = mutPick;
  79.             this.picks++;
  80.             this.levels++;
  81.             this.amount++;
  82.                
  83.             if(goForDestiny)
  84.             {
  85.               // 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.
  86.               this.destiny++;
  87.               this.levels--;
  88.               i = 10;
  89.             }
  90.                
  91.             if(i <= 0+this.isHorror && this.destiny == 0 && (this.levels==4||this.levels==5||this.isHorror>0))
  92.             {
  93.               // 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.
  94.               goForDestiny = true;
  95.             }
  96.             else
  97.             {
  98.               // 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.
  99.               i = 10;
  100.             }
  101.           }
  102.         }
  103.          
  104.         // If nothing in the perfect set was found
  105.         if(i == 3+this.isHorror)
  106.         {
  107.           this.picks++;
  108.           if(wish && !goForDestiny) mutPick = 18;
  109.           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.
  110.           this.pickedMuts[this.picks] = mutPick; // The chosen mutation will be whichever was rolled last, since nothing was good.
  111.           if(mutPick != 18 && mutPick != 25) this.levels++; // If a reroll was chosen, total mutation counter isn't incremented.
  112.         }
  113.       }
  114.     }
  115.  
  116.     // Simulates an entire run worth of mutations.
  117.     public int pickAllMuts()
  118.     {
  119.       // Picks eight regular mutations (i.e. anything except rerolls and destiny).
  120.       while(this.levels<8)
  121.       {
  122.         getMutation(false);
  123.       }
  124.      
  125.       // 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).
  126.       if(this.destiny == 0 && Math.random()<0.7)
  127.       {
  128.         getMutation(true);
  129.       }
  130.      
  131.       return this.amount; // To be compared with the overall target number of perfect mutations in the main function.
  132.     }
  133.  
  134.     public static void main(String[] args)
  135.     {
  136.       int perfectSets = 0;
  137.       for(int i=0; i<100000; i++)
  138.       {
  139. /* User instructions:
  140.    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.
  141.    It can also simulate playing Horror, by editing the second parameter of MutationSimulation. (Also supports multiple Horrors in co-op.)
  142. */
  143.          
  144.         MutationSimulation mutant = new MutationSimulation(7,0);
  145.         int number = mutant.pickAllMuts();
  146.         if(number>=7) perfectSets++;
  147.       }
  148.  
  149.       System.out.print("Got "+perfectSets+" perfect sets out of 100000.");
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement