Challenging scenario - need help from Gurus

This is a discussion on Challenging scenario - need help from Gurus within the C Programming forums, part of the General Programming Boards category; Hello everyone , This is my very first post and i am have started learning C programming 2 months back ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    4

    Challenging scenario - need help from Gurus

    Hello everyone ,

    This is my very first post and i am have started learning C programming 2 months back so you can say i am a beginner in C ... but i have tried hard currently understanding conditional statments (IF-ELSE) , Loops , arrays and functions .

    I have been given a task in my university that i need to design a "maze traversal game" such that the maze changes itself randomly everytime a new user starts the game after thinking and trying day and night for past days i have managed to write the code of the maze in such a way that the square walls of the maze is built using arrays while the inside the squared walls the maze changes itself randomly but the problem i am facing is i simply can't think of any code such that if a user starts to play the game he starts at position X and walks himself all the way through the End position and major thing is whenever a new user is going to start the maze , the maze will be automatically generated but in such a way that a way will also be induced in the maze that the user starts from the starting position and ends at the ending point.

    Kindly i have tried hard thinking of such a code but if anyone can help me , i would be grateful .

    the code which i have written roughly so far is

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<time.h>
    
    int main ()
    
    {
    
    char maze[12][12];
    int x,y,a,b,c;
    char question;
    
    srand((unsigned) time (NULL));
    printf("******************************************\nWelcome to the maze game !\t\t *\nPlease note the keys to play the game\t *\nUP\tDOWN\tRIGHT\tLEFT\t\t *\n[i]\t[m]\t[h]\t[l]\t\t *\n******************************************");
    printf("\n\n");
    
                                   do
                                   {
                                     for(a=0;a<12;a++)
                                               {
    
                                                   maze[0][a]='#';
                                                   maze[11][a]='#';
    
                                                }
                                       for(b=0;b<12;b++)
                                                            {
    
                                                                maze[b][0]='#';
                                                                maze[b][11]='#';
                                                            }
    
                                                                for (x=1;x<=10;x++)
                                                                for (y=1;y<=10;y++)
    
                                                                             {
    
                                                                                 c=rand()%10;
    
    
                                                                                if(c>1 && c<6 )
                                                                                maze[x][y]='#';
                                                                                else
                                                                                maze[x][y]='.';
    
    
                                                                             }
    
                                                                                     for (x=0;x<12;x++)
                                                                                 {
                                                                                                             printf("\n");
                                                                                                             for (y=0;y<12;y++)
                                                                                     {
    
                                                                                                      printf("%c",maze[x][y]);
                                                                                     }
    
    
                                                                                 }
    
    
    
                                     printf("\n Press [c] to continue : ");
                                     fflush(stdin);
                                     scanf("%c",&question);
    
    
    }while( question == 'c');
    
    
    
    
    printf("\n");
    printf("\n");
    
    
    return 0;
    
    }
    i have also attached the pictures of the maze traversal game which is clearly described in 3 steps , how the maze should be , how it changes randomly and also along with changing itself , it shows a valid path from starting and ending point and also a pain is the starting and ending points also changes randomly.

    i have used Quincy 2005 to write the code above and it works without anysort of errors .

    Please help , kindly check the pictures attached , i really am not able to understand an algorithm.

    Thanks
    Attached Images Attached Images    
    Last edited by startingc; 05-02-2010 at 04:06 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    First, you should read this -> SourceForge.net: Indentation - cpwiki
    and then repost some readable code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4
    i already said i am a beginner !!! and i am trying my best to grasp the topics

    thanks though for ur reply


    @salem

    i am a pure "beginner" ..... if u can't help pls dont criticize ..... thanks
    Last edited by startingc; 05-02-2010 at 04:09 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    If you don't want help, then don't post.

    help / suggest / criticise - it's all the same.
    I just said what needed to be said without a lot of fuzzy words just to make you comfortable.

    Now read this instead
    How To Ask Questions The Smart Way
    Then proceed to read the rest of that FAQ

    FWIW, your edit isn't much of an improvement.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4
    @salem


    listen friend ,

    instead of providing me links to lengthy articles , "please" consider this as a request if you want/can help your most welcome cuz at the moment since i need to understand this program , i need help and i m sorry if u felt i was rude in any way

    thanks again for ur reply .
    Last edited by startingc; 05-02-2010 at 04:33 AM.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So, other than indentation, what is it you're actually having a problem with?


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    This is what your code should look like.
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<time.h>
    
    int main ()
    {
      char maze[12][12];
      int x,y,a,b,c;
      char question;
    
      srand((unsigned) time (NULL));
      printf("******************************************\n"
             "Welcome to the maze game !\t\t *\n"
             "Please note the keys to play the game\t *\n"
             "UP\tDOWN\tRIGHT\tLEFT\t\t *\n"
             "[i]\t[m]\t[h]\t[l]\t\t *\n"
             "******************************************");
      printf("\n\n");
    
      do
      {
        for(a=0;a<12;a++)
        {
          maze[0][a]='#';
          maze[11][a]='#';
        }
        for(b=0;b<12;b++)
        {
          maze[b][0]='#';
          maze[b][11]='#';
        }
    
        for (x=1;x<=10;x++)
          for (y=1;y<=10;y++)
          {
            c=rand()%10;
            if(c>1 && c<6 )
              maze[x][y]='#';
            else
              maze[x][y]='.';
          }
    
        for (x=0;x<12;x++)
        {
          printf("\n");
          for (y=0;y<12;y++)
          {
            printf("%c",maze[x][y]);
          }
        }
    
        printf("\n Press [c] to continue : ");
        fflush(stdin);
        scanf("%c",&question);
    
      }while( question == 'c');
    
      printf("\n");
      printf("\n");
    
      return 0;
    }
    Notice how things like braces line up, and all code at the same functional level is indented to the same level.

    Other problems
    1. You generate a new maze every time around the loop. You need to think about generating a maze just once, then entering another loop to let the user "walk" around the maze (and update the screen accordingly).
    2. Your random placement of # in the interior doesn't guarantee a solvable maze.
    There are some additional descriptions in your graphic which describes how to check for a valid maze. You need an isValidMaze function.

    Starter...
    Code:
    void constructMaze ( char maze[12][12] ) {
    }
    
    int main ( ) {
      char maze[12][12];
      constructMaze( maze );
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If I had to generate a maze, I'd use Eller's algorithm. If you have to solve it, then I'd use the "right hand rule".

    Basics are at "Think Labyrinth" Bottom of the page has a link to code showing more details for examples discussed.

    Google has a wealth of info, as always.

    When you post other code, be sure to keep the width of the lines, shorter than your first one. I couldn't even read it without going through 3 page widths. That just isn't worth it, imo.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    4
    @salem ,

    thank you brother salem for your reply ..... thank you alot but what do you mean by "isValidmaze function" ... i mean i know about creating functions and calling functions to the main program , can you pls expand on "isValidmaze"....

    @adak .... thank you for ur reply

    can i ask , "right hand rule" is some sort of a pre-defined algorithm in C language cuz uptil now i have studied conditions statements , loops , arrays and function calling .... pls tell .
    Last edited by startingc; 05-02-2010 at 06:04 AM.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The left-hand or right-hand rule is just a method for walking through a maze. If you take one hand, and put it on a wall, and keep it on a wall, you should eventually find your way all around the entire thing (provided there are no 'islands'). Or, for example, if when encountering an intersection, you look for paths to go in the same order every time, you should have the same thing. For example: Always go north, if you can, if not, go east, if not, go south, if not go west, making sure you aren't running into the same room over and over.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Go to "Think Labyrinth". It's all there.

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    1
    can i have the full source code??

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    > can i have the full source code??
    No - read the rules, make an effort.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  2. logical progression of scenario
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-10-2003, 06:53 PM
  3. most challenging thing to program
    By volk in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 03-28-2003, 02:56 PM
  4. game programming gurus
    By nickeax in forum Windows Programming
    Replies: 5
    Last Post: 03-16-2003, 07:19 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 12:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21