Thread: need help on my c++ idea.

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    61

    need help on my c++ idea.

    hello..i was wondering...
    i want to create in c++ a sensor detecting program..
    it's function is like to analyze which path to take..
    what are the obstacles and which path is the most short in distance to travel.
    the input is like this.. initial place and target place is defined..
    size of the maze or place to travel is given.a bit like pac man game..

    this size is 16 x 5.. S starting point is S and T is final point
    x is the path that can be used..# is the obstacles...
    S x x x # # # #
    x # xx # ###
    X###x########
    xxx##xxxxxxxxxxxx##
    ##xxxx#####T###
    anyone know how to start from this coding idea??
    i am clear on it but need examples please

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    The first very basic thing to do would be to create a C++ "skeleton" file, declare a 2-D array of "char"s, and initialize it to the structure/maze you have above. Do a simple print out of the 2-D array to make sure it indeed is being stored and displayed correctly, i.e. looks exactly the same as above.

    After that you need to start (or continue) on some thorough search algorithms. For starters, you could draw your map out on graphing paper (or create your own matrix on paper), then pretend youre the computer and start from S, pick a random direction to move, go there if you can (i.e. if its an X) and continue this process until you reach T; otherwise if you cant go there (i.e. if its a #), then choose to never go to that spot again and choose a different direction. As your doing this, try to convert what you are doing into C++. This method should work, though would be very slow as its just brute-force (which is why you'd need to look into "real" search algorithms).

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    61
    ok..i get your idea..any example or code snippets that i can see or refer as a example..
    the skeleton file is just a preview of the input is it?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I dont have any code or examples off-hand. I just tried to describe to you a place to start, which is what you asked for, versus just giving you some code that might just make things more confusing if you dont understand what the codes doing. I would try and implement something basic like what I described above, or at least try and do it on paper, like "trace" the program by pretending your the computer and executing the steps the algorithm described above says.

    Also, as I said, my above suggestion is horribly inefficient, which is why you would have to do study up on some search algorithms. Another reason for me not just giving you some of this code, is because they are more advanced and require understanding to make the code even useful, if you are to implement it in your program. I cant think of any algorithms off hand to even suggest for you to start searching, but some key words would be "search algorithm maze" and Im sure you will find examples.

    After you have some code (or even pseudocode, or just an english description), post what you have and what you have problems with. Similarly, if you just find a tutorial/existing code and dont understand it, explain exactly what you dont understand and we will try to help.

    By "skeleton", I just meant a useless (but complete and valid) C++ file, i.e. a "Hello world" (minus the printf("Hello World")). To rephrase my initial suggestion on this: create a C++ file, declare and initialize the 2-D array as you have, and use printf to print it out and make sure the array is initialized and being printed correctly...thats step 1.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Pathfinding

    You should use/learn Astar pathfinding algorithm, it finds shortest path between two points on your map based on obstacles etc, google 'astar pathfinding for beginners for a very good article, i hav done some work on this so maybe search my other posts

    here's the article i mentioned > A* Pathfinding for Beginners

    I would not look into the example code he supplies until you have a good start or even almost completed your own, it will deter you from copying chunks of code, functions or code you are having trouble with is better asked about here than trying to replace by lifting stuff.
    You should try and think it through on paper also, it works better than hacking straight in
    Last edited by rogster001; 10-30-2009 at 02:38 AM. Reason: add link

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Pm me if you like when you get going and i will see if i can help out on your thinking, where i went wrong etc, i got plenty of help on these pages from other members also on this subject

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. project idea ???
    By gemini_shooter in forum C Programming
    Replies: 2
    Last Post: 06-09-2005, 09:56 AM
  2. Have an idea?
    By B0bDole in forum Projects and Job Recruitment
    Replies: 46
    Last Post: 01-13-2005, 03:25 PM
  3. A little problem about an idea, help please
    By louis_mine in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2004, 09:52 PM
  4. totally screwed up idea
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-17-2001, 12:09 PM