Skip to content
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 BFS class for GameMap.getDistance(). #11914

Merged
merged 2 commits into from
Aug 27, 2023

Conversation

asvitkine
Copy link
Contributor

Change Summary & Additional Notes

No functional changes.

The new implementation is a lot faster than the previous recursive one, which had a lot of overhead from creating a ton of temporary collections and doing a lot of recursive calls.
For a given game with FastAI, I observed ProTerritoryValueUtils.findTerritoryValues() (which spends a lot of time calling getDistance()) going from taking ~15% of the CPU to ~9%.

I tested that this is outputting the same results as the old implementation by having the engine run both and compare the values and ran several full rounds of all-AI games on different maps.

This PR also enhances the API of BreadthFirstSearch by supporting a BiPredicate condition and adds a helper visitor impl for finding a territory and returning its distance. Also, fixes an off-by-1 bug in the class for distance (and updates the one existing caller that was using the previous distance value).

Includes tests.

Release Note

@asvitkine asvitkine merged commit e822cae into triplea-game:master Aug 27, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant