Sie sind auf Seite 1von 18

PRESENTS

File
STRUCTURE
Assignment ONE

MAZE
BLAGWA
MAZE
Identification

By : Mahmoud Fayyaz Num : 73

Notes :

1
Index

1. Problem Statement 3
• Stack 3
• Queue 3
• Solve Maze 4
• Bonus 5

2. Overall System 6
• Description 6
• View 8

3. System under Microscope 9


• Required 9
 Stack 9
 Queue 11
 Stack Maze Solver 13
 Queue Maze Solver 14
• Bonus 15
 Maze Generator 1 15
 Maze Generator 2 16
• Complementary 17
 Path Validator 17
 Maze Validator 17
 Maze Viewer 17

2
Problem
Statement

• Required to implement a stack (LIFO ADT).


• Behavior of the stack:
 Push(x): insert element x to the stack.
 Pop(): retrieve and remove last inserted
element in the stack.
 isEmpty(): return if the stack is empty or
not.
 Sizeof(): return the current number of
elements in the stack.
 Empty(): clears the stack.

• Required to implement a queue(FIFO ADT).


• Behavior of the queue:
 Push(x): insert element x to the queue.
 Pop(): retrieve and remove first inserted
element in the queue.
 isEmpty(): return if the queue is empty or
not.
 Sizeof(): return the current number of
elements in the queue.
 Empty(): clears the queue.

3
Problem
Statement

• required to write a program to solve a simple


maze game.
 Maze will be represented as a 2D matrix
with the following properties:
• Each cell in the matrix may be an
open space or a wall.
• Start point is the upper left cell, and
end point is the lower right cell
(Both cells must not be walls).
• There must be at least one solution
for the maze (i.e. a road of open
spaces from start point to end
point).
 The target of your program is to find a
solution of the maze with two methods,
the first one using your stack and the
second one using your queue.
 The input to your program should be a
file maze.txt, its format will be as the
following:
• It will contain comma separated
numbers.
• The first number is the number of
rows.

4
Problem
Statement

• The second number is the number of


columns.
• The following numbers are the 1-
based indices of a row major
representation of the wall cells.
 The output of your program should be
two files out_stack.txt, out_queue.txt.
Output files should contain comma
separated numbers. These numbers are
the 1-based indices of a raw major
representation of a valid solution of the
maze.

• Make an option in your program to randomly


generate a valid maze. Input in this case will
be only the size of the maze (i.e. number of
rows and number of columns). You should
give a visual way to test the generated maze.

5
Ovarall system

• The System Consists of 23 file:


 6 (dot)exe files:
• AssignmentOneFileStructureStackIm
p.exe to test the stack alone.
• AssignmentOneFileStructureQueueI
mp.exe to test the queue alone,
• AssignmentOneFileStructureStackVe
rsion.exe to solve the maze using
stack,
• AssignmentOneFileStructureQueueV
ersion.exe to solve the maze using
queue.
• MazeGenerator.exe to generate
random maze.
• MazeGenerator(2).exe to generate
random maze.
 5 (dot)jar files:
• PathCorrectnessChecker1BasedRow
Major.StackVersionjar.jar To check
validity of the stack path.
• PathCorrectnessChecker1BasedRow
Major.QueueVersionjar.jar To check
validity of the queue path.

6
Ovarall system

• CommaToSpaceAdjustor.jar To
adjust the input.
• MazeCheck.jar To check validity of
the maze
• MazeView.jar To view the maze
 12 I/O Files
• StackTestCasesInput.in
• StackTestCasesOutput.out
• QueueTestCasesInput.in
• QueueTestCasesOutput.out
• MazeGeneration.in
• Maze.in
• MazeCheck.out
• MazeView.out
• StackMazeSolverOutput.out
• StackMazeSolverCheckResult.out
• QueueMazeSolverOutput.out
• QueueMazeSolverCheckResult.out

7
Ovarall system

8
Under
Microscope

• Stack
Structure Node
parameter : element => Data to store
Next Pointer to a structure => Next in the line

Class Stack
Description : Stack is a linked LiFo Data
Structure implemented the Dummy header
Node linked list
Parameter : size integer => number of
elements in the stack
head Pointer to a structure => The first
Dummy Node in the stack
Behavior : Pop => to get the last inserted
element in the stack and remove it from the
stack
push => to insert in the stack
top => to get the last inserted element in the
stack without removing it
getSize => to get the number of element that
the stack store till now
inEmpty => return true if the size = zero
other wise return false

9
Under
Microscope

• Stack
Main
=> for testing the stack
step 1 : read from file "StackTestCasesInput"
step 2 : read the operation
step 3 : write the result in
"StackTestCasesOutput.out"

-> the operation code


1 => Push => it takes the first number in the
file and push it in the stack
2 => Pop => write and remove the last
inserted element
3 => top => write without removing
4 => size => write the number of elements in
the stack
5 => isEmpty => Write true or false

10
Under
Microscope

• Queue
Structure Node
parameter : element => Data to store
Next Pointer to a structure => Next in the line
Prev Pointer to a structure => Prev in the line

Class Queue
Description : Queue is a linked fiFo Data
Structure implemented the Dummy header
and footer Node linked list
Parameter : size integer => number of
elements in the queue
head Pointer to a structure => The first
Dummy Node in the queue
head tail to a structure => The last Dummy
Node in the queue
Behavior : dequeue => to get the first
inserted element in the queue and remove it
from the queue
enqueue => to insert in the queue
first => to get the first inserted element in
the queue without removing it
getSize => to get the number of element that
the queue store till now
inEmpty => return true if the size = zero
other wise return false
11
Under
Microscope

• Queue
Main
=> for testing the stack
step 1 : read from file
"QueueTestCasesInput.in"
step 2 : read the operation
step 3 : write the result in
"QueueTestCasesOutput.out"

-> the operation code


1 => enqueue => it takes the first number in
the file and enqueue it in the Queue
2 => dequeue => write and remove the first
inserted element
3 => first => write without removing
4 => size => write the number of elements in
the queue
5 => isEmpty => Write true or false

12
Under
Microscope

• Stack Maze Solver


get Start , end
Visit(Start)
Stack.push(start)
While (not stack.isEmpty)
{
if (Stack.top() = end) break;
current =
validNeighbour(Stack.top)
if (not current exist)
{
Stack.pop();
continue
}
stack.push(current)
}
vaildNeighbour(current)
{
if (current has right unvisited )
return the right
if (current has down unvisited )
return thedown
if (current has lift unvisited )
return the left
if (current has up unvisited )
return the up
} 13
Under
Microscope

• Queue Maze Solver


get Start , end
Visit(Start)
Queue.enqueue(Start)
While (not Queue.isEmpty)
{
current = Queue.dequeue()
Visit and enqueue all valid
unvisited neighbours
if (end is one of valid neighbor)
break
}

• //Queue
• Order = n^2
• Gets always the shortest path
• Constant (time of execution depend only on
n)
• //Stack
• Order = n^2
• Not a condition to get the shortest path
• Execution time vary (from 2n to n^2)

14
Under
Microscope

• Maze Generation
Get x, y
Array maze[x*y]
Fill maze = wall
For(I 0:x*y)
{
maze[i]=free
if (i in the first row)
maze[i+1]=free
else if(I on the last column)
maze[i-y]=free
else
random
if (random)
maze[i+1]=free
else
maze[i-y]=free
}
maze[x*y-1]=free

15
Under
Microscope

• Maze Generation(1)
Get x, y
Array maze[x*y]
Fill maze = wall
For(I 0:x*y)
{
if(I in an odd row)continue
maze[i]=free
if (i in the first row)
maze[i+1]=free
else if(I on the last column)
maze[i-y]=free
else
random
if (random)
maze[i+1]=free
else
maze[i-y]=free
}
maze[x*y-1]=free

16
Under
Microscope

Complementary
• Path Validator
Check if
1) The path starts at the start point
2) The path doesn’t jump
3) The path doesn’t hit a wall
4) The path ends at the end point
• Maze Validator (fluid fill)
Color the start with special color
Color the neighbours with the same
color
return start color = end color
• Maze View
Loop on the maze input
If wall print X
Else print *

17

Das könnte Ihnen auch gefallen