reset password
Author Message
rabbott
Posts: 1649
Posted 12:52 Sep 08, 2019 |

Hint on Q5: Finding All the Corners.  Your state should keep track of both pacman's position and either the corners visited or the corners yet to be visited depending on how you write your code. You will want to keep a closed set to avoid repeating states. The closed set can be a set of tuples -- but only if the tuple elements are themselves hashable. To be hashable an object must be immutable. But sets are mutable. One solution is to use a frozenset, which you unfreeze as needed.

Hint on Q6: Corners Problem: Heuristic. One reasonable heuristic is the shortest path from the current position through all the unvisited corners. 

Hint on Q7: Eating All The Dots. To reduce the node count, consider using mazeDistance (in searchAgents.py) instead of manhattanDistance. (That seems to me to be something of a cheat, but it solves the problem.) In addition, an interesting heuristic is the maximum distance between any two uneaten food dots plus the distance from pacman to the closest of those two dots. Using these two hints I got the extra credit point and expanded fewer than 400 nodes, more than an order of magnitude smaller than required for the extra credit! But the time required to run the search was more than an order of magnitude longer! The time was not too long for the autograder, though. If you can find a better estimate of the distance between two board positions, that would be better. For example, how about the manhattanDistance along with a penalty for every wall one would cross to use a manhattanDistance path?

Now that I think about it, there is a far better approach: use a cache for mazeDistance. See the comments in the code under foodHeuristic. When I did that for the "trickyFood" layout, the number of nodes expanded was 353, and the total time was 0.4 sec! (The trickyFood layout is in the file test_cases/q7/food_heuristic_grade_tricky.text I created a layout in the layouts folder with that layout so that I could run it directly.)

To use a cache, mazeDistance must check to see whether the distance between two points is already in the cache. If so, return it. Otherwise, compute the distance and put it into the cache before returning it. You will have to add an additional cache parameter to mazeDistance.)

Hint on Q8: Suboptimal Search. It really is as trivial as the question implies. Look at mazeDistance to see how you can create and solve subproblems. 

Last edited by rabbott at 09:16 Sep 12, 2019.
iamrajakumar
Posts: 9
Posted 01:29 Sep 18, 2019 |

Thanks for the hints on question 7 and how to get extra credit. Finally was able to make it work with autograder. Attached the code for reference. 

Please check for foodHeuristic function ~line 226

 

#### Results ###


Finished at 1:16:04

Provisional grades
==================
Question q1: 3/3
Question q2: 3/3
Question q3: 3/3
Question q4: 3/3
Question q5: 3/3
Question q6: 3/3
Question q7: 5/4
Question q8: 3/3
------------------
Total: 26/25

Attachments: