Fix/magic numbers duplication - #18
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR eliminates code duplication by consolidating promotion mapping logic into a single constant. The duplicate promotion mapping dictionaries in three different methods (MCTS.run(), MCTS._simulate(), and self_play_episode()) are replaced with a shared PROMOTION_MAP constant defined at the top of the file.
- Defines a global
PROMOTION_MAPconstant containing chess piece promotion mappings - Removes duplicate promotion mapping dictionaries from three methods
- Updates all methods to use the shared constant with
.get()method calls
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| azlite_portfolio_clean.py | Adds global PROMOTION_MAP constant and removes duplicate dictionaries from three methods |
| tests/test_promotion_mapping.py | Adds comprehensive tests for the new PROMOTION_MAP constant and its usage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| promo_map = {chess.QUEEN: 1, chess.ROOK: 2, | ||
| chess.BISHOP: 3, chess.KNIGHT: 4} | ||
| promo_idxs.append(promo_map.get(mv.promotion, 0)) | ||
| PROMOTION_MAP.get(mv.promotion, 0) |
There was a problem hiding this comment.
Line 348 calls PROMOTION_MAP.get(mv.promotion, 0) but doesn't use the result. This appears to be a copy-paste error - line 348 should be removed as line 349 correctly appends the value to the list.
| PROMOTION_MAP.get(mv.promotion, 0) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Lint error, merge not possible unless Affected areas |
|
Manual Changes recommended |
|
Approval done and fixed. Thank you for your work |
Found that both MCTS.run() and MCTS._simulate() and created the PROMOTION_MAP constant also defined at the top of the file.
What I changed:
Removed duplicate promo_map dictionaries from both methods
Now both use PROMOTION_MAP.get(mv.promotion, 0) instead
Reduces code duplication and makes it easier to maintain
And the test for the above is included in test_promotion_mapping.py in tests folder