Guest User

Untitled

a guest
May 23rd, 2020
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class tft {
  4. private ArrayList<String> one_cost_pool;
  5. private HashMap<String, Integer> bought;
  6. private HashMap<String, Integer> totalBought;
  7. private HashMap<Integer, String> names;
  8. private ArrayList<HashMap<String, Integer>> trials;
  9.  
  10. private int cait_pool = 29, fiora_pool = 29, xayah_pool = 20, jarvan_pool = 29, graves_pool = 29, khazix_pool = 29,
  11. leona_pool = 29, malphite_pool = 29, poppy_pool = 29, tf_pool = 29, ziggs_pool = 29, zoe_pool = 29;
  12. private int[] starting_pool = new int[] { cait_pool, fiora_pool, xayah_pool, jarvan_pool, graves_pool, khazix_pool,
  13. leona_pool, malphite_pool, poppy_pool, tf_pool, ziggs_pool, zoe_pool };
  14.  
  15. private ArrayList<String> lookingFor = new ArrayList<String>(Arrays.asList("cait", "xayah", "fiora", "jarvan"));
  16. private int startingGold = 50, gold, numTrials = 5000, naturalGold = 37;
  17.  
  18. public static void main(String[] args) {
  19. tft test = new tft();
  20. }
  21.  
  22. public tft() {
  23.  
  24. names = new HashMap<Integer, String>();
  25. names.put(0, "cait");
  26. names.put(1, "fiora");
  27. names.put(2, "xayah");
  28. names.put(3, "jarvan");
  29. names.put(4, "graves");
  30. names.put(5, "khazix");
  31. names.put(6, "leona");
  32. names.put(7, "malphite");
  33. names.put(8, "poppy");
  34. names.put(9, "tf");
  35. names.put(10, "ziggs");
  36. names.put(11, "zoe");
  37.  
  38. for (int i = 0; i < 3; i++) {
  39. totalBought = new HashMap<String, Integer>();
  40. for (String str : lookingFor)
  41. totalBought.put(str, 0);
  42. trials = new ArrayList<HashMap<String, Integer>>();
  43. for (int j = 0; j < numTrials; j++)
  44. doTrial(i);
  45. printBought();
  46. System.out.println();
  47. }
  48. }
  49. // strategies: 1. hyperoll, 2. slowroll, 3. contested slowroll
  50. public void doTrial(int strategy) {
  51. one_cost_pool = new ArrayList<String>();
  52. for (int i = 0; i < starting_pool.length; i++)
  53. for (int j = 0; j < starting_pool[i]; j++)
  54. one_cost_pool.add(names.get(i));
  55. bought = new HashMap<String, Integer>();
  56. gold = startingGold;
  57. if (strategy == 0)
  58. hyperRoll();
  59. else if (strategy == 1)
  60. slowRoll();
  61. else if (strategy == 2) {
  62.  
  63. slowRoll();
  64. }
  65. // update totals
  66. for (String str : lookingFor)
  67. if (bought.containsKey(str))
  68. totalBought.put(str, totalBought.get(str) + bought.get(str));
  69. trials.add(bought);
  70. }
  71.  
  72. public void hyperRoll() {
  73. while (gold >= 22)
  74. roll(4);
  75. gold += naturalGold + 15;
  76. while (gold >=3)
  77. roll(5);
  78. }
  79.  
  80. public void slowRoll() {
  81. gold += 25;
  82. while (gold >= 50)
  83. roll(4);
  84. gold += naturalGold;
  85. while (gold >= 3)
  86. roll(5);
  87. }
  88.  
  89. public void roll(int level) {
  90. for (int i = 0; i < 5; i++) {
  91. double rand = Math.random();
  92. if ((level == 4 && rand > 0.4) || (level == 5 && rand > 0.6)) {
  93. // pick random unit out of the pool
  94. String unit = one_cost_pool.remove((int) (Math.random() * one_cost_pool.size()));
  95. // you are looking for unit, and you have less than 9 of that unit
  96. if (lookingFor.contains(unit) && (!bought.containsKey(unit) || bought.get(unit) < 9)) {
  97. if (bought.containsKey(unit))
  98. bought.put(unit, bought.get(unit) + 1);
  99. else bought.put(unit, 1);
  100. gold--;
  101. } else
  102. // put it back if its not what we're looking for
  103. one_cost_pool.add(unit);
  104. }
  105. }
  106. gold -= 2;
  107. }
  108.  
  109. public void printBought() {
  110. for (String name : lookingFor)
  111. System.out.println(name + ": {" + (totalBought.get(name) / ((double) numTrials)) + "} " + "standard dev: {" + getStandardDeviation(name) + "}");
  112. }
  113.  
  114. public double getStandardDeviation(String name) {
  115. double totalNum = 0;
  116. double totalDeviation = 0;
  117. // calculating average
  118. for (HashMap<String, Integer> trial : trials)
  119. if (trial.containsKey(name))
  120. totalNum += trial.get(name);
  121. double average = totalNum / numTrials;
  122. // calculating deviation
  123. for (HashMap<String, Integer> trial : trials)
  124. if (trial.containsKey(name))
  125. totalDeviation += Math.pow(trial.get(name) - average, 2);
  126. return Math.sqrt(totalDeviation / numTrials);
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment