-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotPerformanceEval.java
More file actions
104 lines (87 loc) · 4.64 KB
/
Copy pathBotPerformanceEval.java
File metadata and controls
104 lines (87 loc) · 4.64 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
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
public class BotPerformanceEval {
private static final int GRID_SIZE = 25;
private static final int SIMULATIONS_PER_Q = 40;
private static final BigDecimal Q_STEP = BigDecimal.valueOf(0.1);
//Run a single simulation for a given q value(flamability), Takes in a bot class, where a new instance is created each time
public static boolean runSingleSimulation(double q, Class<? extends FireEscapeBot> botClass) {
try {
Grid grid = new Grid(GRID_SIZE, GRID_SIZE);
Fire fire = new Fire(grid);
FireEscapeBot bot;
Constructor<? extends FireEscapeBot> constructor = botClass.getConstructor(Grid.class, Fire.class);
bot = constructor.newInstance(grid, fire);
bot.move_bot(q);
return grid.getBotCell().equals(grid.getButtonCell()) && !grid.getBotCell().hasFire();
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
}
//Runs simulations for a given flamability value
public static double runSimulationsForQ(double q, Class<? extends FireEscapeBot> botClass) {
int successCount = 0;
for (int i = 0; i < SIMULATIONS_PER_Q; i++) {
if (runSingleSimulation(q, botClass)) {
successCount++;
}
}
return (double) successCount / SIMULATIONS_PER_Q;
}
public static void main(String[] args) {
List<BigDecimal> qValues = new ArrayList<>();
List<Double> successRates = new ArrayList<>();
Bot1 bot1 = new Bot1(new Grid(GRID_SIZE, GRID_SIZE), new Fire(new Grid(GRID_SIZE, GRID_SIZE)));
//Runs simulation for given q values
for (BigDecimal q = BigDecimal.ZERO; q.compareTo(new BigDecimal("0.9")) < 0; q = q.add(Q_STEP)) {
qValues.add(q);
double successRate = runSimulationsForQ(q.doubleValue(), bot1.getClass());
successRates.add(successRate);
System.out.printf("Q: %.2f, Success Rate: %.4f%n", q, successRate);
}
System.out.println("********");
System.out.println("Q values: " + qValues);
System.out.println("Success rates: " + successRates);
// List<BigDecimal> qValues = new ArrayList<>();
// List<Double> successRates = new ArrayList<>();
// Bot2 bot2 = new Bot2(new Grid(GRID_SIZE, GRID_SIZE), new Fire(new Grid(GRID_SIZE, GRID_SIZE)));
// //Runs simulation for given q values
// for (BigDecimal q = BigDecimal.ZERO; q.compareTo(new BigDecimal("0.9")) < 0; q = q.add(Q_STEP)) {
// qValues.add(q);
// double successRate = runSimulationsForQ(q.doubleValue(), bot2.getClass());
// successRates.add(successRate);
// System.out.printf("Q: %.2f, Success Rate: %.4f%n", q, successRate);
// }
// System.out.println("Q values: " + qValues);
// System.out.println("Success rates: " + successRates);
// List<BigDecimal> qValues = new ArrayList<>();
// List<Double> successRates = new ArrayList<>();
// Bot3 bot3 = new Bot3(new Grid(GRID_SIZE, GRID_SIZE), new Fire(new Grid(GRID_SIZE, GRID_SIZE)));
// //Runs simulation for given q values
// for (BigDecimal q = BigDecimal.ZERO; q.compareTo(new BigDecimal("0.9")) < 0; q = q.add(Q_STEP)) {
// qValues.add(q);
// double successRate = runSimulationsForQ(q.doubleValue(), bot3.getClass());
// successRates.add(successRate);
// System.out.printf("Q: %.2f, Success Rate: %.4f%n", q, successRate);
// }
// System.out.println("Q values: " + qValues);
// System.out.println("Success rates: " + successRates);
// List<BigDecimal> qValues = new ArrayList<>();
// List<Double> successRates = new ArrayList<>();
// Bot4 bot4 = new Bot4(new Grid(GRID_SIZE, GRID_SIZE), new Fire(new Grid(GRID_SIZE, GRID_SIZE)));
// //Runs simulation for given q values
// for (BigDecimal q = BigDecimal.ZERO; q.compareTo(new BigDecimal("0.9")) < 0; q = q.add(Q_STEP)) {
// qValues.add(q);
// double successRate = runSimulationsForQ(q.doubleValue(), bot4.getClass());
// successRates.add(successRate);
// System.out.printf("Q: %.2f, Success Rate: %.4f%n", q, successRate);
// }
// System.out.println("Q values: " + qValues);
// System.out.println("Success rates: " + successRates);
}
}