COP 3530
Assignment 5
Due: 7
th
Oct 2008
In this problem you will solve the “Rat in a maze problem” (Lecture 12), using Stacks
and Queues.
The maze is given as a 2D array, where '0's are squares the rat can move to; '1's represent
the squares where the rat cannot move to. The coordinates of the square at the top left
corner are (0,0). The coordinates of the square at the bottom right corner are (14,12). The
positive direction of x axis is to the right, and the positive direction of y axis is down.
(0,0)
0
00100000010000
000100100000000
000000011111111
000111001001000
000001100100100
110001100100000
011001100100000
001001100100000
011001000000000
001000111111111
001010000000000
001010001000000
00001001000000
0
(14,12)
You have to implement three methods:
searchStack(int fromX,int fromY,int toX,int toY)
,
searchQueue(int fromX,int fromY,int toX,int toY)
, and
searchStackSmart(int fromX,int fromY,int toX,int toY)
, which
find a path from
(fromX,fromY)
to
(toX,toY)
, simulating the actions of a rat using
the following strategies:
searchStack:
A rat that always attempts to move in a specific order:
right, down, left,
up. This method should be implemented using a stack.
searchQueue:
On a given square, the rat reproduces, and up to four rats take one step
away from the current square, each rat in a different direction. Each of these rats will
choose one direction: right, down, left and up. This method should be implemented using
a queue.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
searchStackSmart:
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 Davis
 Algorithms, Data Structures, Leftwing politics, ASCII, toX,int toY

Click to edit the document details