Advertisement
akosiraff

MazeStackEtc Answer

Oct 28th, 2018
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1.  
  2. Download: https://solutionzip.com/downloads/mazestacketc/
  3. The objective of this lab is to solve problems using the Stack ADT
  4. Q1. Write a program that uses the Stack implementation given to you
  5. in Stack.py to simulate navigation in a web browser. Every web
  6. browser has both a back and a forward button which allows the user to
  7. navigate to previously seen web pages.
  8. Your task is to implement this functionality using two Stack objects
  9. called forward_stack and back_stack. The forward_stack and
  10. back_stack should be used to store and retrieve the urls as the user
  11. navigates the web.
  12. The interaction with your program will be a sequence of commands,
  13. either “>”, “<", "=", or "x". The ">” and “<" commands will be used to indicate forward and back, respectively. The "=" command is used to enter a new url web page. If the user enters the "=", the computer would expect a url address. Finally, if the user enters "x", the program closes. You can assume the web addresses are always valid. • You will not actually have to do any web navigation. You will simply be keeping track of the current page by outputting the address of the current page between "[" and "]". • There are a few situations you should take care to handle. • First, if a user enters "<" or ">” without there being a previous or
  14. next page to go to, you should output a corresponding error
  15. message (as shown in the sample output below) but allow the
  16. user to continue browsing.
  17. • Secondly, if a user enters “<" and then "=" and then enters a new web address, the user's previous browsing history in the ">”
  18. direction should be erased.
  19. • For example, if a user is on “www.google.com”, enters “<", and then enters "=" and then “www.yahoo.com", the history of visiting "www.google.com" should be lost. This means that if the user enters ">“, this should generate an error message and not
  20. “www.google.com”. This behavior can also be seen below in the
  21. sample data. You can also test an actual web browser (specifically
  22. Firefox or Chrome) if you feel there is other ambiguity. Also, keep
  23. in mind that navigation should start with a home page which we
  24. will set as “www.cs.ualberta.ca”.
  25. • The interaction should start with the current page
  26. being www.cs.ualberta.ca.
  27. Q2. Write a program that uses the Stack implementation given to you
  28. in Stack.py to check if there is a solution to a maze or not. If there is a
  29. solution, your program shows the message Goal is reached, if there is
  30. no solution your program shows the message Goal is Unreachable.
  31. A simple maze implementation is given to you in maze.py.
  32. Hint: You don’t need to change anything in file maze.py.
  33. To solve a maze using the Stack, use the following algorithm:
  34. 1. Add the start square to the stack.
  35. 2. Repeat the following as long as the stack is not empty:
  36. • Pop a square off the stack (the current square)
  37. • If the current square is the finish square, the solution has been
  38. found
  39. • Otherwise, get the list of squares which can be moved to from the
  40. current square, and add them to the stack
  41. Description of maze.py:
  42. • The maze.py file has two classes: Maze and MazeSquare. The Maze
  43. class represents the entire maze and the MazeSquare class
  44. represents a single square in the Maze
  45. • You can create a new instance of Maze class by calling the
  46. constructor: my_maze = Maze(file_name), where file_name is the
  47. name of a text file containing a maze.
  48. • You can get the start square of the maze by
  49. calling my_maze.get_start_square(). This method returns an object
  50. of type MazeSquare.
  51. • To check if a square is the finish square,
  52. call my_maze.is_finish_square(square), where square is of type
  53. MazeSquare.
  54. • The get_legal_moves() is a method in the MazeSquare class. This
  55. method returns a list of objects of type MazeSquare that can be
  56. moved to. Let’s say if square is an identifier that is bound to an
  57. object of type MazeSquare then get_legal_moves() can be called in
  58. the following manner:
  59. list_of_legal_moves = square.get_legal_moves()
  60. An algorithm example is given in the given file
  61. MazeAlgorithmExample.gif.
  62. Two maze files are included for this exercise: solvable_maze.txt and
  63. unsolvable_maze.txt. Check your program using these files. Thus, when
  64. you use solvable_maze.txt file, your program should find a solution and
  65. print the message Goal is reached. However, when you use
  66. unsolvable_maze.txt file, your program can’t find a solution and prints
  67. the message Goal is Unreachable. A graphic representation of each
  68. maze file is given in the file MazeExamples.gif.
  69.  
  70. Download: https://solutionzip.com/downloads/mazestacketc/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement