Like Tree1Likes
  • 1 Post By Salem

build a program, something similar to a maze algorithm

This is a discussion on build a program, something similar to a maze algorithm within the C Programming forums, part of the General Programming Boards category; i have this "test" let's say.. i need to solve this problem, it's not homework but i need it in ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    build a program, something similar to a maze algorithm

    i have this "test" let's say.. i need to solve this problem, it's not homework but i need it in order to pass a test.
    I could need a little help, because i don't understand what i need to do. I need the algorithm here! So it goes: The table below represents a labyrinth. "1" means you cannot pass through that value, "0" means you can pass through that value. "T" is the treasure to achieve and "H" is the entrance. The coordinates are : H(3.1) , T(2.8).
    -I need a program that reads a matrix A[1..M,1..N] which itself represents a labyrinth with elements [0,1] and also reads the H,T value.
    It should print a way to the treasure , if there is one, else it should say "No way to the treasure"he Matrix is:


    Code:
    1 1 1 1 1 1 1 1 1 1    
    1 1 0 0 0 1 0 T 0 1    
    H 0 0 1 1 1 0 1 1 1    
    1 1 0 0 0 0 0 0 0 1    
    1 1 1 1 1 1 1 1 1 1
    I got some pseudocode with someone's help


    Code:
    var walkingDirection = up;
    while (not at target)    
    if (next field in walkingDirection is not a wall)       
     go to next field in walkingDirection    
    else        
    turn right    
    end if
    end while 
    Last edited by Al1229; 03-26-2013 at 12:18 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > i need to solve this problem, it's not homework but i need it in order to pass a test.
    I see a bright future in politics for you, with your apparent ease at redefining words on the fly.

    You're hoping to exchange academic effort (or someone's at any rate) in reward for academic credit (marks, pass, grades etc).
    To me, that's homework.

    Code:
    1 1 1 1 1 1 1 1 1 1    
    1 1 0 0 0 1 0 T 0 1    
    H 0 0 1 1 1 0 1 1 1    
    1 1 0 0 0 0 0 0 0 1    
    1 1 1 1 1 1 1 1 1 1
    Think about what happens when you get to 0
    Think about what happens when you get to 0
    iMalc likes this.
    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
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,264
    The pseudocode you provide is for an algorithm which will not always find the target. E.g. for:
    Code:
    111111111
    100000001
    101011101
    H0101T001
    101011101
    100000001
    111111111
    Also, given it states to loop while not at target, that's going to produce an infinite loop. Not to mention that for the cases where there is no way to the target that will also obviously be an infinite loop.

    There are plenty of maze solving algorithms described on the net. Hop on to your favourite search engine and get searching for something that will actually work.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 04-23-2012, 07:52 AM
  2. Maze Solving algorithm
    By mrJTparadise in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2012, 03:26 PM
  3. Recursive Stack Algorithm Maze Solver
    By unrestricted in forum C Programming
    Replies: 0
    Last Post: 09-04-2007, 03:11 AM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 12:54 AM
  5. Maze game, complete with maze editor and an example maze!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-20-2002, 02:27 AM

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