Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aima.core.environment.eightpuzzle;
- import aima.core.search.framework.HeuristicFunction;
- import aima.core.util.datastructure.XYLocation;
- /**
- * @author Ravi Mohan
- *
- */
- public class Heuristic12 implements HeuristicFunction {
- private EightPuzzleGoalTest goal;
- public Heuristic12(EightPuzzleGoalTest goal) {
- this.goal = goal;
- }
- public double h(Object state) {
- EightPuzzleBoard board = (EightPuzzleBoard) state;
- int retVal = 0;
- for (int i = 1; i < 9; i++) {
- XYLocation loc = board.getLocationOf(i);
- XYLocation locGS = goal.getLocationOf(i);
- retVal += evaluateDistanceOf(loc, locGS);
- }
- return retVal;
- }
- public int evaluateDistanceOf(XYLocation loc, XYLocation locGS) {
- int retVal = 0;
- int xpos = loc.getXCoOrdinate();
- int ypos = loc.getYCoOrdinate();
- int xposGS = locGS.getXCoOrdinate();
- int yposGS = locGS.getYCoOrdinate();
- if (xpos != xposGS) retVal += 1;
- if (ypos != yposGS) retVal +=1;
- return retVal;
- }
- }
Add Comment
Please, Sign In to add comment