In this question you will test using a backtracking

Assignment Help Computer Engineering
Reference no: EM13379898

In this question, you will test, using a backtracking algorithm, if a mouse can escape from a rectangular maze.

The backtracking algorithm helps the mouse by systematically trying all the routes through the maze until it either finds the exit or exhausts all possible routes (and concludes that the mouse is trapped in the maze). If the backtracking algorithm finds a dead end, it retraces its path until it reaches a position from which there is an untried path. The backtracking algorithm always tries all directions from any position, and always in the same order.

The input to the algorithm is a maze with walls (represented by '1' characters) and open passage ways (represented by '0' characters). The starting position of the mouse is represented by 'm' and the exit from the maze by 'e'. Your program should read the maze in from a file, and the name of the file should be a command-line argument. The first line of the input will contain the number of rows and the number of columns in a maze. Thus, the input might look like the following:

772_Problem on backtracking algorithm.png

The maze will always have a wall around the outside, so you need not be concerned about the mouse falling off the maze as it explores all directions.

The backtracking algorithm keeps a stack of positions that are the beginnings of paths it has yet to try. From the current position, the algorithm pushes onto the stack any untried open neighboring positions (if there are any), always looking forward, backward, left and right from the current position. At each step, the algorithm pops the top position off the stack and pushes the untried neighboring positions onto the stack. The algorithm must mark each visited position with a period to avoid revisiting positions --- so that it will not
loop forever trying the same routes.

The backtracking algorithm works as follows:

read in the maze;
initialize the stack;
goalCell = the position of the exit in the maze;
startCell = the initial position of the mouse in the maze;

currentCell = startCell;
while currentCell is not the goalCell
mark currentCell as visited;
push onto the stack the unvisited open neighbours of currentCell;
if the stack is empty
the mouse is trapped: we tried all routes and failed to find the exit;
else
pop a cell from the stack and make it currentCell;
end while;
the mouse can escape the maze: we reached the goal cell.

Because the backtracking algorithm needs a stack, you should implement a stack class (or you can use that from COSC 2006). Each item in the stack is the position of a cell in the maze --- that is, the row and column number of the cell.

Your program should print out the maze after each cell is visited, showing which cells have already been visited. Finally, your program must print out a message indicating whether the exit was found or that no route to the exit could be found (the mouse is trapped).

To develop your program, you can use the input file testMaze.txt, which contains the above maze.

- Hand in your complete Java source code; and a copy of the results produced
- Upload your source code to CMS
- Demonstrate your program to TA before/on the due day

Reference no: EM13379898

Questions Cloud

Imagine that you work for a consulting firm that offers : imagine that you work for a consulting firm that offers information technology and database services. part of its core
Security primitivesaexplain the different roles between : security primitivesaexplain the different roles between hashing and message authentication codes mac. can a good hash
Security infrastructure and protocolsapki and pgp are two : security infrastructure and protocolsapki and pgp are two methods for generating and managing public keys for use in
You are required to conduct research and participate in : you are required to conduct research and participate in onlineforum discussions on a topic from the set total of seven
In this question you will test using a backtracking : in this question you will test using a backtracking algorithm if a mouse can escape from a rectangular maze.the
Part ause the prime minister database primeminister2013sql : part ause the prime minister database primeminister2013.sql available from the interact site. answer the following
A prestigious university has recently implemented a : a prestigious university has recently implemented a consolidation strategy that will require it to centralize their
Purpose the purpose of this assignment is to assess through : purpose the purpose of this assignment is to assess through research students capacity to provide an informed consumer
Jaedan industries has the following account balances as of : jaedan industries has the following account balances as of december 31 2010 found on page 64 amp 65 of the text. the

Reviews

Write a Review

Computer Engineering Questions & Answers

  Calculate the access time when there is a cache miss

calculate the access time when there is a cache miss? Assume that the cache waits until the line has been fetched from main memory and then re-executes for a hit.

  Create class complex for working with complex numbers

modify class Complex for working with complex numbers of the form a + bi, where i is square root of -1. Your class must have two overloaded operators for adding and subtracting the complex numbers.

  Database and characteristics of database

Explain the Database and describe the four characteristics of the database? Explain the Relational Database and generate a relational database for 5 employees.

  Calculating the overall class average

It is now the end of the semester and Alberta would like to have a program which inputs each student`s test scores and outputs average score for every students and the overall class average.

  Recognizing the error

Make out error in the following given code:#include //Line 1 using namespace std; //Line 2

  Questiongiven two character strings s1 and s2 using c and

questiongiven two character strings s1 and s2. using c and pthread to write down a parallel program to find out number

  Centralized and distributed data processing

Discuss in detail the difference between the centralized and the distributed data processing.

  Display comments and identified source codes

Write and manually assemble the following programs. All memory addresses include the starting and ending addreses. display comments and identified source codes.

  Take a byte-addressable computer with 24-bit addresses

take a byte-addressable computer with 24-bit addresses, a cache capable of storing a total of 64KB of data, and blocks of 32 bytes. Show the format of a 24-bit memory address for.

  Program to insert the name cervantes

"In the following exercises, suppose that the Simple combo box appears as shown and that the Sorted property is set to True. Give a statement or statements that will carry out the stated task."

  Design the calculate button the accept button

You have been hired by an engineering company to develop software to perform advanced geometric calculation. Your new boss asked you to develop an application that allows engineers to calculate the surface area and the volume of a sphere. For this..

  Describing the penetration test

By using the MS Word, write down the three-page summary explaining a successful penetration test. Which penetration tools and techniques do you think would be required in the successful penetration test.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd