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

Issue 29 improve worst case AI move time by 150x. #36

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

j-richey
Copy link
Owner

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.

times-optimized

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.

Before staring to work on issue #29, improving the AI move time, a
regression test for issue #26, rando consistently winning over flawless
AI is added. This ensures the performance changes do not break the AI
logic.
This commit greatly improves the worst case game evaluation time. This
was accomplished by reducing the number of nodes on the evaluation tree
the AI has to examine.

First, for a new game we know the outcome will always be a cat's game so
there is no need to do any evaluation.

Second, once a branch in the tree has lead to the worst possible outcome
there is no need to look at other children of the node in question.

Together, these changes improve the worst case evaluation time by about 150x.

See issue #29.
@j-richey j-richey merged commit e97a4e9 into master Jun 15, 2020
@j-richey j-richey deleted the issue-29-improve-ai-move-time branch June 15, 2020 02:25
@j-richey j-richey mentioned this pull request Jun 15, 2020
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