Example #1
0
 public void handleIntersection() {
   TDir curDir = car.getDirection();
   TileModel curTile = car.currTileOnMap();
   if (curTile.isOpen(curDir.rightTurn())) {
     Log.v("BRAIN", "Turning right");
     car.makeTurn(curDir.rightTurn());
   } else if (curTile.isOpen(curDir)) {
     Log.v("BRAIN", "Continuing through intersection because cant turn right");
     car.driveAlong();
   } else if (curTile.isOpen(curDir.leftTurn())) {
     Log.v("BRAIN", "Turning left because can't go straight or right");
     car.makeTurn(curDir.leftTurn());
   } else {
     Log.v("BRAIN", "Stopping because there's nowhere to go");
     car.comeToStop();
   }
 }
Example #2
0
 /*
  * This is the key algorithm.
  */
 @Override
 public void onTimePassed(TimerHandler pTimerHandler) {
   car.updateRoadmapTile();
   if (!car.isDriving()) return;
   if (car.isTurning()) {
     car.handleTurn2();
   } else if (car.atIntersection()) {
     Log.v("BRAIN", "Passing Intersection at: " + car.toString());
     handleIntersection();
   } else if (car.atDeadEnd()) {
     Log.v("BRAIN", "Dead end going: " + car.getDirection() + ", at:" + car.toString());
     car.comeToStop();
   } else {
     car.driveAlong();
   }
 }