Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int heuristic2(int[][] map) {
- int returnValue = 0;
- int desiredColumn, desiredRow;
- for(int i = 0; i < map.length; i++){
- for(int j = 0; j < map[i].length; j++){
- if(map[i][j] == 0) {
- returnValue += Math.abs(i - (map.length-1)) + Math.abs(j - (map.length-1));
- } else {
- desiredColumn = (map[i][j] - 1) % map.length;
- desiredRow = (map[i][j] - 1) / map.length;
- returnValue += Math.abs(i - desiredRow) + Math.abs(j - desiredColumn);
- }
- }
- }
- return returnValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement