Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool DFS (currentState) =
- {
- if (myHashSet.Contains(currentState))
- {
- return;
- }
- else
- {
- myHashSet.Add(currentState);
- }
- if (IsSolution(currentState) return true;
- else
- {
- for (var nextState in GetNextStates(currentState))
- if (DFS(nextState)) return true;
- }
- return false;
- }
- bool DFS (currentState, maxDepth) =
- {
- if (maxDepth = 0) return false;
- if (myHashSet.Contains(currentState))
- {
- return;
- }
- else
- {
- myHashSet.Add(currentState);
- }
- if (IsSolution(currentState) return true;
- else
- {
- for (var nextState in GetNextStates(currentState))
- if (DFS(nextState, maxDepth - 1)) return true;
- }
- return false;
- }
- A - B - C - D - E - A
- |
- F - G (Goal)
- bool DFS (currentState, maxDepth) =
- {
- if (maxDepth = 0) return false;
- if (myHashSet.Contains(currentState))
- {
- return;
- }
- else
- {
- myHashSet.Add(currentState);
- }
- if (IsSolution(currentState) return true;
- else
- {
- for (var nextState in GetNextStates(currentState))
- if (DFS(nextState, maxDepth - 1)) return true;
- }
- myHashSet.Remove(currentState); //the state is pop out from the stack
- return false;
- }
Add Comment
Please, Sign In to add comment