Issue 29 improve worst case AI move time by 150x. #36
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.
Pull request for issue #29 that improves the worst case AI move time by 150x. This was accomplished by reducing the number of nodes that needed to be evaluated to determine the outcome of a game from over 600,000 to less than 9,000. See callgrind-optimized.pdf for the callgrind output from these changes.
Two techniques were used to accomplish the performance improvement.
First, we know the outcomes for all positions in a new games are always cat's games. The code was updated to detect a new game and returned the cached result.
Second, while evaluating a branch, if the worst outcome is found there is no need to continue evaluating other child nodes. Instead, the worst outcome is propagated up the tree.
The graph below shows how each of the above changes changed the benchmarks both individally and combined.
Note: the benchmarks were run on a AMD Ryzen 7 2700x. As shown, both the required worst cast time of 100ms and the desired worst case time of 10ms are far exceeded by the changes in this pull request.