Buggy code:
public class GameState { class MapLocation { @ Override public int hashCode ( ) { } @ Override public boolean equals ( Object obj ) { } public int x ; public int y ; GameState . MapLocation cameFrom ; public float estTotalCost ; public float cost ; public MapLocation ( int x , int y ) { } private GameState getOuterType ( ) { } } class UnitState { private int xPosition ; private int yPosition ; private int unitHP ; private int ID ; private int basicAtt ; private int range ; private String type ; public UnitState ( int x , int y , int hp , int id , int basicAttack , int range , String type ) { } public UnitState ( GameState . UnitState unitState ) { } } private List < Integer > friendlyUnitIDs = new ArrayList < Integer > ( ) ; private List < Integer > enemyUnitIDs = new ArrayList < Integer > ( ) ; private HashSet < GameState . MapLocation > resourceLocations = new HashSet < GameState . MapLocation > ( ) ; private HashSet < AstarAgent . MapLocation > AstarResourceLocations = new HashSet < AstarAgent . MapLocation > ( ) ; AstarAgent searchAgent = new AstarAgent ( 0 ) ; private int mapXExtent ; private int mapYExtent ; private GameState . UnitState [ ] units = new GameState . UnitState [ 4 ] ; private int numArchers ; public GameState ( State . StateView state ) { } public GameState ( GameState newState ) { } public double getUtility ( ) { int tempMin = Integer . MAX_VALUE ; int distanceMetric = 0 ; int numFootmen ; if ( ( friendlyUnitIDs . size ( ) ) < 2 ) { numFootmen = 1 ; } else numFootmen = 2 ; for ( int i = 0 ; i < numFootmen ; i ++ ) { for ( int j = numFootmen ; j < ( numFootmen + ( numArchers ) ) ; j ++ ) { int otherArcherPos ; <START_BUG> if ( j < ( numFootmen + ( numArchers ) ) ) <END_BUG> otherArcherPos = j + 1 ; else otherArcherPos = j - 1 ; AstarAgent . MapLocation footmanLoc = searchAgent . new edu . cwru . sepia . agent . minimax . AstarAgent . MapLocation ( units [ i ] . xPosition , units [ i ] . yPosition , null , 0 ) ; AstarAgent . MapLocation archerLoc = searchAgent . new edu . cwru . sepia . agent . minimax . AstarAgent . MapLocation ( units [ j ] . xPosition , units [ j ] . yPosition , null , 0 ) ; AstarAgent . MapLocation otherArcherLoc ; if ( ( units [ otherArcherPos ] ) == null ) otherArcherLoc = null ; else otherArcherLoc = searchAgent . new edu . cwru . sepia . agent . minimax . AstarAgent . MapLocation ( units [ otherArcherPos ] . xPosition , units [ otherArcherPos ] . yPosition , null , 0 ) ; tempMin = ( tempMin > ( searchAgent . getHopDistance ( footmanLoc , archerLoc , mapXExtent , mapYExtent , otherArcherLoc , AstarResourceLocations ) ) ) ? getDistance ( units [ i ] , units [ j ] ) : tempMin ; } distanceMetric += tempMin ; } int hpMetric = 0 ; for ( int j = 0 ; j < ( numFootmen + ( numArchers ) ) ; j ++ ) { if ( units [ j ] . type . equals ( "footmen" ) ) { hpMetric += units [ j ] . unitHP ; } else hpMetric -= units [ j ] . unitHP ; } return hpMetric ; } public List < GameStateChild > getChildren ( boolean playerTurn ) { } public int getDistance ( GameState . UnitState unit1 , GameState . UnitState unit2 ) { } public boolean isAdjacent ( GameState . UnitState unit1 , GameState . UnitState unit2 ) { } }

Fix:
if ( j < ( ( numFootmen + ( numArchers ) ) - 1 ) )