Skip to content

Commit

Permalink
Homework 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaeckroth committed Jan 14, 2014
1 parent aaa54cb commit 95440a6
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 17 deletions.
Binary file added downloads/pacman.zip
Binary file not shown.
115 changes: 115 additions & 0 deletions homework-2.org
@@ -0,0 +1,115 @@
#+SETUPFILE: setup.org
#+TITLE: Homework 2

* Task 1 Preparation

Download this ZIP file with the Pacman source code: [[./downloads/pacman.zip][pacman.zip]]. This
code, and the idea for the assignment, comes from [[http://inst.eecs.berkeley.edu/~cs188/pacman/html/navigation.html?page=p1/p1_introduction][UC Berkeley]].

- Unzip the code.
- Open up the Windows Command Line or Mac Terminal or Linux Terminal.
- Change your directory to the folder with the pacman code. You should
see a file called =commands.txt= and two folders: =layouts= and
=py=.
- Run some of these commands (as listed in =commands.txt=) to make
sure your setup works.
- =python py/pacman.py= (use your arrow keys to control pacman)
- =python py/pacman.py --layout tinyMaze --pacman GoWestAgent=
- etc.

* Task 1 (20 pts)

I want to make sure you can execute pacman. Tell me (in one sentence)
what happens when you run this command:

- =python py/pacman.py --layout tinyMaze --pacman GoWestAgent=

Tell me the last message printed on your console window when you run
this command:

- =python py/pacman.py -l mediumMaze -p SearchAgent -a fn=bfs=

* Task 2 (80 pts)

Open the file =py/search.py= and find the function =depthFirstSearch=
(line 70) which reads:

#+BEGIN_SRC python
def depthFirstSearch(problem):
"""
Search the deepest nodes in the search tree first [p 85].

Your search algorithm needs to return a list of actions that reaches
the goal. Make sure to implement a graph search algorithm [Fig. 3.7].

To get started, you might want to try some of these simple commands to
understand the search problem that is being passed in:

print "Start:", problem.getStartState()
print "Is the start a goal?", problem.isGoalState(problem.getStartState())
print "Start's successors:", problem.getSuccessors(problem.getStartState())
"""
"*** YOUR CODE HERE ***"
util.raiseNotDefined()
#+END_SRC

Take this template and finish the code so that depth-first search
works. You can test it with pacman by running this command:

- =python py/pacman.py -l mediumMaze -p SearchAgent -a fn=dfs=

Note that the comments above the code will be helpful. Submit just
this file (=search.py=) to the Dropbox, along with a text file with
your answers to Task 1.

#+BEGIN_SRC python
def depthFirstSearch(problem):
"""
Search the deepest nodes in the search tree first [p 85].

Your search algorithm needs to return a list of actions that reaches
the goal. Make sure to implement a graph search algorithm [Fig. 3.7].

To get started, you might want to try some of these simple commands to
understand the search problem that is being passed in:

print "Start:", problem.getStartState()
print "Is the start a goal?", problem.isGoalState(problem.getStartState())
print "Start's successors:", problem.getSuccessors(problem.getStartState())
"""
closedset = []
openset = [problem.getStartState()] # openset starts with starting state
parents = {}
while len(openset) > 0:
state = openset.pop() # get most-recently-added element from openset

# ...

if # ...
print "Found goal!"

# retrieve series of steps that brought us here (use the parents map)
actions = []
while state != problem.getStartState():
# ...

print actions # just to see the resulting actions
return actions
else:
for (next_state, action, cost) in problem.getSuccessors(state):
# next_state is something like (4, 2) (coordinates)
# action is something like WEST
# cost is not used for depth-first search
# ...
#+END_SRC

* Task 3 (Extra credit, +25 pts)

Implement breadth-first search for pacman, in the =breadthFirstSearch=
function. Test with:

- =python py/pacman.py -l mediumMaze -p SearchAgent -a fn=bfs=


#+INCLUDE: footer.org

19 changes: 4 additions & 15 deletions index.html
Expand Up @@ -202,21 +202,10 @@ <h1 style="font-size: 3.5em; margin-bottom: 5px; padding-bottom: 10px;">Intro to
<a href="homework-1.html">Homework 1</a>
<span class="due">Due Fri 1/17, beginning of class</span>
</li>
<!--
<li><a href="homework-2.html">Homework 2</a></li>
<li><a href="homework-3.html">Homework 3</a></li>
<li><a href="homework-4.html">Homework 4</a></li>
<li><a href="homework-5.html">Homework 5</a></li>
<li><a href="homework-6.html">Homework 6</a></li>
<li><a href="homework-7.html">Homework 7</a></li>
<li><a href="homework-8.html">Homework 8</a></li>
<li><a href="midterm-1-guide.html">Midterm guide</a></li>
<li><a href="homework-9.html">Homework 9</a></li>
<li><a href="homework-10.html">Homework 10</a></li>
<li><a href="homework-11.html">Homework 11</a></li>
<li><a href="homework-12.html">Homework 12</a></li>
<li><a href="final-guide.html">Final guide</a></li>
-->
<li>
<a href="homework-2.html">Homework 2</a>
<span class="due">Due Fri 1/24, beginning of class</span>
</li>
</ul>

<ul class="index-links">
Expand Down
3 changes: 2 additions & 1 deletion informed-search.org
Expand Up @@ -18,7 +18,8 @@ lecture notes.

4. while the openset is not empty:

a. grab a state from the openset (and remove it)
a. grab a state from the openset (and remove it);
put it in the closedset (since we're now looking at it)

b. if that state is the goal, hey we're done!

Expand Down
3 changes: 2 additions & 1 deletion uninformed-search.org
Expand Up @@ -41,7 +41,8 @@ All searches essentially follow the same algorithm:

4. while the openset is not empty:

a. grab a state from the openset (and remove it)
a. grab a state from the openset (and remove it);
put it in the closedset (since we're now looking at it)

b. if that state is the goal, hey we're done!

Expand Down

0 comments on commit 95440a6

Please sign in to comment.