-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dead.java
38 lines (35 loc) · 1.36 KB
/
Dead.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
package zombie;
import static zombie.Constants.*;
import static java.lang.Math.*;
import java.util.concurrent.ThreadLocalRandom;
public enum Dead implements Player {
DEADBODY {
@Override
public Action doTurn(PlayerContext context) {
return Move.STAY;
}
},
ZOMBIE {
@Override
public Action doTurn(PlayerContext context) {
// Find nearest non-zombie player
Move bestDirection = Move.randomMove();
int bestDistance = Integer.MAX_VALUE;
for (int x = 0; x < VISION_WIDTH; x++) {
for (int y = 0; y < VISION_WIDTH; y++) {
int distance = max(abs(x - CENTRE_OF_VISION), abs(y - CENTRE_OF_VISION));
PlayerId playerAtLocation = context.getPlayField()[x][y];
if (playerAtLocation != null
&& !PlayerRegistry.isDeadOrUndead(playerAtLocation.getName())
&& distance < bestDistance) {
bestDistance = distance;
bestDirection = Move.inDirection(x - CENTRE_OF_VISION, y - CENTRE_OF_VISION);
}
}
}
return bestDirection;
}
};
public static final String DEADBODYNAME = "DeadBody";
public static final String ZOMBIENAME = "Zombie";
}