-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLion.java
53 lines (45 loc) · 1.05 KB
/
Lion.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
import java.awt.*;
import java.util.Random;
public class Lion extends Critter{
public Lion() { }
Random random = new Random();
private int r = random.nextInt(3);
private int saver = r;
public Color getColor() {
if(r == 0)
return Color.RED;
else if(r == 1)
return Color.GREEN;
else if(r == 2)
return Color.BLUE;
return null;
}
@Override
public String toString()
{
return "L";
}
private int count = 0;
@Override
public Action getMove(CritterInfo info) {
count++;
if (count > 2)
{
count = 0;
r = random.nextInt(3);
while(r == saver)
{
r = random.nextInt(3);
}
saver = r;
}
if(info.getFront() == Neighbor.OTHER)
return Action.INFECT;
if(info.getFront() == Neighbor.WALL || info.getRight() == Neighbor.WALL)
return Action.LEFT;
else if (info.getFront() == Neighbor.SAME)
return Action.RIGHT;
else
return Action.HOP;
}
}