
March 8th, 2005, 10:17 PM
|
|
|
|
Join Date: Apr 2007
Location: Dallas,TX,USA
Posts: 582
Time spent in forums: < 1 sec
Reputation Power: 2
|
|
|
recursion?
Does recursion in JavaScript work differently than recursion in C++/Java/PHP? Is there something weird about how it handles things?
Ok, so here's my code
Code:
function clearAdjacent(id)
{
var id=id;
var rows;
var cols;
id=parseInt(id);
rows=parseInt(document.getElementById('rows').valu e);
cols=parseInt(document.getElementById('cols').valu e);
//Clear this one
swapElement(id,checkNum(id));
//Now do the adjacent ones
alert(id);
if( (id-rows)>=0 && checkNum(id-rows)==0 && mineField[id-rows]=='0') //Check above one
{
clearAdjacent(id-rows);
}
else if( (id-rows) >=0)
{
swapElement((id-rows),checkNum(id-rows));
}
if( ((id+rows) < (rows*cols)) && checkNum(id+rows) == 0 && mineField[id+rows]=='0') //Below
{
clearAdjacent(id+rows);
}
else if((id+rows) < (rows*cols))
{
swapElement((id+rows),checkNum(id+rows));
}
if(((id-1)>=0 && id%rows!=0) && checkNum(id-1) == 0 && mineField[id-1]=='0') //One to the left
{
clearAdjacent(id-1);
}
else if( (id-1)>=0 && id%rows !=0)
{
swapElement(id-1,checkNum(id-1));
}
if((id+1)%rows !=0 && checkNum(id+1) == 0 && mineField[id+1]=='0') //One to the right
{
clearAdjacent(id+1);
}
else if( (id+1)>=0 && id%rows !=0)
{
swapElement(id+1,checkNum(id+1));
}
if(((id+rows+1)<(rows*cols) && (id+1)%rows!=0) && (mineField[(id+rows+1)]=='0') && chekcNum(id+rows+1) == 0) //Down and to the right
{
clearAdjacent(id+rows+1);
}
else if(((id+rows+1)<(rows*cols) && (id+1)%rows!=0))
{
swapElement(id+rows+1,checkNum(id+rows+1));
}
if( (id-rows-1)>=0 && id%rows!=0 && (mineField[(id-rows-1)]=='0') && checkNum(id-rows-1) == 0) //Up and to the left
{
clearAdjacent(id-rows-1);
}
else if((id-rows-1)>=0 && id%rows!=0)
{
swapElement(id-rows-1,checkNum(id-rows-1));
}
if(((id-rows+1)>=0 && (id+1)%rows!=0) && (mineField[(id-rows+1)]=='0') && checkNum(id-rows+1)==0) //Up and to the right
{
clearAdjacent(id-rows+1);
}
else if ((id-rows+1)>=0 && (id+1)%rows!=0)
{
swapElement(id-rows+1,checkNum(id-rows+1));
}
if(((id+rows-1)<(rows*cols) && id%rows!=0) && (mineField[(id+rows-1)]=='0') && checkNum(id+rows-1)==0) //Down and to the left
{
clearAdjacent(id+rows-1);
}
else if (((id+rows-1)<(rows*cols) && id%rows!=0))
{
swapElement(id+rows-1,checkNum(id+rows-1));
}
return;
}
If it helps, this is for a minesweeper game. Now, after recursively going through, to the deepest level, when the last function returns, shouldn't the execution continue in the previous function where it left off? It only get through the first if, goes all the way to the last call, then doesn't go any farther. I'm not sure why though... it should go through all the functions... Any ideas?
|