#include<iostream>
#include<stack>
using namespace std;
struct pos{
int posx; //行变化
int posy; //列变化
};
stack<pos> path;
int map[8][11] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1,
1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1,
1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1,
1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
pos nextpos[8] = { { 0, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, -1 }, { -1, -1 }, { -1, 0 }, { -1, 1 } };
bool mazePath(int maze[][11], pos * nextpos, pos startpos, pos targetpos)
{
pos cpos = startpos;
while (cpos.posx != targetpos.posx||cpos.posy != targetpos.posy)
{
bool gonext = false;
for (int i = 0; i < 8; i++)
{
if (maze[cpos.posx + nextpos[i].posx][cpos.posy + nextpos[i].posy] == 0)
{
maze[cpos.posx][cpos.posy] = 2; //标记已经走过了
path.push(cpos);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载