Lab 07 – 3D Maze.

Slides:



Advertisements
Similar presentations
Chapter Objectives To learn about recursive data structures and recursive methods for a LinkedList class To understand how to use recursion to solve the.
Advertisements

More on Stacks and Queues. As we mentioned before, two common introductory Abstract Data Type (ADT) that worth studying are Stack and Queue Many problems.
CIS 101: Computer Programming and Problem Solving Lecture 9 Usman Roshan Department of Computer Science NJIT.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Chapter 13 Linked Structures - Stacks. Chapter Scope Object references as links Linked vs. array-based structures Managing linked lists Linked implementation.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Notes Ch. 12—Creating Tables Web Page Design. Why Use Tables? Tables are used to create a variety of items such as calendars, charts, and spreadsheets.
CHAPTER 4 RECURSION. BASICALLY, A METHOD IS RECURSIVE IF IT INCLUDES A CALL TO ITSELF.
Chapter 5 Recursion. Basically, a method is recursive if it includes a call to itself.
Stacks Chapter 8. Objectives In this chapter, you will: Learn about stacks Examine various stack operations Learn how to implement a stack as an array.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Applications of Stacks and Queues Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
Kruse/Ryba ch051 Object Oriented Data Structures Recursion Introduction to Recursion Principles of Recursion Backtracking: Postponing the Work Tree-Structured.
TOWERS OF HANOI. : If n = 1, move disk 1 from pole 'A' to pole 'B'. else: 1.First, move n-1 disks from pole 'A' to pole 'C', using pole 'B' as.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
1 Tirgul 11: Recursion & Backtracking. 2 Elements of a recursive solution (Reminder) A base case that is so simple we need no computation to solve it.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
C ++ MULTIPLE CHOICE QUESTION
CHAPTER 4: Linked Structures
Pointers and Linked Lists
5.13 Recursion Recursive functions Functions that call themselves
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Excel Training - Part One
Recursive Exploration II
Andy Wang Object Oriented Programming in C++ COP 3330
Inheritance and Big O And your first reading assignment
CMPT 120 Topic:  Case Study.
CSCI 104 Backtracking Search
Binary Search Trees (Continued)
Problems with Linked List (as we’ve seen so far…)
Fundamentals of Programming II Backtracking with Stacks
Stack and Queue APURBO DATTA.
Java Software Structures: John Lewis & Joseph Chase
Chapter 6 Working with Publisher Tables
Monday, March 19, 2018 Announcements… For Today… For Next Time…
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Chapter 4 Linked Structures - Stacks
Lab 06 – Railroad.
Chapter 6 – Queues and Deques
8.1 Tree Terminology and Applications
Lab 08 - BST.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Lab 10 - Quicksort.
7.4 Problem Solving with Recursion
10 – Iterators C++ Templates 4.6 The Iterator pgs
Array Lists Chapter 6 Section 6.1 to 6.3
Chapter 12 Recursion (methods calling themselves)
Lab 04 – Linked List.
Wednesday, April 11, 2018 Announcements… For Today…
Object Oriented Programming COP3330 / CGS5409
Discussion section #2 HW1 questions?
Graph Implementations
Chapter 4 Linked Structures - Stacks
Linked List (Part I) Data structure.
Chapter 9 One-Dimensional Arrays
Search,Sort,Recursion.
adapted from Recursive Backtracking by Mike Scott, UT Austin
Lecture 13: Two-Dimensional Arrays
Review Session Biggest discrepancy questions
Pointers & Dynamic Data Structures
Search,Sort,Recursion.
Dynamic allocation (continued)
Fundamentals of Using Excel
EECE.2160 ECE Application Programming
Lab 03 – Linked List.
16 – Sequential Containers
8.1 Tree Terminology and Applications
Presentation transcript:

Lab 07 – 3D Maze

3D Maze 3D Maze "Two SCUBA diving buddies have encountered a large, box-shaped storage facility inside the hull of the Heian Maru, a 512' submarine tender lying on the bottom of Truk Lagoon at 108'. The storage facility is composed of cells, some of which can be entered and some which cannot. The only exterior walls that are missing are on the front of the storage facility in the upper left corner, and on the rear of the storage facility in the lower right corner. The divers wish to determine a path through the storage facility. Use recursion to find a path through the maze or to prove that there is no path."

Finding a Path through a Maze 3D Maze Problem Use backtracking to find and display the path through a maze. From each point in a maze you can move to the next cell in a horizontal or vertical direction if the cell is not blocked. Analysis The maze will consist of an array of cells. The starting point is at the top left corner maze[0][0][0]. The exit point is at the bottom right corner, that is maze[HEIGHT - 1][WIDTH - 1][LAYERS - 1]. All cells on the path will have a OPEN value. All cells that represent barriers will have a BLOCKED value. Cells that we have visited will have a TEMPORARY value. If we find a path through the maze, the exit cell value will be EXIT and all cells on the path will have the PATH value.

The Maze Layout 3D Maze The maze size is defined by height x width x layer as specified on the first line of the test file. Width Left Right START 0,0,0 0,1,0 0,2,0 0,3,0 1,0,0 1,1,0 1,2,0 1,3,0 2,0,0 2,1,0 2,2,0 2,3,0 3,0,0 3,1,0 3,2,0 3,3,0 Layer Out IN 0,0,1 0,1,1 0,2,1 0,3,1 1,0,1 1,1,1 1,2,1 1,3,1 2,0,1 2,1,1 2,2,1 2,3,1 3,0,1 3,1,1 3,2,1 3,3,1 0,0,2 0,1,2 0,2,2 0,3,2 1,0,2 1,1,2 1,2,2 1,3,2 2,0,2 2,1,2 2,2,2 2,3,2 3,0,2 3,1,2 3,2,2 3,3,2 Down Up Height 0,0,3 0,1,3 0,2,3 0,3,3 1,0,3 1,1,3 1,2,3 1,3,3 2,0,3 2,1,3 2,2,3 2,3,3 3,0,3 3,1,3 3,2,3 EXIT 3,3,3

The Maze Layout 3D Maze The maze size is defined by height x width x layer as specified on the first line of the test file. Width Left Right (START) (Open) 1 (Blocked) Layer Out IN (Open) 1 (Blocked) (Open) 1 (Blocked) Down Up Height 1 (Blocked) (Open) (Exit)

The Maze Layout (Bonus) 3D Maze Maze values tell which way to proceed thru the maze ("L", "R", "U", "D", "I", or "O".) Width Left Right R (Right) I (In) (Open) 1 (Blocked) Layer Out IN I (In) L (Left) 1 (Blocked) (Open) R (Right) I (In) 1 (Blocked) (Open) Down Up Height 1 (Blocked) D (Down) R (Right) E (Exit)

Dynamic Arrays 3D Maze A dynamic array is basically an array of pointers to arrays. A 2 dimensional dynamic array is created/deleted using a loop as follows: int height = 10; int width = 10; int **myArray = new int*[height]; for(int i = 0; i < height; ++i) { myArray[i] = new int[width]; } Constructor for(int i = 0; i < height; ++i) { delete [] myArray[i]; } delete [] myArray; Destructor

The Maze Array 3D Maze The 3D maze array is of data type "int***" - a pointer to a pointer to a pointer to an int. int** int* int int*** maze_ int maze[3][2][2]

2D Implementation bool find_maze_path(int height, int width) { // check boundary (base case #1) if ((height < 0) || (height >= HEIGHT) || (width < 0) || (width >= WIDTH)) return false; if (maze_[height][width] != OPEN) return false; // blocked (base case #2) if ((height == HEIGHT - 1) && (width == WIDTH - 1)) maze_[height][width] = EXIT; // Success! (base case #3) return true; } maze_[height][width] = PATH; // Recursive case if (find_maze_path(height - 1, width) || find_maze_path(height + 1, width) || find_maze_path(height, width - 1) || find_maze_path(height, width + 1)) return true; maze_[height][width] = TEMPORARY; return false;

Requirements 8 (+2) 2 8 5 Trees Points Requirement (45 + 8 Points) Backtracking used to correctly solve a 4 x 4 x 4 maze (lab07_in_01.txt). Backtracking used to correctly solve a 5 x 5 x 5 maze (lab07_in_02.txt). Backtracking used to correctly solve a 5 x 10 x 6 maze (lab07_in_02.txt). Backtracking used to correctly solve a large maze. BONUS: Your maze program outputs the solution path using 'L' for move left, 'R' for move right, 'U' for move up on the same layer, 'D' for move down on the same layer, 'I' for move to the next layer (layer + 1), and 'O' for move to the previous layer (layer - 1). In addition, 'E' indicates the exit point. 8 Your Maze program uses backtracking to detect an unsolvable maze (lab07_in_05.txt). 5 No Memory Leaks in any test. Points Peer Review 2 A Maze class contains a dynamically sized 3-dimensional maze array as specified by the first line of the input file. The Maze class is derived from the abstract MazeInterface interface class. No STL container is used anywhere in your Maze class. The Maze toString() function returns a formatted string of the maze (as described above.)