void init();
int pass();
void printfoot();
void push();
void nextstep();
void changedir();
void roadprint();
void pop();
void main()
{
init();
do
{
if(pass())
{
printfoot();
push();
nextstep();
}
else
{
curpos=router->seat[router->top];
if(curpos.dir<4)
changedir();
else
pop();
}
if((curpos.x==endpos.x)&&(curpos.y==endpos.y))
{
printf("you get!!\n");
break;
}
}while(router->top>=0);
roadprint();
}
void init ()
{
router=(stack *)malloc(sizeof(stack));
strpos.x=1;
strpos.y=1;
endpos.x=8;
endpos.y=8;
strpos.dir=1;
router->top=-1;
curpos=strpos;
}
int pass()
{
if(map[curpos.x][curpos.y]==0)
return 1;
else
return 0;
}
void printfoot()
{
map[curpos.x][curpos.y]=2;
}
void push()
{
router->top++;
router->seat[router->top]=curpos;
}
void nextstep()
{
curpos=router->seat[router->top];
curpos.y++;
curpos.dir=1;
}
void changedir()
{
router->seat[router->top].dir++;
switch(curpos.dir)
{
case 1:curpos.x++;break;
case 2:curpos.y--;break;
case 3:curpos.x--;break;
case 4:pop();break;
default :printf("error direction!\n");
}
curpos.dir=1;
}
void pop()
{
router->seat[router->top--];
curpos=router->seat[router->top];
changedir();
}
void roadprint()
{
for(int i=0;i<=router->top;i++)
{
printf("seat:%d,%d dir:%d top%d\n",router->seat[i].x,router->seat[i].y,router->seat[i].dir,router->top);
}
}