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

  Massive social-economic and political movement focused

A massive social, economic, and political movement focused on eliminating discrimination began on December 1, 1955 when ________ refused to give up her seat to a white man on a bus as the law required her to do.

  Forensic evaluations in the treatment setting

Forensic evaluations in the treatment setting are typically comprised of several components relevant to the selection of the treatment course. The major highlights of the forensic evaluation are different from clinical evaluations conducted in non-fo..

  Regulates product safety-make at least one recommendation

Analyze the ways in which the U.S. government regulates product safety and make at least one recommendation for how the regulatory approach of one of the agencies discussed (FDA, CPSC, or NHTSA) could be improved. Explain your rationale

  NSA terrorist surveillance program

Due to the recent revelations about the NSA terrorist surveillance program, several citizen groups in your city are concerned about their privacy rights, specifically whether law enforcement will be able to conduct warrantless searches, wiretaps, e-m..

  Operated through centralized bureaucracie

The economies of countries such as Russia and China have historically been operated through centralized bureaucracies. Recommend what can be done to infuse such economies with a commitment to corporate entrepreneurship and the innovation resulting fr..

  Good strategic sense-value chain activities

Does it make good strategic sense for Apple to be a competitor in the computer, personal media player, smartphone, and tablet computer industries? Are the value chain activities that Apple performs in computers, personal media players, tablet compute..

  Aspects of cognitive performance

Describe the impact of the following drugs on the different aspects of cognitive performance.

  Sculpture reappears in romanesque

Sculpture "reappears" in Romanesque Europe. State why this is and pick one sculptural work to discuss.

  Skip company produces a product called lem

Skip Company produces a product called Lem. The standard direct material cost to produce one unit of Lem is four quarts of raw material at $2.50 per quart. During May 2013, 4,200 quarts of raw material were purchased at a cost of $10,080

  Case study-scenario of an adolescent girl

Create a case study/scenario of an adolescent girl in which you describe the persons, (her) physical changes and her experiences and the effect those changes on her sexuality, relationships, and self-concept.

  A feed stream of pure liquid water enters an evaporator

A feed stream of pure liquid water enters an evaporator at a rate of 0.75 kg/s. Three streams come from the evaporator: a vapor stream and two liquid streams.

  Aircraft solutions or quality web design company

Phase II – the Course Project (comprised of Phase I and II) – Recommend solutions to the potential weaknesses from either the Aircraft Solutions or Quality Web Design Company

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