Results 1 to 9 of 9
- 02-10-2012, 04:56 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
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.
- 02-10-2012, 06:14 PM #2
Re: How to implement the wall follower algorithm in java?
What is the 'forward' direction? You'd need to know which way the rat was facing to determine where the "right" wall is.I can't really tell it to move forward.
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?
- 02-10-2012, 06:28 PM #3
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
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
- 02-10-2012, 06:50 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
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.
- 02-10-2012, 06:52 PM #5
Re: How to implement the wall follower algorithm in java?
There has to be a forward direction if you want to talk about going left or right. They are relative to the forward direction.there is no forward direction
How do you define the left wall without knowing which way the rat is facing(the forward direction)?
- 02-10-2012, 06:58 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
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++
- 02-10-2012, 07:10 PM #7
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?
- 02-10-2012, 07:28 PM #8
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
Re: How to implement the wall follower algorithm in java?
Hmmm interesting. Ok.
So how do I keep track of that ?
- 02-10-2012, 08:42 PM #9
Re: How to implement the wall follower algorithm in java?
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Problem with Code to post a simple message to facebook wall
By Sunanda in forum Apache CommonsReplies: 0Last Post: 01-11-2012, 07:29 AM -
Brick wall using BLEUJ
By boumasmoud in forum New To JavaReplies: 1Last Post: 11-03-2011, 10:33 PM -
Only one wall block?
By werner291 in forum New To JavaReplies: 4Last Post: 09-28-2011, 01:47 PM -
Wall bug on physics simulation
By mustachMan in forum New To JavaReplies: 2Last Post: 07-14-2010, 05:56 AM -
Using Java To Implement RSA Algorithm
By Floetic in forum New To JavaReplies: 3Last Post: 03-31-2008, 11:56 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks