Commits

Anonymous committed c0e888b Draft

Minor formatting changes.
Add printout of robot movement commands.

  • Participants
  • Parent commits 5df0210

Comments (0)

Files changed (2)

     return 0;
   }
   std::ifstream stream(argv[1]);
+  std::cout << "Navigation (press Enter after each character:" << std::endl
+    << "\tLeft:  " << CMD_LEFT  << std::endl
+    << "\tRight: " << CMD_RIGHT << std::endl
+    << "\tUp:    " << CMD_UP    << std::endl
+    << "\tDown:  " << CMD_DOWN  << std::endl;
+  
   Map map = readMap(stream);
   while (true){
     printMap(map, std::cout);
 }
 
 namespace{
-  bool isValidPoint(const Map& map, const Point& p){
-    return (p.first >= 0 /*unsigned, but in case we move to signed*/ && p.first < map.cols()
-	    && p.second >= 0 && p.second < map.rows());
+  bool isValidPoint(const Map& map, const Point& p) {
+    bool result = p.first >= 0 /* unsigned, but in case we move to signed */
+      && p.first < map.cols()
+      && p.second >= 0
+      && p.second < map.rows();
+    return result;
   }
   bool canGoTo(const Map& map, const Point& p){
     if (isValidPoint(map, p)){
       // Rules: 2.2
       char inThere = map.get(p);
       // direct move
-      if (inThere == C_EMPTY || inThere == C_EARTH || inThere == C_LAMBDA || inThere == C_OPEN_LIFT){
+      if (inThere == C_EMPTY || inThere == C_EARTH
+        || inThere == C_LAMBDA || inThere == C_OPEN_LIFT)
+      {
 	return true;
       }
       // move the rock! do this ONLY if going left/right
 	// 2.3.1
 	newMap.get(col, row) = C_EMPTY;
 	newMap.get(col, row - 1) = C_ROCK;
-      } else if (in_there == C_ROCK && safeGet(col, row - 1) == C_ROCK && safeGet(col + 1, row) == C_EMPTY && safeGet(col + 1, row - 1) == C_EMPTY){
+      } else if (in_there == C_ROCK 
+          && safeGet(col, row - 1) == C_ROCK
+          && safeGet(col + 1, row) == C_EMPTY
+          && safeGet(col + 1, row - 1) == C_EMPTY)
+      {
 	// 2.3.2
 	newMap.get(col, row) = C_EMPTY;
 	newMap.get(col + 1, row - 1) = C_ROCK;
       } else if (in_there == C_ROCK 
 		 && safeGet(col, row - 1) == C_ROCK 
 		 && (
-		     (safeGet(col + 1, row) != C_EMPTY && safeGet(col + 1, row) != C_INVALID) ||
+		     (safeGet(col + 1, row) != C_EMPTY && safeGet(col + 1, row) != C_INVALID)
+                     ||
 		     (safeGet(col + 1, row - 1) != C_EMPTY && safeGet(col + 1, row - 1) != C_INVALID)
 		     )
 		 && safeGet(col - 1, row) == C_EMPTY