-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use same depth-first search for generate and solve #3
Conversation
@@ -9,7 +9,7 @@ | |||
:when (not= (.abs js/Math dx) (.abs js/Math dy))] | |||
[(+ x dx) (+ y dy)]))) | |||
|
|||
(defn unvisited-neighbors [location visited size] | |||
(defn unvisited-neighbors [location {:keys [visited size]}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pass the last two as a map but not the first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar question on other fns below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a weird choice and I'm happy to change if we want.
It seems like we are passing around a bag of bits to a lot of functions. These all seem related to the state of the maze. That last argument is that full bag of bits and we're plucking what we want out of it.
The first argument is the location that we are checking against the maze state. It didn't seem right to stick it in the same bag since it's not related to the maze like the others.
Super happy to tidy this up in another PR. It's pretty inconsistent. There are a few untouched functions that are different yet.
Great change overall. Good to 🚢 |
We cannot use recur in solve-maze because the canvas does not get updated between iterations. For consistency, it makes sense to not use recur here either.
This is more clear because we are randomly picking from unvisited-neighbors
This will be nil already if not provided
This will help merge common behavior into a shared function.
merge with the rcall search-mze
random-reachable-neighbor works for both generate-maze and solve-maze so there's no need to use the more general random-unvisited-neighbor for generate-maze.
This is a clearer definition than an empty path.
In every case, we are going to want to start searching from [0 0]. Let's make it the default instead of passing it in everywhere.
This is the only function that mentions a 'grid' and it's confusing. This function really returns all walls for the maze.
The function is only used once and the name isn't very clear. It makes more sense to move this difference into all-walls-without-doors.
Use same depth-first search for generate and solve
Fixes #2✈️ PDX
SJO
generate-maze
andsolve-maze
use an identical depth-first search. This pulls the algorithm intosearch-maze
and lets each specify a different finish condition.In order to see the bits that these two functions had in common, there's also some function renaming.