-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayground.java
More file actions
56 lines (46 loc) · 2.1 KB
/
Playground.java
File metadata and controls
56 lines (46 loc) · 2.1 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
class Playground {
public static void main(String[] args) {
double bestScore = 0;
boolean opt = false;
boolean[] ab = new boolean[]{true, false};
for (boolean test : ab) {
int trials = 10_000;
int totalSteps = 0;
int maxSteps = Integer.MIN_VALUE;
int successCount = 0;
for (int i = 0; i < trials; i++) {
TreasureHunt game = new TreasureHunt();
CordsGen.ab = test;
TreasureHunt.TrialResult result = StudentAgent.run(game);
if (result.foundGoal) {
totalSteps += result.steps;
successCount++;
if (result.steps > maxSteps)
maxSteps = result.steps;
}
if (i % 100 == 0)
System.out.print(
"Trial " + i +
": " + (result.foundGoal ? "X" : "O") +
", S=" + result.steps +
"<" + maxSteps +
" ~: " + ((int) (((double) successCount / i) * 100_000.0d / totalSteps * i)) +
" \r"
);
}
double successRate = (double) successCount / trials;
System.out.println("Max Steps: " + maxSteps + " ");
System.out.println("Successes: " + successCount + "/" + trials + " (" + ((int) (successRate * 100)) + "%)");
System.out.println("Average steps: " + (successCount > 0 ? ((double) totalSteps / successCount) : "N/A"));
double avgSteps = (successCount > 0) ? ((double) totalSteps / successCount) : Double.MAX_VALUE;
double score = (successRate * 100_000.0) / (avgSteps + 1);
System.out.printf("Score: %.3f!\n\n", score);
if (score > bestScore) {
bestScore = score;
opt = test;
}
}
System.out.println("\nBest score: " + bestScore);
System.out.println("Best option: " + opt);
}
}