Пример #1
0
 private int tickExplore() {
   Situation s = this.getSituation();
   if (s.getExitCount() > 2) {
     this.addToGraph(new JunctionNode(this.robot));
   }
   switch (s) {
     case CORRIDOR:
       int dir = this.corridor();
       if (dir != IRobot.AHEAD) { // Corner
         // Don't really want to do this but it massively simplifies
         // NavigatorController
         this.addToGraph(new Node(this.robot.getLocation()));
       }
       return dir;
     case CROSSROAD:
       return this.crossroads();
     case DEAD_END:
       if (!this.firstRun) {
         this.isBacktracking = true;
       }
       return this.deadEnd();
     case JUNCTION:
       return this.junction();
     default:
       return 0;
   }
 }
Пример #2
0
 protected final Situation getSituation() {
   int count = 0;
   for (int i = IRobot.AHEAD; i <= IRobot.LEFT; i++) {
     if (this.robot.look(i) != IRobot.WALL) {
       count++;
     }
   }
   for (Situation s : Situation.values()) {
     if (s.getExitCount() == count) {
       return s;
     }
   }
   throw new IllegalStateException("Cannot handle number of exits: " + count);
 }