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.


  1. Create the maze randomly.
  2. The mouse must goes thru all the paths it can go.
  3. But it cannot repeat the same path otherwise it won't stop.
  4. 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.

  1. 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.
  2. 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.
  3. Mark each location that the mouse has gone thru.
  4. 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.
  5. When the stack is out, stop the program.
  6. 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