Hello,
We have analyzed the AI search strategies in this project for a university assignment on Software Refactoring. We detected some opportunities to clean up the code in AlphaBeta.java and HeuristicEvaluation.java.
Refactoring Suggestions:
-
Long Parameter List in AlphaBeta.java:
- Current State: Methods
maxValue and minValue pass 5 parameters recursively (map, alpha, beta, depth, totalStates).
- Proposal: Introduce a Parameter Object pattern (e.g.,
SearchContext class) to group these parameters. This cleans the method signature and facilitates adding future parameters (like time limits) without breaking recursion.
-
Complex Logic in HeuristicEvaluation.utility():
- Current State: The score calculation happens in a single, complex line inside a loop, and uses a magic number for
Map.getPhase().
- Proposal: Introduce Explaining Variables for the math (
rawScore, weightedScore) and the phase condition to clarify how the utility is calculated.
-
Dead Code in HeuristicEvaluation.java:
- Current State: The method
nPlayerUtility exists but is not used by the implemented 2-player AlphaBeta strategy.
- Proposal: Remove Dead Code to reduce noise and confusion about supported game modes.
These changes are aimed at reducing cognitive load when reading the core AI logic.
Best regards.
Hello,
We have analyzed the AI search strategies in this project for a university assignment on Software Refactoring. We detected some opportunities to clean up the code in
AlphaBeta.javaandHeuristicEvaluation.java.Refactoring Suggestions:
Long Parameter List in
AlphaBeta.java:maxValueandminValuepass 5 parameters recursively (map,alpha,beta,depth,totalStates).SearchContextclass) to group these parameters. This cleans the method signature and facilitates adding future parameters (like time limits) without breaking recursion.Complex Logic in
HeuristicEvaluation.utility():Map.getPhase().rawScore,weightedScore) and the phase condition to clarify how the utility is calculated.Dead Code in
HeuristicEvaluation.java:nPlayerUtilityexists but is not used by the implemented 2-player AlphaBeta strategy.These changes are aimed at reducing cognitive load when reading the core AI logic.
Best regards.