Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 30th, 2007, 12:15 AM   #1
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Angry Checking possible moves recursivley

I have a map which is composed of 16x16 squares, There are six types of squares which can have walls on different sides (left + top, top, top+right,right, left+bottom,bottom, bottom+left) Those squares are the obstacles within the map. I also have special squares which move vertically and horizontally. My problem is figuring out how far a certain square can move before it collides with a block. I am trying to accomplish this recursively but I am not sure how I can do this since the values are increasing and not decreasing. I am not sure how to test for the base case where the function should return.

I have spent a couple hours trying to figure this out, and I am simply stumped. Any hints will be really appreciated.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Oct 30th, 2007, 5:39 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Re: Checking possible moves recursivley

Just keep recursing until:

a) You hit a wall
b) You run out of unexplored spaces
c) You hit some internal limit on how far the function should explore

Presumably you're only interested in places you haven't been before, so keep a record of what places have been explored. If your map is 16 by 16, there's only 255 additional places your special squares can move to.
Arevos is offline   Reply With Quote
Old Oct 30th, 2007, 10:30 AM   #3
SamReidHughes
Newbie
 
Join Date: Oct 2007
Posts: 13
Rep Power: 0 SamReidHughes is on a distinguished road
Re: Checking possible moves recursivley

I presume your data structure describing barriers is a set of edges, where an edge is an ordered pair of square coordinates normalized in sorted order. Right? And you have some kind of function such as "existsBarrier(board, squarecoordinate, squarecoordinate)", right?

This algorithm -- moving a square in one direction until it has to stop -- does not need to be recursive; it could just be done iteratively. So if you write the algorithm recursively, the recursive call would be done in the return statement.
SamReidHughes is offline   Reply With Quote
Old Oct 30th, 2007, 10:45 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Re: Checking possible moves recursivley

Quote:
Originally Posted by SamReidHughes View Post
This algorithm -- moving a square in one direction until it has to stop
I rather assumed that the square could move in any horizontal or vertical direction, and that this was more a path-finding problem than a collision detection problem. Otherwise, as you say, you wouldn't need recursion.

Could you explain a little further, Wizard1988? It's not clear what exactly you want to do.
Arevos is offline   Reply With Quote
Old Oct 30th, 2007, 11:42 AM   #5
WaltP
Programmer
 
Join Date: Oct 2007
Posts: 39
Rep Power: 0 WaltP is on a distinguished road
Re: Checking possible moves recursivley

When you enter a square, pass into the function the direction entered from (i.e. if you moved left out of the previous square, this value is right)

Each direction must test the direction entered before calling the function again and skip that call.
Enter a square and, if no wall, go left. When the function returns, go up, then skip right, then go down. At this point you return from the function and end up in the previous square to continue it's journey 'round the horn.
WaltP is offline   Reply With Quote
Old Oct 30th, 2007, 9:00 PM   #6
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 3 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Re: Checking possible moves recursivley

I managed to fix my problem. I had to check the current square as well as the one ahead of it.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC