Thread: some progress made in stack maze..

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    Question some progress made in stack maze..

    i started out on programming d maze problem..and this is where i have reached
    i am having problems in certain areas wich i have mentioned in d code..plz have a look..


    << code snipped - reposted with tags below >>


    The problem i am now facing is that i am not able to link the maze(wich i am entering from d user of 0's and 1's) with processing part due to wich the maze displayed contains all 0's...plz help!!

  2. #2
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Use CODE tags

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    what is that???

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    i started out on programming d maze problem..and this is where i have reached
    i am having problems in certain areas wich i have mentioned in d code..plz have a look..



    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    struct str
    {
    	int x1,y1;
    	struct str *next,*prev;
    };
    struct pos
    {
    	int i,j;
    };
    void insert(struct str **,int,int);
    struct pos delet(struct str **);
    void main()
    {
    	int i=0,j=0,k,val=0;
    	int x2,y2;
    	int move;
    	static int r;
    	struct pos position;
    	int **maze,x,y;
    	struct str *start,*temp;
    	clrscr();
    	printf("Enter the order of matrix:\n");
    	scanf("%d",&y);
    	scanf("%d",&x);
    	maze=(int **)calloc(x,sizeof(int *));
    	for(i=0;i<x;i++)
    	{
    		maze[i]=(int *)calloc(y,sizeof(int));
    	}
    	printf("\nEnter location of\n 1)passages(0)\n 2)blockages(1)\n");
    
    	for(i=0;i<x;i++)
    	{
    		for(j=0;j<y;j++)             //this portion does not link                
    		{                                    //with d rest of program
    		  printf("\nmaze[%d][%d]=",i,j);
    		  scanf("%d",&val);
    		}
    	}
    
    	clrscr();
    	move=0;
    	r=0;
    	maze[0][0]=2;        //Starting position of rat
    	maze[x-1][y-1]=3;    //Location of food
    	x2=0;   y2=0;       //temporary coordinates
    	
              /*i have tried to define all the possible combinations below to be worked out*/
    
                   if(maze[0][1]==3||maze[0][1]==0)
    	{
    		move++;
    	}
    	else if(maze[1][0]==3||maze[1][0]==0)
    	{
    		move++;
    	}
    	start=temp=NULL;
    	do
    	{
    	  clrscr();
    	  for(i=0;i<x;i++)
    	  {
    	    printf("\n\n");
    	    for(j=0;j<y;j++)
    	    {
    	     if(maze[i][j]==2)
    	     {
    	      textcolor(RED+BLINK);       //some beautifications
    	      cprintf("       %d",maze[i][j]);
    	     }
    	     else
    	     {
    	      textcolor(WHITE);
    	      printf("\t%d",maze[i][j]);
    	     }
    	    }
    	   }
    
    	   if( ((maze[x2][y2+1]==0)||(maze[x2][y2+1]==3)) && ( ((y2+1)<y) && ((y2+1)>0)) )
    	    {
    	     if(maze[x2][y2+1]==3)
    	       {
    		 printf("\n\nfood is found");
    		 getch();
    		 exit(0);
    	       }
    	     maze[x2][y2]=4;
    	     insert(&start,x2,y2);
    	     y2=y2+1;
    	     maze[x2][y2]=2;
    	    }
    	    else if( ((maze[x2-1][y2]==0)||(maze[x2-1][y2]==3)) && ( ((x2-1)<x) && ((x2-1)>=0)) )
    	    {
    	     if(maze[x2-1][y2]==3)
    	     {
    	      printf("\n\nfood is found");
    	      getch();
    	      exit(0);
    	     }
    	     maze[x2][y2]=4;
    	     insert(&start,x2,y2);
    	     x2=x2-1;
    	     maze[x2][y2]=2;
    	    }
    	    else if( ((maze[x2][y2-1]==0)||(maze[x2][y2-1]==3)) && ( ((y2-1)<y) && ((y2-1)>=0)) )
    	    {
    	     if(maze[x2][y2-1]==3)
    	     {
    	      printf("\n\nfood is found");
    	      getch();
    	      exit(0);
    	     }
    	     maze[x2][y2]=4;
    	     insert(&start,x2,y2);
    	     y2=y2-1;
    	     maze[x2][y2]=2;
    	    }
    	    else if( ((maze[x2+1][y2]==0)||(maze[x2+1][y2]==3)) && ( ((x2+1)<x) && ((x2+1)>0)) )
    	    {
    	     if(maze[x2+1][y2]==3)
    	     {
    	      printf("\n\nfood is found");
    	      getch();
    	      exit(0);
    	     }
    	     maze[x2][y2]=4;
    	     insert(&start,x2,y2);
    	     x2=x2+1;
    	     maze[x2][y2]=2;
    	    }
    	    else
    	    {
    	     maze[x2][y2]=5;
    	     position=delet(&start);
    	     x2=position.i;
    	     y2=position.j;
    	     maze[x2][y2]=2;
    	    }
    	    if(x2==0&&y2==0)
    	    {
    	     r++;
    	    }
    	    if(r>move)
    	    {
    	     printf("\n\nnot found ");
    	     getch();
    	     exit(0);
    	    }
    	    getch();
    	  }while(maze[x2][y2]!=3);
     }
    void insert(struct str **start,int x2,int y2)
    {
    	struct str *node,*temp;
    	node=temp=NULL;
    	if(*start==NULL)
    	{
    		node=(struct str *)malloc(sizeof(struct str));
    		*start=node;
    		node->prev=NULL;
    		node->next=NULL;
    		node->x1=x2;
    		node->y1=y2;
    	}
    	else
    	{
    		node=(struct str *)malloc(sizeof(struct str));
    		for(temp=*start;temp->next!=NULL;temp=temp->next)
    		{}
    		temp->next=node;
    		node->next=NULL;
    		node->prev=temp;
    		node->x1=x2;
    		node->y1=y2;
    	}
    }
    struct pos delet(struct str **start)
    {
    	struct pos p;
    	struct str *temp;
    	temp=NULL;
    	for(temp=*start;temp->next!=NULL;temp=temp->next)
    	{}
    	p.i=temp->x1;
    	p.j=temp->y1;
    	temp->prev->next=NULL;
    	return(p);
    }
    The problem i am now facing is that i am not able to link the maze(wich i am entering from d user of 0's and 1's) with processing part due to wich the maze displayed contains all 0's...plz help!!
    Last edited by Ken Fitlike; 10-02-2006 at 08:56 AM. Reason: added code tags

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack
    By planet_abhi in forum C Programming
    Replies: 2
    Last Post: 04-12-2003, 04:22 AM
  2. What am I doing wrong, stack?
    By TeenyTig in forum C Programming
    Replies: 2
    Last Post: 05-27-2002, 02:12 PM
  3. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  4. made some progress on strings.. still one issue
    By ss3x in forum C++ Programming
    Replies: 0
    Last Post: 04-21-2002, 10:37 PM
  5. stack make file problem
    By puckett_m in forum C Programming
    Replies: 2
    Last Post: 11-22-2001, 11:51 AM