/ do a dfs of maze and display as you go
public void dfs(int i, int j)
{
StackNode p=new StackNode();
theStack = new StackNode();
theStack.xcoord = i;
theStack.ycoord = j;
theStack.next = null;
// set current square to visited
theMaze.mazegrid[i,j] = 3;
while (empty())
{
p = pop();
if (theMaze.mazegrid[p.xcoord + 1,p.ycoord] == 0)
{
theMaze.mazegrid[p.xcoord + 1, p.ycoord] = 3;
visit(p.xcoord + 1, p.ycoord);
}
if (theMaze.mazegrid[p.xcoord,p.ycoord+1] == 0)
{
theMaze.mazegrid[p.xcoord, p.ycoord + 1] = 3;
visit(p.xcoord, p.ycoord+1);
}
if (theMaze.mazegrid[p.xcoord - 1,p.ycoord] == 0)
{
theMaze.mazegrid[p.xcoord - 1, p.ycoord] = 3;
visit(p.xcoord - 1, p.ycoord);
}
if (theMaze.mazegrid[p.xcoord,p.ycoord-1] == 0)
{
theMaze.mazegrid[p.xcoord, p.ycoord - 1] = 3;
visit(p.xcoord, p.ycoord-1);
}
//display the maze
theMaze.display_maze(offScreenDC);
drawArea.DrawImage(offScreenBmp, 0, 0);
//wait a bit
Thread.Sleep(200);
}
// move the bot and return to original position
// after all children have been searched
// set current square to revisited (i.e. backtracked to)
theMaze.mazegrid[i,j] = 4;
//display the maze
theMaze.display_maze(offScreenDC);
drawArea.DrawImage(offScreenBmp, 0, 0);
//wait a bit
}