Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TITLE RECURSIVELY FINDING PATHS THROUGH A MAZE in C++ INTRODUCTION Recursion is a programming technique in which a function calls itself. This project applies recursion

TITLE

RECURSIVELY FINDING PATHS THROUGH A MAZE in C++

INTRODUCTION

Recursion is a programming technique in which a function calls itself. This project applies recursion to a new problem, and illustrates the recursive implementation of backtracking.

DESCRIPTION

Consider finding all paths from an entrance on the top of a maze to an exit on the bottom. This task can be accomplished recursively, so in this project, you design, implement, test, and document a program that calls a recursive function to find a path through a maze.

An array of characters represents a maze: blanks represent corridors, and `+' characters represent walls. Indicate the steps along a path with some other character. The program will read a maze from a data file, identify the path(s) through the maze, and print out each path. There may be more than one path.

INPUT

The program will read the name of a data file from the terminal. A data file will contain the dimensions of a maze and an array of `+'s and blanks that represent the maze. This array must be no larger than 22 rows by 76 columns, so that it can be displayed on a standard terminal screen. The entrance to the maze will always be the second position on the top row, which must therefore be blank. The exit must be on the maze's bottom row. Except for its entrance and exit, the entire perimeter of the maze will be "wall;" there will be no other entrances or exits.

OUTPUT

The program's output will be the maze with a path through it indicated, one such picture of the maze for each path. Direct output to the terminal.

ERRORS

The program should recover gracefully if the user enters the name of an input file that does not exist. Otherwise, it may assume that the input is correct; it need not detect any errors.

EXAMPLE

This is a typical instance of this problem. The input file maze.dat is on the left. Corresponding output might look like the right figure.

20 20 + ++++++++++++++++++ + + ++ +++ +++ ++++++ ++ ++ + +++ +++ ++++ + + ++ ++++++ + +++ ++ ++ ++ + + +++ ++++ ++ ++ + + ++++ ++ +++++ + + + +++ +++ + + ++ + +++ ++++++ ++ + +++++ +++ ++ + +++ ++++ ++ ++ + ++++ +++ + +++ +++++++++++ + ++ +++++++ + ++ +++ ++++++++ + ++ ++++++ + + + +++ ++++++ +++ ++++ +++ +++ +++++++++++++ ++++++ 
A path through the maze: 
+@++++++++++++++++++ 
+@@@@@@@@@@+ ++ +++ +++ ++++++@@@++ ++ 
+ +++@@@@+++@@@@++++ + +@++@++++++@@@@+ +++@@@++@@@@@++ ++@+ +@@@+++ ++++@++ ++@+ +@++++ ++@@@+++++@+ +@ + +++@+++ @@+ +@++ + +++@++++++@++ +@ +++++@@@+++@@@@++ +@+++ @++++@@++ ++ +@@@++++@@@@@@+++ + +++@ +++++++++++ + ++@@+++++++ + ++@+++ ++++++++ + ++@++++++@@@@@@@@+ + + @@@+++@@++++++@+++ ++++@@@@@+++ @@@@+++ +++++++++++++@++++++ 

OTHER REQUIREMENTS

Use a recursive function to identify each step of a path through the maze. Your program should be able to handle mazes of any dimensions up to 22 by 76; read the dimensions of each maze from its file. (The example above is 20 by 20.) Test the program with examples that are at least 16 by 16. Note that larger examples are more entertaining.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

2. Identify and choose outcomes to evaluate a training program.

Answered: 1 week ago