-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentAgent.java
More file actions
64 lines (55 loc) · 1.98 KB
/
StudentAgent.java
File metadata and controls
64 lines (55 loc) · 1.98 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
public class StudentAgent {
public static int maxSteps = 8000;
private static int steps = 0;
public static TreasureHunt.TrialResult run(TreasureHunt game) {
CordsGen cg = new CordsGen(game);
steps = 0;
TreasureHunt.Collectible cl;
TreasureHunt.TrialResult res = null;
// Find the first hint
cg.firstHint();
// Find hints until we have narrowed the goal
while (
cg.numGoals() > cg.numHints() &&
res == null &&
remSteps() > cg.numGoals()
) {
int[] cur = cg.nextHint();
if (cur == null)
break;
jump(game, cur);
cl = game.search();
if (cl == null)
cg.remCord(cur);
else if (cl.isHint()) {
cg.addHint(cur, (int) cl.getMessage()[0], (int[]) cl.getMessage()[1]);
} else {
res = game.submit();
}
}
// Brute force the goal
while (res == null) {
int[] cur = cg.nextGoal();
if (cur == null) // out of goals
res = game.submit();
else {
jump(game, cur);
cl = game.search();
if (isGoal(cl)) { // is goal
res = game.submit();
} else if (isHint(cl)) { // is hinted
cg.addHint(cur, (int) cl.getMessage()[0], (int[]) cl.getMessage()[1]);
}
}
}
return game.submit();
}
private static boolean nbail() { return steps < maxSteps; }
public static int remSteps() { return maxSteps - steps; }
public static void jump(TreasureHunt game, int[] pos) {
game.jumpTo(pos[0], pos[1], pos[2]);
steps++;
}
public static boolean isGoal(TreasureHunt.Collectible c) { return c != null && !c.isHint(); }
public static boolean isHint(TreasureHunt.Collectible c) { return c != null && c.isHint(); }
}