MUD32 (.NET) Development Blog

Notes on Coding and Design of the MUD32 Mud Client by Matt Owen

The Art of Recursion

I've been asked by a few people now how I did the logic behind the map-walker code shown in the screenshot on the Cartography post.

The map-walker tool uses a a recursive function (Called WalkMap) that basically does the following.
  1. Load exits for Room X
  2. Using a static X/Y grid system, draw the room box on the map, and lines for each exit
  3. For each exit, if we've not visited that destination room before, call WalkMap with that destination room number; also update X and/or Y based on Exit name
  4. If no more exits to walk, exit function

Once you get your head around the recursive nature of the function, it's easy to understand that the walker, literally 'walks' the map, following every exit until it reaches a dead end, at which point the function returns one level back up the recursion, and looks for more exits in the previous room. The hardest part to get right was actually the mapping of the rooms on screen, as keeping track of the X/Y co-ords is quite tricky especially if you don't want to overwrite several rooms in the same place. I'm lucky in that the original map layout had hardly any overlapping rooms in the X/Y space - a later revision of the walker may gain the ability to extend an exit line to place on the map where there is not a room already there.


On 18/11/2013 at 08:08 ~
Latest Posts

About this Blog

MUD32.NET is a small project to build a new unique MUD Client on the Windows platform, using the .NET framework, and modern gameplay elements.

For more information, please read this post.
© 1997-2014