public void exploreWithDFS() { this.stack = new Stack(); DFSNode currentNode = StartDFSNode; this.DFSNodes.Add(currentNode); try { while (!this._shouldStop) { while (stack.Count > 0 || currentNode != null) { if (CurrentCoverage >= UserSetting.CoverageLimit && UserSetting.CoverageLimit != 100) { Console.WriteLine("Coverage limit reached!"); OnSendingMessage("Coverage limit reached!!!"); this._shouldStop = true; break; } if (currentNode != null) { Console.WriteLine("Visiting node X = {0}, Y = {1}", currentNode.X, currentNode.Y); currentNode.isVisited = true; this.X = currentNode.X; this.Y = currentNode.Y; computeCoverage(); if (currentNode.Equals(this.GoalDFSNode)) { Console.WriteLine("Reach goal!"); OnSendingMessage("Reached goal zone!!!"); //OnSendingMessage("X = " + GoalDFSNode.X); //OnSendingMessage("Y = " + GoalDFSNode.Y); } getDFSChildren(currentNode); if (currentNode.BottomChild != null) { stack.Push(currentNode.BottomChild); this.DFSNodes.Add(currentNode.BottomChild); } if (currentNode.LeftChild != null) { stack.Push(currentNode.LeftChild); this.DFSNodes.Add(currentNode.LeftChild); } if (currentNode.TopChild != null) { stack.Push(currentNode.TopChild); this.DFSNodes.Add(currentNode.TopChild); } if (currentNode.RightChild != null) { stack.Push(currentNode.RightChild); this.DFSNodes.Add(currentNode.RightChild); } while (currentNode.allChildrenVisited()) { Console.WriteLine("No more children, backtracking!!!"); //no more children, backtracking currentNode = currentNode.ParentNode; Thread.Sleep(1000 / UserSetting.Speed); this.X = currentNode.X; this.Y = currentNode.Y; if (currentNode == StartDFSNode) { break; } } //printStack(); if (stack.Count > 0) { currentNode = (DFSNode)stack.Pop(); } else { break; } } else { if (stack.Count > 0) { currentNode = (DFSNode)stack.Pop(); } else { break; } } Thread.Sleep(1000 / UserSetting.Speed); } this.isExplored = true; Console.WriteLine("Exploration finished!!!"); OnSendingMessage("Exploration finished!!!"); } } catch (Exception e) { Console.WriteLine(e); } }