Find the quickest way out of the maze

Assignment Help Other Subject
Reference no: EM13334952

In this assignment you will develop an animated application that uses depth-first and breadth-first searches as the basis of the implementation.

Go to Stream and download the files

mazegame.py
mazeclass.py
Set up a new project in Eclipse and add these files to it.

mazegame.py is a program that implements the beginnings of a game about finding a way through a maze. When you run this program, you will see a screen, 1000 pixels wide by 500 pixels high, displaying a maze. In our game, the maze is a two-dimensional structure with walls and paths. A character, called Theseus, is placed somewhere in the maze and has to follow the paths to achieve the goals of his missions. The paths can branch, which means that Theseus has choices where to go next. As for his missions, he has to achieve the following:

1. Walk through the maze in a systematic way such that eventually he has visited all locations that are reachable from his initial position.
2. Find his way out of the maze.
3. Find the quickest way out of the maze.

To achieve the first mission, Theseus performs a depth-first search from his current location, and after he has done so, returns to his current position. He marks the locations that he has visited with a special token, and the ones he has revisited with another special token.
For the second mission, Theseus traverses the maze in his mind without actually marking locations - he has a good memory of the maze - to find his way to the exit. When doing so, he has two choices. He can record the path taken on a stack, which he then uses to build the path to actually walk to the exit, or alternatively, he can set a parent attribute for each cell in the maze that he visits, then once he finds the exit, he can follow the parent references to build the path that he uses to walk to the exit.

For the third mission, Theseus traverses the maze in his mind again. To find the shortest path to the exit he can use a breadth-first search, where he records the cells that he visits in a queue. Each cell added to the queue should have the parent attribute set to be location of the cell that caused it to be added to the queue. Once Theseus finds the exit, he can follow the parent references to build the shortest path to the exit. Alternatively, Theseus can search recursively and set a cost attribute for each cell that he visits. This records the shortest distance that he has had to travel to reach the cell. Whenever he comes upon a cell that he has visited previously, he compares the cost value for the cell with his current path cost. If his current path cost to the cell is smaller than that recorded, he updates both the parent reference and the cost for the cell and continues his search from that cell. Otherwise, if his current path cost to the cell is larger than or equal to that recorded, he ignores the cell as he continues his recursive search. Once Theseus has completed his search, he can again follow parent references to build the shortest path to the exit.

mazeclass.py uses a two-dimensional grid (list of lists) to represent the maze. Each list item is a cell, with attributes status, parent and cost. The values for the status attribute have the following meaning:

• 0 The location is part of a path and has not been visited by Theseus before.
• 1 The location is part of a wall and therefore cannot be visited.
• 2 The location is part of the perimeter of the maze and therefore cannot be visited.
• 3 The location is part of a path and has been visited by Theseus.
• 4 The location is part of a path and has been revisited by Theseus (i.e., visited for a second time).
• 5 The location is part of a path and has been examined by Theseus in his mind.
• 6 The location is the exit square.

The constructor for a maze uses a two dimensional integer array of status values to build the maze, and places Theseus at a random location in the maze. To test your program using different mazes you can insert different two dimensional integer arrays as values for the mazegrid variable in mazegame.py. The code has a number of methods that are used to display the maze, which you can use as is, or alter to your liking.

mazegame.py includes headers for the three functions that you are supposed to implement:
def dfs(i, j):
...

This function performs the depth-first search and changes the entries in the maze grid appropriately. It also takes care of displaying the maze and providing a time delay after each change. An easy way to do this is by including the following code:

the_maze.display_maze(screen)
pygame.time.delay(200)
pygame.display.flip()

def setpath(i, j):
...
This function looks for the exit in the maze without initially changing the display of the maze. It changes the entries for the locations in the maze that have been examined from 0 to 5. It also keeps track of the path, which is then displayed step by step at the end of the procedure.

def shortestpath(i, j):
...
This function looks for the shortest path to the exit in the maze without initially changing the display of the maze. It also keeps track of the path, which is then displayed step by step at the end of the procedure.

You can invoke these functions by pressing the 'd, 's' or 'q' keys, respectively. The main game loop takes care of recognizing key presses and allowing to quit the program. The maze is reset to its initial state before each invocation of one of the three functions.

Reference no: EM13334952

Questions Cloud

What force must be applied to the chain : During a testing process, a worker in a factory mounts a bicycle wheel on a stationary stand and applies a tangential resistive force of 115 N to the tire's rim. what force must be applied to the chain
Explain sample of a noble gas occupies a volume : A 1.07 g sample of a Noble gas occupies a volume of 363 mL at 35°C and 678 mmHg. Identify the Noble gas in this sample? A) He B) Ne C) Ar D) Kr E) Xe
How long does the laundromat have to wait : The Corner Cleaners 24-hour laundromat has 16 washing machines.
What is the angular acceleration of the cylinder : A solid cylinder is mounted above the ground with its axis of rotation oriented horizontally. What is the angular acceleration of the cylinder
Find the quickest way out of the maze : To achieve the first mission, Theseus performs a depth-first search from his current location, and after he has done so, returns to his current position.
Find overall capitalization rate using band-of-investment : You borrow $75,000 for 30 years at 11% interest compounded annually. The value of the property is $100,000, PGI= $20,000, vacancy rates are 8%, and operating expenses are $81,000.
Determine the mass of this canister : An astronaut in space cannot use conventional means, such as a scale or balance to determine the mass of an object. What is the mass of this canister
Calculate the spacing between the slits of the grating : The wavelength of the laser beam used in a compact disc player is 483 nm. Estimate the spacing between the slits of the grating
Explain the ph of the resulting solution equal : Calculate the pH after 37.9 mL of NaOH has beed added. pH= ______. At what volume (in mL) of NaOH added does the pH of the resulting solution equal 7.00? Include the units of mL in your answer.

Reviews

Write a Review

Other Subject Questions & Answers

  Effort to unionize a company is often accompanied

Minimizing costs of inputs relative to the price of inputs is an important goal for. Elections in units where employees are not currently represented are called. The effort to unionize a company is often accompanied by

  Describe neurotransmitters in terms

Describe neurotransmitters in terms of what they are, their general function within the body, and their impact on behavior. Discuss the connection between neurons and neurotransmitters.

  Distribution of the number of bagel customers

A baker wants to know how many dozens of bagels to bake each day in order to maximize pro?t. For any given day, the probability distribution of the number of bagel customers is given by

  Explain identical genetically local group like italian-kurd

Humans are 99.9% identical genetically. Of tiny amount of difference which exists, 85% is found in any local group, be they Italians, Kurds, or Cherokees.

  Discussing the uniform commercial code warranty stipulations

What UCC warranties were breached by the dealer? What is the effect of the dealer's knowledge or lack of knowledge of the facts at issue?

  Supply chain management a logistics perspective

Supply Chain Management A logistics perspective. Case 3-1 Red Fish, Blue Fish, LLP: A Sequel 1. What are the advantages and potential disadvantages to Red Fish, Blue Fish of having China

  After tax cash flows-what are the economic life

The PW of the ATCF (After Tax Cash Flows) through year k, PWk, for a defender (three-year remaining useful life) and a challenger (five-year useful life) are given in the following table:Year 1 PW of ATCF through year k, PWk: Defender -$14,020, Chall..

  Explain strain theory

Explain "strain theory," what are the sources of strain, and how do people cope with it?

  Identify the three elements the supreme court recognized

Identify the three elements the Supreme Court recognized that must be present to order for necessity to succeed as a defense

  Forensic psychologist employed

You are a forensic psychologist employed in a state psychiatric facility. The client was committed to your facility for restoration of competency after the judge determined him incompetent to stand trial. He has been a patient at the facility for 3 m..

  What is negotiation

What is negotiation? What are the common negotiation pitfalls? What are the strategies to overcome them?

  Resource loading-how does it differ from resource leveling

What is resource loading? How does it differ from resource leveling?

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