Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 8th, 2005, 10:17 PM
pickleman78 pickleman78 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Dallas,TX,USA
Posts: 582 pickleman78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to pickleman78
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?

Reply With Quote
  #2  
Old March 9th, 2005, 08:37 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: recursion?

i don't have an answer for your problem, however searching google it describes javascript recursion the same as i've always understood it. execution should continue where it left off.

Reply With Quote
  #3  
Old March 10th, 2005, 10:45 PM
pickleman78 pickleman78 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Dallas,TX,USA
Posts: 582 pickleman78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to pickleman78
RE: recursion?

alright then... I probably made some stupid mistake somewhere... too much of this script was poor planning on my part, I should have used a 2d array, and it would all be much clearer, but I decided to translate it into a a 1d array... bad plan I guess.... Oh well, I'm gonna switch languages, and use Java instead of JavaScript.... I needed to do some working with UI stuff in Java anyway... thanks though

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > recursion?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway