Skip to content
Snippets Groups Projects
Forked from Tessaris Sergio / wumpus
26 commits behind the upstream repository.
Name Last commit Last update
examples
gym_wumpus
wumpus
LICENSE.txt
README.md
setup.py

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/tessaris/wumpus and use pip install ., or install directly from the repository using

pip install https://gitlab.inf.unibz.it/tessaris/wumpus/-/archive/master/wumpus-master.tar.gz

Usage

To write your own player you should create a subclass of Player (defined in gridworld.py) and then use an instance as a parameter of the run_episode method of GridWorld class (defined in gridworld.py).

Examples of the usage of the package can be found in the implementation of two players RandomPlayer and UserPlayer from gridworld.py, and in the files wumpus-usage.py, eater-usage.py in the examples, eater-usage.py directory of the repository.

Your player could be also run using the script gridrunner script (in the repository is the runner.py file) and it'll be available once the package is installed (in alternative could be executed using python -m wumpus.runner):

$ gridrunner --help
usage: gridrunner [-h] [--name NAME] [--path PATH] --entry ENTRY
                  [--world {EaterWorld,WumpusWorld}] [--horizon HORIZON]
                  [--noshow] [--out OUT] [--version]
                  [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

For example:

$ gridrunner --world EaterWorld --entry wumpus:RandomPlayer --noshow --horizon 5 --path examples ./examples/eater-world.json
┌────────┐
│.....│
│.██...│
│.....│
│.....│
│🍌🐒.🍌.│
└────────┘
Step 0: agent Eater_df9919cd executing W -> reward 9
Step 1: agent Eater_df9919cd executing S -> reward -1
Step 2: agent Eater_df9919cd executing N -> reward -1
Step 3: agent Eater_df9919cd executing W -> reward -1
Step 4: agent Eater_df9919cd executing N -> reward -1
Episode terminated by maximum number of steps (5).
┌─────────┐
│.....│
│.██...│
│🐒....│
│.....│
│...🍌.│
└─────────┘
Episode terminated with a reward of 5 for agent Eater_df9919cd