-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvgCompletionCalculator.java
More file actions
91 lines (83 loc) · 2.55 KB
/
Copy pathAvgCompletionCalculator.java
File metadata and controls
91 lines (83 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.*;
class AvgCompletionCalculator {
int wantedCompletions;
int killCount = 0;
ArrayList<Integer> drops = new ArrayList<Integer>();
ArrayList<Integer> dropCompletions = new ArrayList<Integer>();
Random rand = new Random(System.nanoTime());
AvgCompletionCalculator(int wantedCompletions) {
this.wantedCompletions = wantedCompletions;
}
public void addDrop(int droprate) {
drops.add(droprate - 1);
dropCompletions.add(0);
}
public boolean isComplete() {
for (int i: dropCompletions) {
if (i < wantedCompletions) {
return false;
}
}
return true;
}
public void completeBoss() {
while (!isComplete()) {
killCount ++;
for (int i = 0; i < drops.size(); i++) {
int roll = rand.nextInt(drops.get(i) + 1);
if (roll == drops.get(i)) {
dropCompletions.set(i, dropCompletions.get(i) + 1);
i = drops.size() + 1;
}
}
}
}
public static void main(String[] args) {
int completions;
int runs = 100000;
try {
runs = Integer.parseInt(args[0]);
} catch (Exception ignored) {
}
ArrayList<Integer> droprates = new ArrayList<Integer>();
Scanner in = new Scanner(System.in);
int input = -1;
while (input != 0) {
System.out.println("Input droprate of wanted item.");
System.out.print("Stop by inputting '0': ");
try {
input = Integer.parseInt(in.nextLine());
} catch (Exception e) {
System.out.println("");
System.out.println("Please input a positive integer or 0..");
return;
}
if (input != 0) {
droprates.add(input);
}
}
System.out.println();
System.out.print("Input how many completions you want: ");
completions = Integer.parseInt(in.nextLine());
ArrayList<Integer> completionTime = new ArrayList<Integer>();
AvgCompletionCalculator ac;
for (int i = 0; i < runs; i++) {
ac = new AvgCompletionCalculator(completions);
for (int x: droprates) {
ac.addDrop(x);
}
ac.completeBoss();
completionTime.add(ac.killCount);
}
Collections.sort(completionTime);
long totalKills = 0;
for (int i = 0; i < runs; i++) {
totalKills += completionTime.get(i);
}
double average = (double) totalKills / (double) runs;
System.out.println("Average: " + average);
System.out.println("Median: " + completionTime.get((int)(runs / 2)));
System.out.println("Best: " + completionTime.get(0));
System.out.println("Worst: " + completionTime.get(runs - 1));
}
}