Skip to main content

Multi-Agent Reinforcement Learning Environment for the board game Gobblet using PettingZoo.

Project description

gobblet-rl

PyPI version License

Interactive Multi-Agent Reinforcement Learning Environment for the Gobblet board game using PettingZoo and Pygame.

Light         Dark

Installation

Using pip (recommended)

pip install gobblet-rl

Local

git clone hhttps://github.com/elliottower/gobblet-rl.git
cd gobblet-rl
pip install -e .

Usage

Setting up a basic environment

In a Python shell, run the following:

from gobblet import gobblet_v1

env = gobblet_v1.env()

Play an interactive game

In the terminal, run the following:

python gobblet/examples/example_user_input.py"

To select a piece size, press a number key 1, 2, or 3, or press space to cycle through pieces. Placing a piece is done by clicking on a square on the board. A preview will appear showing legal moves with the selected piece size. Clicking on an already placed piece will pick it up and prompt you to place it in a new location (re-placing in the same location is an illegal move).

Screen recording of a game

In the terminal, run the following:

python gobblet/examples/example_record_game.py"

This will save a screen recording of a game to gobblet/examples/game.gif

Display a game between two basic CPU agents

In the terminal, run the following:

python gobblet/examples/example_basic.py"

This will launch a game with two agents choosing random actions (other agent types will be added in the future)

Train a DQL agent with Tianshou

In the terminal, run the following:

python gobblet/example_tianshou.py

This will train a DQN model from Tianshou for 50 epochs, and then render the trained agent playing against a random agent in an example match.

Command Line Arguments

Game Modes

example_user_input.py and example_record_game.py take the following arguments:

The default game mode is human vs CPU, with the human playing as red and CPU as yellow.

--player 1 sets the human player as yellow, with the CPU moving first as red.

--cpu-players 0 will launch a game with no CPU agents, taking interactive input for both agents.

--cpu-player 2 will launch a game with two CPU agents, and takes no interactive input.

Display Modes

example_basic.py takes the following arguments to change display mode:

--render_mode="human" will render the game board visually using pygame. Player 1 plays red and goes first, while player 2 plays yellow.

When playing interactively, possible moves can be previewed by hovering the mouse over each square. To move a piece which is already placed, simply click on it.

--render_mode="text" will render a 3x3 board only showing the topmost pieces (pieces which are covered by others, or 'gobbled', are hidden):

TURN: 2, AGENT: player_1, ACTION: 51, POSITION: 6, PIECE: 3
       |       |       
  -    |   -   |   -3  
_______|_______|_______
       |       |       
  -    |   -   |   +2  
_______|_______|_______
       |       |       
  -    |   -   |   -   
       |       |       

--render_mode="text_full" will render three different 3x3 boards representing the small, medium and large pieces. This gives full information about pieces which are covered or 'gobbled' by other pieces. :

TURN: 3, AGENT: player_0, ACTION: 42, POSITION: 6, PIECE: 5
         SMALL                     MED                     LARGE           
       |       |                |       |                |       |       
  -    |   -   |   -       -    |   -   |   -       -    |   -   |   +5  
_______|_______|_______  _______|_______|_______  _______|_______|_______
       |       |                |       |                |       |       
  -    |   -   |   -2      -    |   -   |   -       -    |   -   |   -   
_______|_______|_______  _______|_______|_______  _______|_______|_______
       |       |                |       |                |       |       
  -    |   -   |   -       -    |   -   |   -       -    |   -   |   -6  
       |       |                |       |                |       |       

Testing

Testing can be done via pytest:

git clone https://github.com/elliottower/gobblet-rl.git
cd gobblet-rl
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gobblet-rl-1.2.1.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

gobblet_rl-1.2.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file gobblet-rl-1.2.1.tar.gz.

File metadata

  • Download URL: gobblet-rl-1.2.1.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for gobblet-rl-1.2.1.tar.gz
Algorithm Hash digest
SHA256 711db752f56429fc89afbe443cd770f34b94e83801e04684f49f51df4e0d4d1a
MD5 fd4141f904039922eb1b5e62d4f09f0f
BLAKE2b-256 950b9a29f4e0beaa0feb0e6482e7fe9630dc58182769c73022cecf9d2b23104b

See more details on using hashes here.

File details

Details for the file gobblet_rl-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: gobblet_rl-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for gobblet_rl-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c72c188711b52da7ccae93478f37cf6afb7e2a587ef3a483edc95f2f051b56a8
MD5 c592e119f972a185daaa9ddb9bedf906
BLAKE2b-256 56ef47ae3d8621397253a48b73e6b28a8402877cd82e2db221c9d5a2fad2603e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page