Assignment2 Program
Assignment2 Program
Instructions: Check the instructions in the syllabus. The university policy on academic
dishonesty and plagiarism (cheating) will be taken very seriously in this course. You must
not let other students copy your work outside your group. Discussions of the assignment
is okay, for example to understand the concepts involved. If you work in a group, put
down the name of all members of your group. On your assignment, put down your name,
the number of the assignment and the number of the course. Spelling and grammar count.
For the due date please see our course management server https://courses.cs.sfu.ca .
Programming
We recommend completing this assignment in Python. Mainly because Python code is the
easiest for us to grade, but also because Python has good support for high-level
manipulation of structured objects.
We can accept the languages supported in the CSIL environment, which include C++,
Python, Java, Visual Basic, C#. Your comments on the code should make clear the logic
of your source code even for a reader who may not have programmed in your chosen
language before. It must be possible to execute your code in the CSIL environment, and
you must provide instructions for how to do so. If we cannot run your code, you will lose
marks. Here is some advice for checking the executability.
Group Work. You can work in a group with up to 4 individuals. Please put down the
names of your fellow group members. All team members will receive the same mark.
Part 1: Single-Agent Search in the Wumpus World. 100 points.
Problem Description.
Initial State.
The agents initial location is the square (1,1).
The initial location of 3 pits, 1 Wumpus and 1 pot of gold is specified in an input
file.
The initial locations of the agent, the pits, the Wumpus and the gold are all
different.
State Operators.
The agent can move 1 step sideways in any direction, but not diagonally. For
example, from the square (2,2) the agent can move to the squares (1,2),(2,3),(2,1),
(3,2).
The agent is not allowed to move to a square that contains a Wumpus or a pit.
Goal State.
The agents goal is attained when it reaches the square containing the pot of gold.
The cost of a solution is the number of moves. So an optimal solution reaches the
pot of gold with the minimum number of moves.
Program Description
Input.
The input to your program is a text file called wumpus.txt where each line specifies an
initial location, like this.
Gold=2,3
Wumpus=1,3
Pit=3,1
Pit=3,3
Pit=4,4
Output.
Your program should implement both Depth-First Search and Iterative Deepening Depth-
First Search to find a route to the pot of gold. For each search algorithm, write to screen
the following.
Source Code.
Documentation on how to run your program. This should include at least a
readme file.
Description of two test cases, one where the agent can reach the gold and one
where it cannot. E.g.,
o Show the input file.
o Show a screenshot of how your program reads the input file and what
output it produces.
o Explain why you think that the output is correct.
Grading Criteria
Correctness:
o Program runs and find optimal solution:
o Algorithm implementation (e.g., alpha-beta search).
Quality of documentation: 30%
o Screenshots, readme files.
o Comments in the source code. Your comments on the code should make
clear the logic of your source code even for a reader who may not have
programmed in your chosen language before.
Total points: 100.
Part 2: Adversarial Search in the Wumpus World
Summary. The program is essentially the same as before: the agent has to reach the pot of
gold without running into the Wumpus and without falling into a pit. The difference is
that this time the Wumpus can move as well, so the Wumpus can try and block the
agents path. (This is called a pursuit-evasion type of game.) The assignment
implements minimax search to find an optimal strategy for both players. You should be
able to reuse the code you built in part I for managing the state of the Wumpus world and
for finding legal moves.
Game Description.
Initial State.
The agents initial location is the square (1,1).
The initial location of 3 pits, 1 Wumpus and 1 pot of gold is specified in an input
file.
The initial locations of the agent, the pits, the Wumpus and the gold are all
different.
Legal Moves.
There are two players, the Agent and the Wumpus, that can move in the same way.
The agent can move 1 step sideways in any direction, but not diagonally. For
example, from the square (2,2) the agent can move to the squares (1,2),(2,3),(2,1),
(3,2).
The agent is not allowed to move to a square that contains a Wumpus or a pit.
The Wumpus can move 1 step sideways just like the agent.
The Wumpus is not allowed to move to a square that contains a pit or the pot of
gold.
The agent has the first move, followed by the Wumpus, then the agent, then the
Wumpus, etc.
Terminal States.
The game ends with a win for the Agent if it reaches the pot of gold before 6
moves. That is, the agent has to reach the pot of gold using no more than 6 steps.
The Wumpus wins if 6 moves have been made and the agent has not reached the
gold.
The Wumpus also wins if it enters the same square that the agent is on. (Then the
Wumpus eats the agent.)
Program Description
Input.
The input to your program is the same as in part 1: a text file called wumpus.txt where
each line specifies an initial location, like this.
Gold=2,3
Wumpus=1,3
Pit=3,1
Pit=3,3
Pit=4,4
To play the game, your program should accept as input a move by the agent read from the
keyboard. The move is in the form (x,y) specifying the square that the agent moves to.
You can assume that the user does not enter illegal moves.
Output.
Your program should implement minimax search or alpha-beta search to find an optimal
strategy for the Wumpus. You may find that the overhead of implementing alpha-beta
search saves you development time because testing the algorithm is faster and needs less
memory.
During game play, when an Agent move is input, output the following:
If the game reaches a terminal state, output who has won (e.g. the Agent has reached
the gold).
If the game is not in a terminal state, output:
1. An optimal move for the Wumpus.
2. The minimax value for the position that results from the Wumpus reply. (Or
the alpha-beta interval if you use alpha-beta search.)
3. The new game position (the 4x4 grid as in Figure 1) after the Wumpus reply.
After the output, your program should be ready to accept a new move by the
agent as input. For instance, you could issue a prompt Please input your next
move.
What to Hand In
Please upload your solution and documentation to courses.cs.sfu.ca. It is up to you to
provide evidence that your program is correct. At a minimum you should include the
following.
Source Code.
Documentation on how to run your program. This should include at least a
readme file.
Description of two test cases, one where the agent wins and one where the
Wumpus wins. E.g.,
o Show the input file.
o Show a screenshot of how your program reads the input file and what
output it produces.
o Explain why you think that the output is correct.
Grading Criteria
Same as in Part 1.