Skip to content

Refactoring Proposal: Code cleanup in AlphaBeta and HeuristicEvaluation classes #2

Description

@himerino

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:

  1. 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.
  2. 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.
  3. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions