本文整理汇总了C++中Maze::FoundTheExit方法的典型用法代码示例。如果您正苦于以下问题:C++ Maze::FoundTheExit方法的具体用法?C++ Maze::FoundTheExit怎么用?C++ Maze::FoundTheExit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maze
的用法示例。
在下文中一共展示了Maze::FoundTheExit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find_path
bool find_path(Maze &maze, int row, int col)
{
Point position{row, col};
// to prevent circular path and going backwards and this make it search
// forward.
if (maze.AlreadyTried(position))
{
return false;
}
// found a path which is stop condition
if (maze.FoundTheExit(position))
{
return true;
}
// remember a position tried
maze.RememberPosition(position);
Point new_position{};
// left
if ((new_position = maze.GetPositionToMoveLeft(position)) != position)
{
cout << "l:(" << new_position.first << ", " << new_position.second << ")" << endl;
if (find_path(maze, new_position.first, new_position.second))
{
// cout << "left:insert(" << new_position.first << ", " << new_position.second << ")" << endl;
maze.path_points.insert(maze.path_points.begin(), new_position);
return true;
}
}
// right
if ((new_position = maze.GetPositionToMoveRight(position)) != position)
{
cout << "r:(" << new_position.first << ", " << new_position.second << ")" << endl;
if (find_path(maze, new_position.first, new_position.second))
{
cout << "right:insert(" << new_position.first << ", " << new_position.second << ")" << endl;
maze.path_points.insert(maze.path_points.begin(), new_position);
return true;
}
}
// up
if ((new_position = maze.GetPositionToMoveUp(position)) != position)
{
cout << "u:(" << new_position.first << ", " << new_position.second << ")" << endl;
if (find_path(maze, new_position.first, new_position.second))
{
// cout << "up:insert(" << new_position.first << ", " << new_position.second << ")" << endl;
maze.path_points.insert(maze.path_points.begin(), new_position);
return true;
}
}
// down
if ((new_position = maze.GetPositionToMoveDown(position)) != position)
{
cout << "d:(" << new_position.first << ", " << new_position.second << ")" << endl;
if (find_path(maze, new_position.first, new_position.second))
{
// cout << "down:insert(" << new_position.first << ", " << new_position.second << ")" << endl;
maze.path_points.insert(maze.path_points.begin(), new_position);
return true;
}
}
// diag right up
if ((new_position = maze.GetPositionToDiagRightUp(position)) != position)
{
cout << "dru:(" << new_position.first << ", " << new_position.second << ")" << endl;
if (find_path(maze, new_position.first, new_position.second))
{
// cout << "diag:rup:insert(" << new_position.first << ", " << new_position.second << ")" << endl;
maze.path_points.insert(maze.path_points.begin(), new_position);
return true;
}
}
// diag right down
if ((new_position = maze.GetPositionToDiagRightDown(position)) != position)
{
cout << "drd:(" << new_position.first << ", " << new_position.second << ")" << endl;
if (find_path(maze, new_position.first, new_position.second))
{
// cout << "diag:rdown:insert(" << new_position.first << ", " << new_position.second << ")" << endl;
maze.path_points.insert(maze.path_points.begin(), new_position);
return true;
}
}
//.........这里部分代码省略.........