public int manhattanDistance(State state)
    {
    	int headDistance = 0, tailDistance = 0;
    	
    	//Each index contains a int array that contains {headRow, headCol, tailRow, tailCol}
        int[] tempWorm = new int[4];
        int[] coords = new int[2];      

        for(int i = 0; i < state.board.length; i++)
        {
           	for(int j = 0; j < state.board[0].length; j++)
           	{	
     	      	if(state.board[i][j] == (char) (48))
     	      	{
     	      		tempWorm = new int[4];
    	    		tempWorm[2] = i;
     	     		tempWorm[3] = j;
      	    		coords = getHeadCoords(i, j, state.board);
      	    		tempWorm[0] = coords[0];
      	     		tempWorm[1] = coords[1];
      	     	}
            }
        }    
        
        headDistance = (state.board.length - 1 - tempWorm[0]) + (state.board[0].length - 1 - tempWorm[1]);
    	tailDistance = (state.board.length - 1 - tempWorm[2]) + (state.board[0].length - 1 - tempWorm[3]);
    	
    	if(headDistance < tailDistance)
    		return headDistance;
    	else
    		return tailDistance;
    }