本文整理汇总了C++中Maze::drawMark方法的典型用法代码示例。如果您正苦于以下问题:C++ Maze::drawMark方法的具体用法?C++ Maze::drawMark怎么用?C++ Maze::drawMark使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maze
的用法示例。
在下文中一共展示了Maze::drawMark方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deepthFirstStackSearch
void deepthFirstStackSearch(Maze &maze,pointT current,pointT exit){
set<pointT> block;
stack<pointT> pathStack;
pathStack.push(current);
while(true){
pointT currentP=pathStack.top();
block.insert(currentP);
pointT around;
bool flag=false;
int i=0;
while(i<4){
around=currentP;
switch(i){
case 0:
around.col--;
break;
case 1:
around.row--;
break;
case 2:
around.col++;
break;
default:
around.row++;
}
//判断该点合法
if(maze.pointInBounds(around)&&!maze.isWall(currentP,around)&&block.count(around)==0){
flag=true;
break;
}
i++;
}
//有可走的子节点
if(flag){
if(around==exit){
maze.drawMark(around,"Red");
break;
}
else{
pathStack.push(around);
}
}
else{
pathStack.pop();
}
}
while(!pathStack.empty()){
maze.drawMark(pathStack.top(),"Red");
pathStack.pop();
}
}
示例2: search
bool search(Maze &maze,set<pointT> &includePoint,pointT current,pointT exit){
pointT around;
includePoint.insert(current);
int i=0;
while(i<4){
around=current;
switch(i){
case 0:
around.col--;
break;
case 1:
around.row--;
break;
case 2:
around.col++;
break;
default:
around.row++;
}
//判断该点合法
if(maze.pointInBounds(around)&&!maze.isWall(current,around)&&includePoint.count(around)==0){
if(around==exit){
cout<<"get it"<<endl;
maze.drawMark(around,"Red");
return true;
}
else{
bool flag=search(maze,includePoint,around,exit);
if(flag){
maze.drawMark(around,"Red");
return true;
}
}
}
i++;
}
return false;
}
示例3: breadthFirstSearch
void breadthFirstSearch(Maze &maze,const pointT entry,const pointT exit){
pointT current=entry;
pointT around;
//int i=search(maze,current,current,exit);
queue< stack<pointT> > pathQueue;
stack<pointT> currentStack;
set<pointT> includePointT;
currentStack.push(current);
pathQueue.push(currentStack);
while(true){
//获取当前队列的最先进去的一个栈,栈顶的点作为当前点
currentStack=pathQueue.front();
current=currentStack.top();
//将当前点插入set,保证不走重复路
includePointT.insert(current);
//获取当前点附近可走的点
int i=0;
bool flag=false;
while(i<4){
around=current;
switch(i){
case 0:
around.col--;
break;
case 1:
around.row--;
break;
case 2:
around.col++;
break;
default:
around.row++;
}
i++;
//判断该点是否合法
if(maze.pointInBounds(around)){
//int index=includePointT.count(around);
if(!maze.isWall(current,around)&&includePointT.count(around)==0){
//判断是否是出口
if(around==exit){
cout<<"get it"<<endl;
maze.drawMark(around,"Red");
flag=true;
break;
}
else{
stack<pointT> tem = currentStack;
tem.push(around);
pathQueue.push(tem);
}
}
}
}
//如果找到出口退出循环
if(flag){
//mark the path
while(!currentStack.empty()){
pointT top=currentStack.top();
maze.drawMark(top,"Red");
currentStack.pop();
}
break;
}
else{
pathQueue.pop();
}
}
}
示例4: deepthFirstIteratorSearch
void deepthFirstIteratorSearch(Maze &maze,pointT current,pointT exit){
set<pointT> includePoint;
includePoint.insert(current);
bool flag=search(maze,includePoint,current,exit);
if(flag) maze.drawMark(current,"Red");
}