AI Berkeley Solution PDF
AI Berkeley Solution PDF
AI Berkeley Solution PDF
L ab 1
D ue on 27/1/2016 11.55pm
Ins truc tions : Upload to your moodle account one z ip file containing the following. P leas e do
not s ubmit hardcopy of your s olutions . In cas e moodle is not acces s ible email the z ip file to the
ins tructor at ckn@ iitrpr.ac.in. L ate s ubmis sion is not allowed without prior approval of the
ins tructor. Y ou are expected to follow the honor code of the cours e while doing this homework.
1. T his lab s hould be attempted individually.
2. A neatly formatted P D F document with your ans wers for each of the ques tions in the
homework. Y ou can us e latex, MS word or any other s oftware to create the P D F .
3. Include a separate folder named as code containing the scripts for the homework along
with the neces s ary data files .
4. Include a R E AD ME file explaining how to execute the s cripts .
5. Name the Z IP file us ing the following convention rollnumberhwnumber.z ip
S earc h in P ac man
In this as s ignment, you will be experimenting with different AI s earch techniques that w e
dis cus s ed in the clas s in a P acman environment. T his is part of the P acman projects developed
at UC B erkeley [1]. T he P acman agent needs to find paths through the maz e world, both to
reach a location and to collect food efficiently.
Y ou are provided with a s tarter code for this project. T he code cons is ts of s everal P ython files ,
s ome of which you will need to read and unders tand to complete the as s ignment, and s ome of
which you can ignore.
F iles you will edit
search.py
Pacman.py T he main file that runs P acman games . T his file des cribes a P acman G ameS tate
type, which you us e in this project
game.py
T he logic behind how the P acman world works . T his file des cribes s everal
s upporting types like AgentS tate, Agent, D irection, and G rid.
Us eful data s tructures for implementing s earch algorithms
Util.py
F iles you c an ig nore
graphicsDisplay.py
ghostAgents.py
keyboardAgents.py
layout.py
autograder.py
P roject autograder
testParser.py
testClasses.py
test_cases/
searchTestClasses.py
T he z ip file als o includes an autograder s cript for you to grade your ans wers on your machine.
T his can be run with the command:
Python autograder.py
Y ou mus t only include search.py and searchAgents.py as part of the final lab s ubmis s ion.
Y our code mus t be well commented. P leas e do not change the other files or s ubmit other files .
B ut, things get ugly for this agent when turning is required:
In corner maz es , there are four dots , one in each corner. O ur new s earch problem is to find the
s hortes t path through the maz e that touches all four corners (whether the maz e has food there
or not). Note that for s ome maz es like tinyCorners, the s hortes t path does not always go to
the clos es t food firs t! Hint: the s hortes t path through tinyCorners takes 28 s teps .
N ote: Make s ure to complete Ques tion 2 before working on Q ues tion 5, becaus e Q ues tion 5
builds upon your ans wer for Q ues tion 2.
Implement the CornersProblem s earch problem in searchAgents.py. Y ou will need to
choos e a s tate repres entation that encodes all the information neces s ary to detect whether all
four corners have been reached. N ow, your s earch agent s hould s olve:
python pacman.py -l tinyCorners -p SearchAgent -a
fn=bfs,prob=CornersProblem
python pacman.py -l mediumCorners -p SearchAgent -a
fn=bfs,prob=CornersProblem
T o receive full credit, you need to define an abs tract s tate repres entation that does not encode
irrelevant information (like the pos ition of ghos ts , where extra food is , etc.). D o not us e a
P acman GameState as a s earch s tate. Y our code will be very, very s low if you do (and wrong).
H int: T he only parts of the game s tate you need to reference in your implementation are the
s tarting P acman pos ition and the location of the four corners .
O ur implementation of breadthFirstSearch expands jus t under 2000 s earch nodes on
mediumCorners. H owever, heuris tics (us ed with A* s earch) can reduce the amount of
s earching required.
works well, you can check whether it is indeed cons is tent, too. T he only way to guarantee
cons is tency is with a proof. H owever, incons is tency can often be detected by verifying that for
each node you expand, its s ucces s or nodes are equal or higher in in f-value. Moreover, if UC S
and A* ever return paths of different lengths , your heuris tic is incons is tent. T his s tuff is tricky!
N on-TrivialH euristics:T he trivial heuris tics are the ones that return z ero everywhere (UC S ) and
the heuris tic which computes the true completion cos t. T he former won't s ave you any time,
while the latter will timeout the autograder. Y ou want a heuris tic which reduces total compute
time, though for this as s ignment the autograder will only check node counts (as ide from
enforcing a reas onable time limit).
G rading: Y our heuris tic mus t be a non-trivial non-negative cons is tent heuris tic to receive any
points . Make s ure that your heuris tic returns 0 at every goal s tate and never returns a negative
value. D epending on how few nodes your heuris tic expands , you'll be graded:
Number of nodes expanded
G rade
More than 2000
2
At mos t 2000
3
At mos t 1600
4
At mos t 1200
5
R emember: If your heuris tic is incons is tent, you will receive no credit, s o be careful!
-a
Y ou s hould find that UC S s tarts to s low down even for the s eemingly s imple tinySearch. As
a reference, our implementation takes 2.5 s econds to find a path of length 27 after expanding
5057 s earch nodes .
N ote: Make s ure to complete Ques tion 4 before working on Q ues tion 7, becaus e Q ues tion 7
builds upon your ans wer for Q ues tion 4.
for the
G rade
1
3
4
5
6
R emember: If your heuris tic is incons is tent, you will receive no credit, s o be careful! C an you
s olve mediumSearch in a s hort time? If s o, we're either very, very impres s ed, or your heuris tic
is incons is tent.
S ubm is s ion
Include a neatly formatted pdf document that des cribes your heuris tics , and other obs ervations
while implementing the lab.
R eference
[1] http://ai.berkeley.edu/project_overview.html