Advertisement
Raizekas

Untitled

Mar 7th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import uk.ac.warwick.dcs.maze.logic.IRobot;
  2. import java.util.*;
  3. public class GrandFinaleShort {
  4.   private List<Integer> headings;
  5.   private int pollRun = 0;
  6.   public void controlRobot(IRobot robot) {
  7.     if (robot.getRuns() == 0) {
  8.       if (pollRun == 0) headings = new ArrayList<Integer>();
  9.       List<Integer> pExits = new ArrayList<Integer>();
  10.       for (int i = IRobot.AHEAD; i <= IRobot.LEFT; i++)
  11.     if (robot.look(i) == IRobot.PASSAGE)    pExits.add(i); 
  12.       if (pExits.size() != 0) {
  13.     robot.face(pExits.get((int)(Math.random() * pExits.size())));
  14.     System.out.println(robot.getHeading());
  15.     headings.add(robot.getHeading());
  16.       }
  17.       else {
  18.     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);
  19.     else robot.setHeading(headings.get(headings.size() - 1) - 2);
  20.     headings.remove(headings.size() - 1);
  21.       }
  22.     }
  23.     else robot.setHeading(headings.get(pollRun));
  24.     pollRun++;
  25.     }
  26.   public void reset() {
  27.     pollRun = 0;
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement