Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class tft {
- private ArrayList<String> one_cost_pool;
- private HashMap<String, Integer> bought;
- private HashMap<String, Integer> totalBought;
- private HashMap<Integer, String> names;
- private ArrayList<HashMap<String, Integer>> trials;
- private int cait_pool = 29, fiora_pool = 29, xayah_pool = 20, jarvan_pool = 29, graves_pool = 29, khazix_pool = 29,
- leona_pool = 29, malphite_pool = 29, poppy_pool = 29, tf_pool = 29, ziggs_pool = 29, zoe_pool = 29;
- private int[] starting_pool = new int[] { cait_pool, fiora_pool, xayah_pool, jarvan_pool, graves_pool, khazix_pool,
- leona_pool, malphite_pool, poppy_pool, tf_pool, ziggs_pool, zoe_pool };
- private ArrayList<String> lookingFor = new ArrayList<String>(Arrays.asList("cait", "xayah", "fiora", "jarvan"));
- private int startingGold = 50, gold, numTrials = 5000, naturalGold = 37;
- public static void main(String[] args) {
- tft test = new tft();
- }
- public tft() {
- names = new HashMap<Integer, String>();
- names.put(0, "cait");
- names.put(1, "fiora");
- names.put(2, "xayah");
- names.put(3, "jarvan");
- names.put(4, "graves");
- names.put(5, "khazix");
- names.put(6, "leona");
- names.put(7, "malphite");
- names.put(8, "poppy");
- names.put(9, "tf");
- names.put(10, "ziggs");
- names.put(11, "zoe");
- for (int i = 0; i < 3; i++) {
- totalBought = new HashMap<String, Integer>();
- for (String str : lookingFor)
- totalBought.put(str, 0);
- trials = new ArrayList<HashMap<String, Integer>>();
- for (int j = 0; j < numTrials; j++)
- doTrial(i);
- printBought();
- System.out.println();
- }
- }
- // strategies: 1. hyperoll, 2. slowroll, 3. contested slowroll
- public void doTrial(int strategy) {
- one_cost_pool = new ArrayList<String>();
- for (int i = 0; i < starting_pool.length; i++)
- for (int j = 0; j < starting_pool[i]; j++)
- one_cost_pool.add(names.get(i));
- bought = new HashMap<String, Integer>();
- gold = startingGold;
- if (strategy == 0)
- hyperRoll();
- else if (strategy == 1)
- slowRoll();
- else if (strategy == 2) {
- slowRoll();
- }
- // update totals
- for (String str : lookingFor)
- if (bought.containsKey(str))
- totalBought.put(str, totalBought.get(str) + bought.get(str));
- trials.add(bought);
- }
- public void hyperRoll() {
- while (gold >= 22)
- roll(4);
- gold += naturalGold + 15;
- while (gold >=3)
- roll(5);
- }
- public void slowRoll() {
- gold += 25;
- while (gold >= 50)
- roll(4);
- gold += naturalGold;
- while (gold >= 3)
- roll(5);
- }
- public void roll(int level) {
- for (int i = 0; i < 5; i++) {
- double rand = Math.random();
- if ((level == 4 && rand > 0.4) || (level == 5 && rand > 0.6)) {
- // pick random unit out of the pool
- String unit = one_cost_pool.remove((int) (Math.random() * one_cost_pool.size()));
- // you are looking for unit, and you have less than 9 of that unit
- if (lookingFor.contains(unit) && (!bought.containsKey(unit) || bought.get(unit) < 9)) {
- if (bought.containsKey(unit))
- bought.put(unit, bought.get(unit) + 1);
- else bought.put(unit, 1);
- gold--;
- } else
- // put it back if its not what we're looking for
- one_cost_pool.add(unit);
- }
- }
- gold -= 2;
- }
- public void printBought() {
- for (String name : lookingFor)
- System.out.println(name + ": {" + (totalBought.get(name) / ((double) numTrials)) + "} " + "standard dev: {" + getStandardDeviation(name) + "}");
- }
- public double getStandardDeviation(String name) {
- double totalNum = 0;
- double totalDeviation = 0;
- // calculating average
- for (HashMap<String, Integer> trial : trials)
- if (trial.containsKey(name))
- totalNum += trial.get(name);
- double average = totalNum / numTrials;
- // calculating deviation
- for (HashMap<String, Integer> trial : trials)
- if (trial.containsKey(name))
- totalDeviation += Math.pow(trial.get(name) - average, 2);
- return Math.sqrt(totalDeviation / numTrials);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment