public double h(Object state) { EightPuzzleBoard board = (EightPuzzleBoard)state; int retVal = 0; for (int i = 1; i < 9; i++) { XYLocation loc = board.getLocationOf(i); retVal += evaluateManhattanDistanceOf(i, loc); } return(retVal); }
private int getNumberOfMisplacedTiles(EightPuzzleBoard board) { int numberOfMisplacedTiles = 0; if (!(board.getLocationOf(0).Equals(new XYLocation(0, 0)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(1).Equals(new XYLocation(0, 1)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(2).Equals(new XYLocation(0, 2)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(3).Equals(new XYLocation(1, 0)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(4).Equals(new XYLocation(1, 1)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(5).Equals(new XYLocation(1, 2)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(6).Equals(new XYLocation(2, 0)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(7).Equals(new XYLocation(2, 1)))) { numberOfMisplacedTiles++; } if (!(board.getLocationOf(8).Equals(new XYLocation(2, 2)))) { numberOfMisplacedTiles++; } return(numberOfMisplacedTiles); }