فهرست منبع

Make variables of DFS more meaningful

DricomDragon 5 سال پیش
والد
کامیت
3c8530b2d1
1فایلهای تغییر یافته به همراه10 افزوده شده و 10 حذف شده
  1. 10 10
      main.cc

+ 10 - 10
main.cc

@@ -150,12 +150,12 @@ class World
 
 
 		// Depth-first search
-		// starting from tile number s0, find a path to tile number t
+		// starting from tile number origin, find a path to tile number t
 		// return true if such a path exists, false otherwise
 		// if it exists the path is given in variable path (hence the reference &)
-		const bool dfs(unsigned int s0, unsigned int target, list<unsigned int>& path, list<unsigned int>& discovered)
+		const bool dfs(unsigned int origin, unsigned int target, list<unsigned int>& path, list<unsigned int>& discovered)
 		{
-			bool r = false;
+			bool targetIsReached = false;
 
 			bool explored[size];
 			unsigned int previous[size];
@@ -165,11 +165,11 @@ class World
 				previous[k] = k;
 			}
 
-			explored[s0] = true;
+			explored[origin] = true;
 
 
 			stack<unsigned int> open;
-			open.push(s0);
+			open.push(origin);
 
 			int current;
 			int neighbour;
@@ -197,19 +197,19 @@ class World
 				discovered.push_back(current);
 
 				// Stop if target found
-				r = (current == target);
+				targetIsReached = (current == target);
 
-			} while (!r && !open.empty());
+			} while (!targetIsReached && !open.empty());
 
 			// Build path
-			if (r) {
+			if (targetIsReached) {
 				do {
 					path.push_back(current);
 					current = previous[current];
-				} while (current != s0);
+				} while (current != origin);
 			}
 
-			return r;
+			return targetIsReached;
 		} 
 };