Recursion is typically used to traverse a tree-like structure where 100 is plenty. The one method where I think 100 could be too little is something like searching a maze where the path has more than 100 squares or points to check along a path. Wolph42, how were you using your recursion?
random dungeon generator. I've already have a field with randomly generated room in it. now im trying to create paths between the rooms. Starting in one room and going in a random direction (recursively) until another room is found. Repeat for all rooms. I've thought of at least 5 other methods, but this is the one I would like to get working first.
as for how...
-pick a random point in first room.
-choose a random direction: N/E/S/W.
-Create an array with all four directions,
while empty corridor OR !all 4 direction checked
-pick the direction randomly chosen (get that coord)
- check coord is 'ok' (that is: no edge of dungeon)
- recursive function: corridor = nextCoord(coord, other stuff)
<!-- start recursive function: nextCoord() -->
- add coord to 'corridor array'
- low random chance that direction changes
- create array of 3 adjacent coords
- pick coord of cell in the current direction
- check if is 'ok'. If not return empty corridor ; if it is corridor = nextCoord(coord)
- return corridor
its a bit more complex e.g. not 1 but 2 steps at the time to limit the required recursions. if a corridor fails, fall back to the point where the direction changed, pick the next direction and try again from that point onward until all 3 directions have been tried.
currently debugging. so far I've either hit bugs OR recursive limit.
Recursive loops give me head-aches...
if all fails:
- not doing it recursively but using a forward 'defer' loop, remembering the 'direction change nodes' on which you can fall back and try again from there on. That however is WAY trickier, but theoretically should give infinite amount of trial on error
- plot a straight corridor from S to N and simply plot corridors from that one to the room in a straight line (not pretty but effective)
- pick two rooms, pick two coords from those room and simply plot the shortest path between those two (potentially going around other rooms or not)