import java.awt.Color; public class Pigeon extends Critter { private String last; public Pigeon() { last = "*"; } public Action getMove(CritterInfo info) { if (info.getFront() == Neighbor.EMPTY) { last = "H"; return Action.HOP; } else { if (Math.random() < 0.5) { last = "L"; return Action.LEFT; } else { last = "R"; return Action.RIGHT; } } } public String toString() { return last; } } public class HighSchooler extends Critter { public static final Action[] MOVES = Action.values(); // There's a question of whether this should track the popular kid's // getMove() return on the last *turn* or most recent value returned // period. The problem description leans toward the latter case (which // is easier to implement anyway). private static Action last; // Technically we don't need a full count here (could use a boolean // to answer the question in the constructor:"Am I the first?"). private static int studentCount; private boolean popular; public HighSchooler() { popular = studentCount == 0; studentCount++; } public Action getMove(CritterInfo info) { if (popular) { last = MOVES[(int) (Math.random() * MOVES.length)]; System.out.println(last); } else if (last == null) { return Action.HOP; } return last; } public Color getColor() { return Color.RED; } public String toString() { return "A"; } } public class Orca extends Critter { private boolean moving; int count; public Orca() { // Begin in 'moving mode'. flipMode(); } public Action getMove(CritterInfo info) { if (count == 0) flipMode(); count--; if (moving) { if (info.getFront() == Neighbor.EMPTY) { return Action.HOP; } else { return Action.INFECT; } } else { // turning mode return Action.LEFT; } } public String toString() { return moving ? "M" : "T"; } private void flipMode() { if (moving) { moving = false; count = 2; } else { moving = true; count = 4; } } }