CPSC 415 - Artificial Intelligence - Fall 2023

Program #4 — Logic-based agents

Possible experience: up to +50XP

Due: Monday, Nov. 27th, midnight

Overview

For this assignment, you'll be exploring a simulated Wumpus World. The goal is to design a logic-based agent that can intelligently search its environment and make rational choices about what actions to take as it safely seeks gold. As always, your agent's performance will be evaluated on a quantitative performance measure.

Supporting classes

The files agent.py, environment.py, wumpus.py, main_wumpus.py, and visualize.py in the class's github repo have the supporting Python classes for this project. There are also two (dumb) sample explorer files, random_ExplorerAgent.py and manual_ExplorerAgent.py, which you can use to get your feet wet.

The agent.py, environment.py, and visualize.py files are unchanged from program #1. wumpus.py contains subclasses of Agent and Environment for this assignment. Feel free to take a look at them. Your agent will be inheriting from ExplorerAgent.

main_wumpus.py is the top-level script you'll call to run a wumpus simulation. You can run it in several ways:

$ python3 main_wumpus.py yourUmwId interactive

to run it in "interactive" mode, where you'll press the Go button for each move. (Replace yourUmwId with "random" to run the default random explorer, or your actual UMW ID (e.g., jsmith19) to run your explorer.)

You can also run it in "auto" mode:

$ python3 main_wumpus.py yourUmwId auto

in which case it will be off to the races.

You can also use the auto option to run the simulation in "manual mode" by literally specifying "manual" as the agent name:

$ python3 main_wumpus.py manual auto

This allows you to play the game as a human agent, entering your move choices one by one.

Finally, you can run an entire suite of simulations by typing:

$ python3 main_wumpus.py yourUmwId suite=500

which will run 500 simulations (all on one processor, currently) and dump the results to the screen in CSV format. You can redirect that to a file if you want to analyze it more carefully, or just look at the last two lines which give the min/max/median for your score and the number of moves you took.

There are also options to specify a particular random seed and to give a debug level, like for the vacuum program. See the main_wumpus.py usage message for details on this.

Your mission

Your job is to create a Python class for a knowledge-based agent called yourUmwIdExplorerAgent, which inherits from ExplorerAgent. It should make use of a KB class which will record and remember information about the board as you discover it. All this should be in a file called yourUmwId_ExplorerAgent.py. Its first few lines should look like this:

from wumpus import ExplorerAgent from PropKB import KB class yourUmwId_ExplorerAgent(ExplorerAgent): def __init__(self): super().__init__() self.kb = KB() def program(self, percept): pass

Your agent's program() method will be called by the simulator once each time you move. You will be given a 5-tuple of percept values each time, whose elements are as follows:

Your method should return one of the string values that are available in the ExplorerAgent.possible_actions list (see wumpus.py), namely: 'Forward', 'TurnRight', 'TurnLeft', 'Grab', 'Shoot', or 'Climb'. As you would expect, not all of these will always "work": 'Grab' does nothing unless there is gold in your current square; 'Shoot' does nothing if you've already shot your arrow, etc.

Getting started

Get the fresh version of the class repo by doing a git pull. Make sure you can play Wumpus World manually by typing:

$ python3 main_wumpus.py manual auto

and specifying moves yourself. (You will find it's an amazingly easy game to play...if the entire board is fully-observable, which of course it won't be for your agent program. *tear*)

When you get bored of this, create your agent and KB classes, in a file named exactly yourUmwId_ExplorerAgent.py. You are now ready to begin thinking.

Your Knowledge Base

You can make your KB class work however you choose. My only requirement is that you have a KB class and actually use it in your agent. This is to enforce the architectural lesson that logic-based agents are based on an outsourced knowledge base that operates somewhat autonomously from the agent itself.

I do suggest, however, that you make use of the KB class that I wrote specifically for this and the following assignment. The PropKB.py and cnf.py files are already in the class code base (you're welcome), and the KB itself is described semi-exhaustively on the github page.

Throughout this assignment, +3XP for finding a legitimate bug in my knowledge base code, and +1XP for correcting or suggesting a non-frivolous change to the documentation (README.md) for it.

Grading

As with the vacuum cleaner assignment, I will randomly run your explorer agent on a large number of randomly generated Wumpus Worlds (perhaps 1000) and average your performance measure on them. The performance measure I will use is exactly the one in the book. As the deadline gets closer, I will be in a position to state more precisely how XP will be mathematically tied to average performance score.

Turning it in

You will turn this assignment in by attaching your properly-named ExplorerAgent Python file to an email with subject line "CPSC 415 Program #4 turnin".

Getting help

Come to office hours, or send me email with subject line "CPSC 415 Program #4 help!!"