forked from CS32431718SEM1-GP03/Tetris-Agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainer.java
68 lines (56 loc) · 2.95 KB
/
Trainer.java
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
/**
* Created by hyma on 26/3/18.
*/
public class Trainer {
public static final double STARTING_NEGATIVE = -50;
public static final double STARTING_POSITIVE = 50;
public static final double INCREMENT_VALUE = 5;
private static int index = 0;
public static final int INDEX_NUMHOLES = index++;
public static final int INDEX_HEIGHT_DIFF = index++;
public static final int INDEX_MAX_HEIGHT = index++;
public static final int INDEX_ROWS_CLEARED = index++;
public static final int INDEX_LOST = index++;
static int mostRowsCleared = 0;
static double[] bestConfiguration = {
-30, -2, -3, -4, -100000000
};
private static int getRowsClearedFromSimulation() {
PlayerSkeleton player = new PlayerSkeleton();
return player.run();
}
// Within one configuration of weights
protected static int simulateConfiguration(double numHolesWeight, double heightDiffWeight, double maxHeightWeight,
double rowsClearedWeight) {
// System.out.print("[" + numHolesWeight + ", " + heightDiffWeight + ", " + maxHeightWeight + ", " + rowsClearedWeight + "]");
int currentRowsCleared = getRowsClearedFromSimulation();
System.out.println("Rows cleared = " + currentRowsCleared);
if (currentRowsCleared > mostRowsCleared) {
mostRowsCleared = currentRowsCleared;
bestConfiguration[INDEX_NUMHOLES] = numHolesWeight;
bestConfiguration[INDEX_HEIGHT_DIFF] = heightDiffWeight;
bestConfiguration[INDEX_MAX_HEIGHT] = maxHeightWeight;
bestConfiguration[INDEX_ROWS_CLEARED] = rowsClearedWeight;
bestConfiguration[INDEX_LOST] = -100000000;
}
return currentRowsCleared;
}
public static void main(String[] args) {
System.out.println("Starting Trainer class. Format is: ");
System.out.println("[numHolesWeight, heightDiffWeight, maxHeightWeight, rowsClearedWeight]");
System.out.println("---------------------------");
// simulateConfiguration(-75,-100,-50,100);
// loops to modify weights
/* for (double numHolesWeight = STARTING_NEGATIVE; numHolesWeight <= 0; numHolesWeight += INCREMENT_VALUE) {
for (double heightDiffWeight = STARTING_NEGATIVE; heightDiffWeight <= 0; heightDiffWeight += INCREMENT_VALUE) {
for (double maxHeightWeight = STARTING_NEGATIVE; maxHeightWeight <= 0; maxHeightWeight += INCREMENT_VALUE) {
for (double rowsClearedWeight = STARTING_POSITIVE; rowsClearedWeight >= 0; rowsClearedWeight -= INCREMENT_VALUE) {
simulateConfiguration(numHolesWeight, heightDiffWeight, maxHeightWeight, rowsClearedWeight);
}
}
}
}*/
System.out.println("---------------------------");
System.out.println("Best configuration was " + bestConfiguration + " which cleared " + mostRowsCleared + ".");
}
}