Results 1 to 9 of 9
Like Tree2Likes
  • 2 Post By DarrylBurke

Thread: How to implement the wall follower algorithm in java?

  1. #1
    michaelnana is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default How to implement the wall follower algorithm in java?

    Hey guys,

    I'm new here. Well I'm working on my homework in java which is about implementing a rat that will traverse through the maze and exit.
    So for my second rat I want to implement a left hand or right hand wall follower rat. i.e the rat will always check to see if there is a wall on the right and move along it.

    The problem is I don't see how I can implement it. The reason I say this is because the rat is just a simple dot. I can't really tell it to move forward. I can say move up which is incrementing the rows or move right which is incrementing the cols so I reall can't figure out the wall follow algorithm.

    I know I would need direction but every implementation of direction I have made so far just gets my rat stuck.

    I'm looking for someone to help me understand the algorithm and how to implement it, like some sort of pseudo code and explanation. That would be greatly appreciated.

    This may help as well. This is how the maze looks like.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    F X X
    X XX XXX X XXXXXXXXXXXXXXXXX X
    X X XXX X X X
    XX X XXX XXXXX XXXXXXXXXXXXX X
    XX X XXX X
    XX X XXXXXXXXXXXXXXXXXXXXXXX X
    XX X XX X XXXX X
    XX X XX XXXXXXXXXXXXXXX XXXX X
    X X XX X X
    X XX XXXXXXXXXXXXXXXX X XXXXXX
    X XX X XXXXXX
    X XXXXXXXXXXXXXXXXXX XXXXXX
    XXXXXXXXXXXXXXXXXXXXXXX XXXXXX
    XXXX XXX XXXXXX
    XXXXXXXXXXXXX XXXXXX XXXX
    X X
    X XXXXX XXXXXXXXXXXXXXXXXXXX X
    X XXXXX X X X XXXXXXXXX X
    X X X X XXXX X XXXXXXXXX X
    X XXXXX X X X X X X
    X X X X X XXXX XXXXXXXXX X
    X X XXXXX X X XXXX XXXXXXXXX X
    X X X X
    X XXXXX X XXXXXXXXXXXXXXXXXXXX
    X X X X
    X X XXXXX XXXX XXXX XXXXXXXX X
    X X XXXX XXXX X X
    XSXXXXXXXXX X X X XX X
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Where the x are the walls.

    So yeah, thanks in advance.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: How to implement the wall follower algorithm in java?

    I can't really tell it to move forward.
    What is the 'forward' direction? You'd need to know which way the rat was facing to determine where the "right" wall is.
    Would going through a hole in the wall set the direction the rat is facing?
    When it moves in any direction, would that set the direction the rat is facing?

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: How to implement the wall follower algorithm in java?

    Crosss posted at How to implement the wall follower algorithm in java? Please be forthright in telling others where else this is posted

  4. #4
    michaelnana is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: How to implement the wall follower algorithm in java?

    As far as I know there is no forward direction. Basically I want it to follow the left wall to the end. That's the reason why I'm kind of stuck. How do I get it to check the wall and move forward as long as there is a wall.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: How to implement the wall follower algorithm in java?

    there is no forward direction
    There has to be a forward direction if you want to talk about going left or right. They are relative to the forward direction.

    How do you define the left wall without knowing which way the rat is facing(the forward direction)?

  6. #6
    michaelnana is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: How to implement the wall follower algorithm in java?

    Well since the maze is basically a 2d array it has rows and columns.
    the left will be the col--
    the right col++
    up will be rows --
    down will be rows++

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: How to implement the wall follower algorithm in java?

    The left,right direction has to be relative to the direction the rat is moving. It can not be a constant as you suggest.

    What if the starting position is column 0? How can the rat ever move?

  8. #8
    michaelnana is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: How to implement the wall follower algorithm in java?

    Hmmm interesting. Ok.

    So how do I keep track of that ?

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

Similar Threads

  1. Brick wall using BLEUJ
    By boumasmoud in forum New To Java
    Replies: 1
    Last Post: 11-03-2011, 10:33 PM
  2. Only one wall block?
    By werner291 in forum New To Java
    Replies: 4
    Last Post: 09-28-2011, 01:47 PM
  3. Wall bug on physics simulation
    By mustachMan in forum New To Java
    Replies: 2
    Last Post: 07-14-2010, 05:56 AM
  4. Using Java To Implement RSA Algorithm
    By Floetic in forum New To Java
    Replies: 3
    Last Post: 03-31-2008, 11:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •