package edu.utdallas.robotchess.engine.heuristics;

import java.util.*;

import edu.utdallas.robotchess.game.*;

/*
 * Basic mobility is simply the number of moves available to the player at a given time.
 *
 * There are several possibilities suggested for improving on this:
 *  - Bishop/Knight mobility may be prioritized over Rooks (on opening especially)
 *  - forward mobility prioritized over backward mobility
 *  - for rooks, vertical mobility prioritized over horizontal mobility
 *  - though not a legal move, it is useful to count moves to the square 
 *    of a friendly piece (i.e. for protection)
 */
public class MobilityHeuristicFunction implements HeuristicFunction
{
    @Override
    public double h(ChessGame game)
    {
        List<ChessPiece> activePieces = game.getActivePieces();
        
        double mobilityValue = 0.0;

        for (int i = 0; i < activePieces.size(); i++) {
            ChessPiece piece = activePieces.get(i);
            
            if (piece.getTeam() == game.getActiveTeam()) {
                ArrayList<Square> moveLocations = game.generateMoveLocations(piece);
                mobilityValue += moveLocations.size();
            }
        }

        return mobilityValue;
    }
}

@@ -1204,16 +1204,26 @@
  return 
+normalize(
 mobility
@@ -1227,16 +1227,107 @@
 ityValue
+);%0A    %7D%0A    %0A    private double normalize(double value)%0A    %7B%0A        return value / 100.0
 ;%0A    %7D%0A

normalize the mobility function