#include <stddef.h>
char *maze_runner(const int *maze, size_t n, const char *directions) {
int start, line, column, current;
for( start = 0; start < n * n; start++ )
if( maze[start] == 2 )
break;//找到起点
line = start / n;
column = start % n;
while( *directions )
{
if( *directions == 'N' )
line-=1;
else if( *directions == 'S' )
line+=1;
else if( *directions == 'E' )
column+=1;
else
column-=1;
current = line * n + column;
if( line < 0 || line >=n || column < 0 || column >=n || maze[current] == 1)//判断是否存在越界情况或碰到墙壁
return "Dead";
else if(maze[current] == 3 )
return "Finish";
directions++;
}
return "Lost";
}