Multi-Agent Reinforcement Learning Environment for the board game Gobblet using PettingZoo.
Project description
gobblet-rl
Interactive Multi-Agent Reinforcement Learning Environment for the Gobblet board game using PettingZoo and Pygame.
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:
import pettingzoo
from gobblet import gobblet_v1
env = gobblet_v1.env()
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.
Play an interactive game againt an agent
In the terminal, run the following:
python gobblet/example_interactive_pygame.py --render_mode="human" --agent_type="random_permissible"
Command Line Arguments
Game Modes
The default game mode is human vs CPU, with the human playing as red and CPU as yellow. The --player
argument allows you to play as yellow, with the CPU moving first.
The flag --no-cpu
will launch a game with no CPU agents, taking interactive input for both agents.
The flag --cpu-only
will launch a game with two CPU agents, and takes no interactive input.
Render Modes
--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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gobblet-rl-1.2.0.tar.gz
.
File metadata
- Download URL: gobblet-rl-1.2.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dfb0a0ac690343138e91295072f2d46631b50933f699babe6c9a94bbc16a87d |
|
MD5 | bef6cc332fd9a37ad48278deb26347d6 |
|
BLAKE2b-256 | 02cd71f5b14035ba9333c7ac4ed323993d2b2ce80ecd370494538f217dbc2937 |
File details
Details for the file gobblet_rl-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: gobblet_rl-1.2.0-py3-none-any.whl
- Upload date:
- Size: 33.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c5c15f55cc1b85d111383debab2d916515b9d5992fa9268d9097456ff1452b1 |
|
MD5 | 2cd2112b9cc3b16beddc885c400e9ec1 |
|
BLAKE2b-256 | 4e611cb3ddb56c15419496fa2920e77e006e0ba93ab78c80d068f769e35aa4ba |