浏览代码

Fix DFS non stoping when target is reach

DricomDragon 5 年之前
父节点
当前提交
ffb2c0f871
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      main.cc

+ 4 - 1
main.cc

@@ -153,7 +153,7 @@ class World
 		// starting from tile number s0, 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 &)
-		bool dfs(unsigned int s0, unsigned int t, list<unsigned int>& path)
+		bool dfs(unsigned int s0, unsigned int target, list<unsigned int>& path)
 		{
 			bool r = false;
 
@@ -191,6 +191,9 @@ class World
 				// Current tile is now processed
 				explored[current] = true;
 
+				// Stop if target found
+				r = (current == target);
+
 
 			} while (!r && !open.empty());