Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public static int heuristic2(int[][] map) {
  2. int returnValue = 0;
  3. int desiredColumn, desiredRow;
  4. for(int i = 0; i < map.length; i++){
  5. for(int j = 0; j < map[i].length; j++){
  6. if(map[i][j] == 0) {
  7. returnValue += Math.abs(i - (map.length-1)) + Math.abs(j - (map.length-1));
  8. } else {
  9. desiredColumn = (map[i][j] - 1) % map.length;
  10. desiredRow = (map[i][j] - 1) / map.length;
  11. returnValue += Math.abs(i - desiredRow) + Math.abs(j - desiredColumn);
  12. }
  13. }
  14. }
  15.  
  16. return returnValue;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement