-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCritter.java
58 lines (45 loc) · 1.1 KB
/
MyCritter.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
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
public class MyCritter extends Critter {
private static Map<String, Map<Attack, Integer>> losses = new HashMap<>();
private String lastOpponent;
private Attack lastAttack;
public boolean eat() {
String n = getNeighbor(Direction.NORTH);
if (n.equals(" ")) {
return true;
}
return false;
}
public Attack fight(String opponent) {
lastOpponent = opponent;
Attack a = Attack.FORFEIT;
lastAttack = a;
return a;
}
public Color getColor() {
return Color.BLACK;
}
public Direction getMove() {
return Direction.NORTH;
}
public String toString() {
return "?";
}
public void lose() {
if (!losses.containsKey(lastOpponent)) {
losses.put(lastOpponent, new HashMap<>());
}
Attack opponentAttack = null;
if (lastAttack == Attack.POUNCE) {
opponentAttack = Attack.SCRATCH;
}
Map<Attack, Integer> counts = losses.get(lastOpponent);
if (!counts.containsKey(opponentAttack)) {
counts.put(opponentAttack, 1);
} else {
counts.put(opponentAttack, counts.get(opponentAttack) + 1);
}
}
}