title: Getting access to the state of a node in NxN 2D array
body: <p>I'm implementing NxN puzzle in 2D array in Java.  I have the following classes:</p>
  
  <pre><code>public class Node {
  
      //private members
      private int boardSize;
      private int row, col;
  
      int state[][] = new int[][]{};   //the state of a node
  
      // the total cost from root node to current node
      private int pathCost;  
      // this is the heuristic cost from the current node to the goal node
      private int heuristicCost;  
     // functionCost = pathCost + heuristicCost
      private int funcitonCost; 
      // parent of the current node
      private Node parentNode;
  
     ......
  
    // I have here all accessor functions and functions that return x and y cordinates when a //number in the array is given.
  }
  
  public class A*Algo {
  
  
  
      private int[][] goalNode ={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};
  
      private NodeComparator nodeComparator = new NodeComparator();
      private PriorityQueue&lt;Node&gt; openList = null;    // open list
      private PriorityQueue&lt;Node&gt; closedList = null;       // closed list
      private int steps = 0;
      private int BOARDSIZE;
  
  
            // constructor
            public AStar(Node startNode, int boardSize){
          //this.node = new Node(tiles, null, boardSize);
          //this.tiles = tiles;
          this.BOARDSIZE = boardSize;
      /*  this.succesorNodes = new FifoNodeStore();
          this.fringeNodes = new FifoNodeStore();*/
          this.openList = new PriorityQueue&lt;Node&gt;(0, nodeComparator);
          this.closedList = new PriorityQueue&lt;Node&gt;(0, nodeComparator);
  
          startNode.setParentNode(null);
          startNode.setPathCost(0);
                  // PROBLEM :::: goalNode must be a Node and not int[][]
                  // How can i represent the goal node?
          startNode.setHeuristicCost(manhattan(startNode, goalNode)); 
          this.addToOpenList(startNode);
          this.search(startNode);
      }
  
  
  
     public int manhattan(Node currentNode, Node goalNode) {
      return Math.abs(currentNode.x - goalNode.x) + Math.abs(currentNode.y - goalNode.y);
      }
  
  }
  </code></pre>
  
  <p>I have the following two problems:</p>
  
  <p>1)
  How should I represent the goal Node?
  In the second class I declare the goal node as <code>int[][]</code> but I want it to be a node so that I can give it to the manhattan function.</p>
  
  <p>2)
  In the Node class, I have a state <code>int state[][]</code> which represent the state of the node. Now my problem is how do i get access to the individual coordinates in the state in the nodes.  Assuming the goalNode declaration is correct then I must be able to call the manhattan like this:</p>
  
  <pre><code>manhattan(startNode, goalNode)
  </code></pre>
  
  <p>to calculate from the current node to the goal node.</p>
  
  <h2>Edit</h2>
  
  <p>I am required to use the manhattan heuristic in the following way:         </p>
  
  <pre><code>the sum of the vertical and horizontal distances from 
              the current node to the goal node/tile
  
                              +(plus)
  
  the number of moves to reach the goal node from the initial position
  </code></pre>