Try next candidates after blocking exits #42
Merged
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.
Description
Refactoring to keep all candidates, in priority order, rather than just finding the best one and discarding the rest. Enables us to ignore the best one for any reason, and fallback to the next in the list.
getBestCandidate
to besortValidCandidates
, so it keeps the whole list in distance orderMotivation and Context
Currently, we only check the blocked exits once, after we've picked a best candidate. If the best candidate does get blocked, we return null. This means there might be other good candidates that get ignored if the best one is in a blocked direction. So instead, we want to keep all the candidates in a sorted order, and find the first one that's a valid move.
Fixes a bug where the best candidate might be outside a container behind a blocked exit, but there is another second best candidate that should be chosen instead.
i.e. here, UP from 6 should go to 2, but 3 is a better candidate. Previously it tries to go to 3, sees the blocked exit, then stops completely. Now it will discard 3, and try again successfully to move you to 2.
![image](https://private-user-images.githubusercontent.com/7268569/306600614-7571d87c-79f0-4648-ba9d-f19a7138583d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3MjEyODYsIm5iZiI6MTcxODcyMDk4NiwicGF0aCI6Ii83MjY4NTY5LzMwNjYwMDYxNC03NTcxZDg3Yy03OWYwLTQ2NDgtYmE5ZC1mMTlhNzEzODU4M2QucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MThUMTQyOTQ2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmVjNTI3MWNkMjJiNmFiZDdkNmM3MDE0MGE4NDRjZmUwYzE3ZGY4ZmEzNDhiOTdhYWMzZWVmZGVkZWQ1M2VjNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.GwhIp_e19Qc65hgwfv-z6GtM_cBTi9ZV6VEo5oaVTiA)
How Has This Been Tested?
Updated the template file to expose the behaviour, and added an integration test for it
Checklist: