Counting number of merged objects
<p>This probably has an easy solution that I'm not realizing. With the following code (from the php/javascript jigsaw puzzle codes) I'm merging one object with another (puzzle pieces). I want to be able to count how many objects there are after each merge, to check for the condition that only one object is left (the puzzle is solved). I tried writing a separate function to count the number hasownproperties for the object (although I'd like to just count the merged object number, not the number object properties to avoid complicating this script for the varying puzzle difficulty levels), but it didn't work. Suggestions?</p>

<pre><code>var cluster = new Array();

function merge_cluster(a, b) {
    for (i in cluster[b]) {
        obj = dd.elements[cluster[b][i]];
        cluster[a][obj.name] = obj.name;
        obj.cluster = a;
    }
}


function my_DropFunc() {
    align_cluster(dd.obj.cluster);

    for (r = -1; r &lt;= 1; r++) {
        for (c = -1; c &lt;= 1; c++) {
            if (c != 0 || r != 0) {
                obj = dd.elements['t_' + (dd.obj.row + r) + '_' + (dd.obj.col + c)];
                if (obj) {
                    if (dd.obj.x + c * &lt; ? = $vw ? &gt; == obj.x &amp;&amp; dd.obj.y + r * &lt; ? = $vh ? &gt; == obj.y) {
                        merge_cluster(dd.obj.cluster, obj.cluster);
                        //this is probably the ideal place to do a count check since it runs every time a piece is dropped, only once, whereas the merge_cluster function runs multiple times when a new cluster is merged.
                    }
                }
            }
        }
    }

}
</code></pre>
