The
Mouse in
The Maze
(QBASIC/QuickBASIC)
The problem:
There is a very typical problem in programming -- The Mouse in
The Maze. What you have to do is to create a maze by random and let
the "mouse" (just use a character to represent it such as '@')
to go through the maze. The mouse will go to every path it can go until
it has gone thru all the paths it can go.
- Create the maze randomly.
- The mouse must goes thru all the paths it can go.
- But it cannot repeat the same path otherwise it won't stop.
- Stop the mouse when it has gone thru all the paths.
Solution:
To solve this problem, I made use of "STACK".
The stack is used to record the path that the mouse hasn't gone thru so
that it can come back and continue the journal.
- Use an array to indicate the maze. Each location is for program
to determine if there is a block, or is the way has been gone thru.
- Use an array to indicate the stack. Store each location that the
mouse has just gone that it will come back to the way it came.
- Mark each location that the mouse has gone thru.
- There are 4 directions that the mouse can go. The program will check
if there is any way to go. Marked location is not to be consider.
- When the stack is out, stop the program.
- The source
Return to
QUICKBASIC
FORUM
(Home) (About
Lawrence) (QuickBASIC forum)
(PASSWORD LOCK 1.0)
(My QuickBASIC Library)
~ A sub page of Lawrence's Homepage ~
Last modified on Monday, 21 October 1996
by
Lawrence Law, Spg Rengam, Johore, Malaysia