[WIP] Cleanup and reorganize MetalFish codebase #31
+0
−0
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>[Chore] Codebase cleanup, reorganization, and dead code removal</issue_title>
<issue_description>## Summary
Comprehensive cleanup and reorganization of the MetalFish codebase to improve maintainability, reduce redundancy, and establish a cleaner architecture. This involves analyzing every file, removing unused code, merging overlapping functionality, restructuring directories, and removing all references to Stockfish and Lc0.
Current State Analysis
Directory Structure (Current)
Key Issues Identified
1. Multiple MCTS Implementations (HIGH PRIORITY)
The
src/mcts/directory has overlapping implementations:thread_safe_mcts.cpp/happle_silicon_mcts.cpp/hparallel_hybrid_search.cpp/hab_integration.cpp/hlc0_mcts_core.hstockfish_adapter.cpp/hposition_classifier.cpp/hProblem:
AppleSiliconMCTSEvaluator,ThreadSafeMCTS, andParallelHybridSearchall implement similar MCTS logic with different optimizations. This should be ONE configurable class.2. Redundant Test Files
Multiple test files cover the same functionality:
test_core.cpp+test_bitboard.cpp+test_position.cpp+test_movegen.cpptest_core.cpptest_mcts.cpp+test_mcts_module.cpp+test_mcts_comprehensive.cpptest_mcts.cpptest_search.cpp+test_search_module.cpp+test_search_comprehensive.cpptest_search.cpptest_gpu_nnue.cpp+test_gpu_module.cpp+test_gpu_comprehensive.cpptest_gpu.cpptest_hybrid.cpp+test_hybrid_comprehensive.cpptest_hybrid.cpp3. Large Files Needing Split
gpu_nnue_integration.cppsearch.cppuci.cppthread_safe_mcts.cpp4. Platform-Specific Code Not Properly Isolated
Files with mixed platform code that should be separated:
src/core/memory.cpp- Has#ifdef __APPLE__mixed insrc/core/numa.h- 1,437 lines with platform-specific sectionssrc/search/apple_silicon_search.h- Should be in a platform/ directorysrc/mcts/apple_silicon_mcts.cpp- Should be in platform/5. Unused/Dead Code Patterns
src/core/shm.handsrc/core/shm_linux.h- Shared memory (likely unused)src/core/perft.h- Perft testing (move to tests/)src/search/tune.cpp/h- Tuning infrastructure (review if used)src/gpu/cpu_backend.cpp- CPU fallback (verify it's actually used)6. Stockfish/Lc0 References That Must Be Removed (HIGH PRIORITY)
MetalFish is its own engine. All references to Stockfish and Lc0 must be removed or rebranded.
Files with Stockfish references (18 files):
src/gpu/gpu_accumulator_cache.hsrc/gpu/gpu_nnue_integration.cppsrc/gpu/gpu_mcts_backend.hsrc/gpu/gpu_mcts_backend.cppsrc/gpu/gpu_nnue_integration.hsrc/core/numa.hsrc/uci/engine.hsrc/uci/benchmark.cppsrc/uci/uci.cppsrc/eval/nnue/network.cppsrc/mcts/thread_safe_mcts.cppsrc/mcts/parallel_hybrid_search.hsrc/mcts/parallel_hybrid_search.cppsrc/mcts/stockfish_adapter.h→ Rename tometalfish_adapter.hsrc/mcts/ab_integration.hsrc/mcts/ab_integration.cppsrc/mcts/stockfish_adapter.cpp→ Rename tometalfish_adapter.cpptests/test_hybrid.cppFiles with Lc0/Leela references (8 files):
src/mcts/apple_silicon_mcts.hsrc/mcts/thread_safe_mcts.hsrc/mcts/apple_silicon_mcts.cppsrc/mcts/thread_safe_mcts.cppsrc/mcts/lc0_mcts_core.h→ Rename tomcts_core.hsrc/mcts/parallel_hybrid_search.cppsrc/mcts/stockfish_adapter.h💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.