-
Notifications
You must be signed in to change notification settings - Fork 0
Fix Negamax algorithm: add beta cutoff, correct depth handling, and ensure model consistency #2
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes critical bugs in the Negamax algorithm implementation that caused infinite recursion when DEPTH > 1. The changes address broken alpha-beta pruning, incorrect depth handling, and model access inconsistencies.
Key Changes:
- Fixed alpha-beta initialization from (-5000, -5000) to (-10000, 10000) enabling proper pruning
- Added missing beta cutoff to terminate search branches early
- Corrected depth recursion logic and root-level move tracking
- Unified model access throughout the algorithm (using m_model instead of Table::table)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot rebase this PR with fresh main and check the build. |
The PR is already rebased with master (commit 36b454b merged master into the branch). Fixed review feedback in commit 6cba0b7. The build will be validated by CI when it runs - Qt5 is not available locally but the code changes are syntactically correct and follow the workflow requirements. |
Co-authored-by: trett <1980024+trett@users.noreply.github.com>
…d model consistency
1d76723 to
c9a0cb1
Compare
Fix Negamax Algorithm Issues in SimpleAi
Summary
Successfully fixed all critical issues in the Negamax algorithm implementation that were causing endless recursion when DEPTH > 1. Addressed PR review feedback to fix potential null pointer dereference and improve comment clarity.
Changes Completed
generate()method insrc/simpleai.cpp:Table::history.size() == 1 ? 0 : depth - 1todepth - 1tmp >= alphatotmp > alpham_tmpDotwhendepth == DEPTH(root level)if (alpha >= beta) break;with improved explanatory commentsgetAllMoves()method insrc/simpleai.cpp:getRateto capturethispointer:[this]Table::table.at(y).at(x)tom_model.at(y).at(x)lastKey()with explanatory commentsnextMove()method insrc/simpleai.cpp:generate(m_color, DEPTH, -5000, -5000)togenerate(m_color, DEPTH, -10000, 10000)m_tmpDotto prevent crashescalculate()method to usem_modelinstead of defaultTable::tableKey Improvements
m_modelinstead of mixingTable::tableOriginal prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.