Wumpus World Simulator
This package implements a Python version of the Hunt the Wumpus game as described in the book Artificial Intelligence: A Modern Approach by Russell and Norvig.
The package has been written to be used in the master course of AI taught at the Faculty of Computer Science of the Free University of Bozen-Bolzano.
Install
You can download the source code from https://gitlab.inf.unibz.it/Davide.Lanti1/wumpus-tessaris and use pip install .
,
or install directly from the repository using:
pip install git+https://gitlab.inf.unibz.it/Davide.Lanti1/wumpus-tessaris
The present project is a fork of the original work by Prof. Sergio Tessaris: https://gitlab.inf.unibz.it/tessaris/wumpus.
Usage
To write your own player you should create a subclass of OnlinePlayer
or OfflinePlayer
(defined in player.py) and then use an instance as a parameter of the run_episode
function (defined in runner.py).
Examples of the usage of the package can be found in the implementation of two players RandomPlayer
and UserPlayer
in player.py, and in the files wumpus_usage.py
, eater_usage.py
in the examples
directory of the repository.
Your player could be also run using the script gridrunner
script (in the repository is the cli.py
file) and it'll be available once the package is installed (in alternative could be executed using python -m wumpus.cli
):
$ gridrunner --help
usage: gridrunner [-h] [--name NAME] [--path PATH] --entry ENTRY
[--world {EaterWorld,WumpusWorld}] [--horizon HORIZON]
[--noshow] [--out OUT] [--version] [--log LOG]
[infiles [infiles ...]]
Run episodes on worlds using the specified player.
positional arguments:
infiles world description JSON files, they must be compatible
with the world type (see --world option). (default:
None)
optional arguments:
-h, --help show this help message and exit
--name NAME, -n NAME name of the player, default to the name of the player
class (default: None)
--path PATH, -p PATH path of the player library, it's prepended to the
sys.path variable (default: .)
--entry ENTRY, -e ENTRY
object reference for a Player subclass in the form
'importable.module:object.attr'. See
<https://packaging.python.org/specifications/entry-
points/#data-model> for details. (default: None)
--world {EaterWorld,WumpusWorld}, -w {EaterWorld,WumpusWorld}
class name of the world (default: EaterWorld)
--horizon HORIZON, -z HORIZON
maximum number of steps (default: 20)
--noshow prevent the printing the world at each step (default:
True)
--out OUT, -o OUT write output to file (default: <_io.TextIOWrapper
name='<stdout>' mode='w' encoding='UTF-8'>)
--version show program's version number and exit
--log LOG, -l LOG write the log of the games to file (JSON) (default:
None)
For example:
$ gridrunner --world EaterWorld --entry wumpus:RandomPlayer --noshow --horizon 5 ./examples/eater-world.json
Step 0: agent Eater_c881e1b0 executing N -> reward -1
Step 1: agent Eater_c881e1b0 executing W -> reward -1
Step 2: agent Eater_c881e1b0 executing E -> reward -1
Step 3: agent Eater_c881e1b0 executing W -> reward -1
Step 4: agent Eater_c881e1b0 executing E -> reward -1
Episode terminated by maximum number of steps (5).
┌──────────┐
│.....│
│.██...│
│.....│
│.🐒...│
│🍌..🍌.│
└──────────┘
Episode terminated with a reward of -5 for agent Eater_c881e1b0
You can also use a player defined in a script; e.g., if the player class GooPlayer
is defined in the eater_usage.py
you can use the eater_usage:GooPlayer
entry. Remember Python rules for finding modules, where the current directory is added to the search path. If the script is in a different directory, you can use the --path
argument to tell the script where to find it:
gridrunner --world EaterWorld --entry eater_usage:GooPlayer --path examples --noshow --horizon 5 ./resources/eater-world.json