In this lab you will implement the A* algorithm for the domain in labs 2 and 3.
You will work in pairs on this lab (with provision for sections with an odd number of students). You can start with the lab 3 solution written by either student. It is expected that you will talk through the development together.
Modify your Lab 3 solution by adding two methods to Rat
:
astar_path_to(self, target_location: Room) -> List[Room]
"""Returns the list of rooms from the start location to the
target location, using A* search to find the path."""
astar_directions_to(self, target_location: Room) -> List[str]
"""Return the list of room names from the rat's current location to
the target location. Uses A* search."""
rooms_visited_by_last_search(self) -> List[str]
"""Return the list of rooms visited (in any order)"""
As before, talk to your instructor if you do not have a working solution to lab 3; we will be happy to help you debug your lab 3 solution to where it can serve as a start for lab 4.
We did have to make a few more changes to existing files. Download the new versions:
dungeon.py
: This has been modified to add additional methods to check the validity of a path and so that rooms have coordinates.test_lab4.py
: a version of the tests from lab 3. This version supports A*. It also prints all rooms visited by the rat in alphabetical order (so the order they were visited does not matter).lab4_main.py
: a revised version of lab2_main.py
designed for submitting this lab.astar_path_to
.astar_path_to
and astar_directions_to
, to the end of class Rat
.estimated_cost_to
in class Room
. This computes what is known as the manhatten distance: the distance that would be covered while sticking to the streets when going between to locations. This has been implemented by adding a coordinate system to the dungeon.rooms_visited_by_last_search
is used by esubmit to display all of the rooms visited during the search. The various algorithms track this information in different ways; you can probably make the data private or protected and then return that data from this method. Ensure the list is reset on each new search. Warning: still use sets to keep track of which rooms have been visited; you can write rooms_visited_by_last_search
to convert the set into a list.test_lab4.py
contains test code used by esubmit to ensure your solution works. Run those on your own machine before trying to use esubmit.As for lab 3, submit your solution using esubmit. You will submit at least two files, your revised version of rat.py
and the unchanged version of lab4_main.py
. The other two files, the updated dungeon.py
and test_lab4.py
, are already provided by esubmit. If you do try to submit those two files, your version will be ignored.
Only ONE partner needs to submit. If both do submit at
some point - reasonable when doing final debugging! - be sure the final
submission is marked "OFFICIAL SUBMISSION" (in the comment block
of rat.py
) for just one of the two (and maybe submit
an "IGNORE ME" submission for the other partner).
Note: it is likely you will have differences in your output compared to our output on this lab. In particular, the paths you compute for tests 6 and 7 are likely to be different than the paths we compute. This is because the order you visit equal-value rooms is not determined, so your solution is likely to explore slightly different rooms than ours. You may also visit a few rooms extra on test_rat_5
. If you have any question about any differences in your output, contact your instructor.