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

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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