I am attempting to implement an algorithm that creates a Maze using a Depth - First Search algorithm (like this one). I have a two - dimensional array of Cell objects in a CellMatrix class. Each Cell holds a reference to a List<Cell> of its neighbors. Each cell also holds a reference to a Map which maps a direction (NORTH, SOUTH, EAST, WEST) to any of three conditions that can occur at a edge (WALL, PASSAGE, BOUNDARY). My current method is much longer than I usually like, and contains four if / else statements with what at first glance seems like a lot of code duplication (each if / else does basically the same thing). I know that many times these conditions can be alleviated through creative use of a Strategy (or Command) pattern. but I'm at a loss to see how it could be implemented here. Any help here would be greatly appreciated. [ October 06, 2006: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
As you are thinking, I'd look to collapse those four repetitive sections into one method called four times. The method would need to know whether we're at an edge, which direction we're facing and the neighbor cell.
Would something like that make sense? [ October 07, 2006: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jan 17, 2006
That sounds like a winner to me. Thanks for the help one more time Stan.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com