Upload
bishoy-emile
View
215
Download
0
Embed Size (px)
Citation preview
8/13/2019 maze.txt
1/6
#include#include#include using namespace std;ifstream rff("maze.txt");//rff:ReadFromFileofstream ptf("mazesolution.txt");//ptf:Print To Filestruct point{
int row;int col;
};struct node{
point data;node*next;
};struct stack{
node*top;int count;
};bool isEmpty(stack*&s){
if (s->count==0)
return true;elsereturn false;
}bool isFull(stack*&s){
node*temp = new node;if (temp==0)
return true;else
return false;}bool push(stack*&s,point p)
{ if (isFull(s)==false){node*temp= new node;temp->data.row= p.row;temp->data.col= p.col;temp->next=s->top;s->top=temp;s->count ++;return true;}else
return false;
}bool pop(stack*&s,point&p){
if (isEmpty(s)==false){
p.row=s->top->data.row;p.col=s->top->data.col;s->count --;node*temp=s->top;s->top=s->top->next;
8/13/2019 maze.txt
2/6
delete temp;return true;
}else
return false;}bool top(stack*&s,point&p){
if (isEmpty(s)==false){
p.row=s->top->data.row;p.col=s->top->data.col;return true;
}else
return false;}bool createStack(stack*&s){
s=new stack;s->top=NULL;s->count=0;return true;
}
void createArray(int** &maze,int row,int col){maze = new int*[row];for(int i=0;i>ch;}
}}
point findExit(int**M,int r,int c){
int i=0,j=0;point p;while (M[i][j] !=0){
if ( j==0&&i!=r-1)//in the first column and not reaching the last row
{i++;
}else if(i==r-1&&j !=c-1)// in the last row but not the last colu
8/13/2019 maze.txt
3/6
mn{
j++;}else if(j==c-1&& i!=0)//in the last column but not the first row{
i--;}else if (i==0 && j!=0)//in the first row still searching for the
exitj--;
if( i==0 && j==0)// no exit at allbreak;
}p.row=i;p.col=j;return p;
}bool isInvalid(int **A,point pos,point size){
if( (pos.row>=size.row||pos.col>=size.col||pos.row
8/13/2019 maze.txt
4/6
pos.row--;else
pos.row++;if (M[pos.row][pos.col]==0)
count++;}control=count;return (count>1);
}void path(int **Maze,point mouse,point dest,point size){
if (isInvalid(Maze,mouse,size))//checking whether the mouse is in a wrong place or not
{ptf
8/13/2019 maze.txt
5/6
}for (int i=0;i
8/13/2019 maze.txt
6/6
ptf