Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import uk.ac.warwick.dcs.maze.logic.IRobot;
- import java.util.*;
- public class GrandFinaleShort {
- private List<Integer> headings;
- private int pollRun = 0;
- public void controlRobot(IRobot robot) {
- if (robot.getRuns() == 0) {
- if (pollRun == 0) headings = new ArrayList<Integer>();
- List<Integer> pExits = new ArrayList<Integer>();
- for (int i = IRobot.AHEAD; i <= IRobot.LEFT; i++)
- if (robot.look(i) == IRobot.PASSAGE) pExits.add(i);
- if (pExits.size() != 0) {
- robot.face(pExits.get((int)(Math.random() * pExits.size())));
- System.out.println(robot.getHeading());
- headings.add(robot.getHeading());
- }
- else {
- if ((headings.get(headings.size() - 1) + 2 <= IRobot.WEST) && (headings.get(headings.size() - 1) + 2 >= IRobot.NORTH)) robot.setHeading(headings.get(headings.size() - 1) + 2);
- else robot.setHeading(headings.get(headings.size() - 1) - 2);
- headings.remove(headings.size() - 1);
- }
- }
- else robot.setHeading(headings.get(pollRun));
- pollRun++;
- }
- public void reset() {
- pollRun = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement