Skip already-visited tiles during radius calculation (approx. 5% fewer tiles) #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have found the shortest path to a given tile when it is dequeued from the priority queue for the first time. There is no shorter path because all other tiles in the priority queue have the same or greater cost from the starting tile (Djikstra).
To keep the implementation simple, this commit uses the existing
closed
array to mark tiles that have been visited. We can also remove the check forcurrentVector.equals(start)
because the tile forstart
will already have been put intoclosed
.The tests pass. The number of visited tiles is slightly lower in one of the Radius test cases (added logging to measure this).
The random MapGenerator test perhaps shows a more representative impact. I ran it one time before and after this commit, and looked at the average number of tiles visited in
calculateRadius
during each run: before = 395, after = 372. Of course, there is randomness and it shows we can expect about 5% savings in tiles visited.