Skip to main content

A Python library for competitive reinforcement learning environments

Project description

RL Arena ๐ŸŽฎ

A Python library for competitive reinforcement learning environments, similar to kaggle-environments but focused on multi-agent RL research and competitions.

Tests PyPI version Python 3.9+ License: Apache 2.0 Code style: black

๐ŸŒŸ Features

  • Easy-to-use API: Familiar Gymnasium-style interface
  • Competitive Multi-Agent: Built for head-to-head competition
  • Extensible: Simple framework for adding new environments
  • Well-tested: Comprehensive test suite with >80% coverage
  • Type-safe: Full type hints for better development experience
  • Reproducible: Deterministic environments with seed support
  • Visualization System: Real-time rendering with Matplotlib
  • Replay Recording: Save and replay matches in JSON format
  • HTML5 Replays: Interactive browser-based match playback

๐Ÿ“ฆ Installation

From PyPI (recommended)

pip install rl-arena

From Source

git clone https://github.com/rl-arena/rl-arena-env.git
cd rl-arena-env
pip install -e .

For Development

git clone https://github.com/rl-arena/rl-arena-env.git
cd rl-arena-env
pip install -e ".[dev]"

๐Ÿš€ Quick Start (30 seconds!)

RL-Arena makes it easy to: Create environments โ†’ Train agents โ†’ Test โ†’ Submit

import rl_arena

# 1๏ธโƒฃ Create environment
env = rl_arena.make("pong")

# 2๏ธโƒฃ Train agent (DQN)
model = rl_arena.train_dqn("pong", total_timesteps=10000)

# 3๏ธโƒฃ Test agent
agent = rl_arena.create_agent(model)
results = rl_arena.evaluate(agent, "pong", n_episodes=10)
print(f"Average reward: {results['mean_reward']:.2f}")

# 4๏ธโƒฃ Create submission file
rl_arena.create_submission(
    agent,
    "my_submission.py",
    agent_name="MyAgent",
    author="your_name"
)

That's it! Submit my_submission.py to rl-arena-backend.


๐Ÿ“– Basic Usage

Environment Creation

import rl_arena

# Create environment
env = rl_arena.make("pong")

# Use built-in agents
agent1 = rl_arena.RandomAgent()
agent2 = rl_arena.RuleBasedAgent()

# Run a game
observations, info = env.reset(seed=42)
done = False

while not done:
    # Get actions from agents
    actions = [
        agent1.act(observations[0]),
        agent2.act(observations[1])
    ]
    
    # Step environment
    observations, rewards, terminated, truncated, info = env.step(actions)
    done = terminated or truncated
    
    # Render
    env.render()

print(f"Final scores: {info['scores']}")
env.close()

๐ŸŽฏ Available Environments

Environment Players Description Complexity
pong 2 Classic Pong game โญ Easy

More environments coming soon! Contributions welcome!

๐ŸŽฎ Environment Details

Pong

Classic 2-player Pong game with customizable physics.

env = rl_arena.make("pong", configuration={
    "winning_score": 11,    # First to 11 wins
    "max_steps": 1000,      # Episode length limit
    "ball_speed": 0.02,     # Ball movement speed
    "paddle_height": 0.2,   # Paddle size
})

State Space: Ball position & velocity, paddle positions, scores
Action Space: Discrete(3) - UP, STAY, DOWN
Rewards: +1 for scoring, -1 for conceding

See Pong documentation for more details.

๐Ÿ“š Documentation

๐Ÿ”จ Development

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=rl_arena tests/

# Run specific test file
pytest tests/test_core.py -v

Code Quality

# Format code
black rl_arena/ tests/ examples/

# Type checking
mypy rl_arena/

# Linting
flake8 rl_arena/ tests/ examples/

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. Add New Environments: See Environment Creation Tutorial
  2. Fix Bugs: Check open issues
  3. Improve Documentation: Help make RL Arena more accessible
  4. Add Examples: Share your agent implementations

Quick Contribution Workflow

# Fork and clone
git clone https://github.com/YOUR-USERNAME/rl-arena-env.git
cd rl-arena-env

# Create branch
git checkout -b feature/my-new-environment

# Make changes, add tests, update docs

# Run tests and linting
pytest
black rl_arena/ tests/
flake8 rl_arena/

# Commit and push
git commit -m "feat: Add new environment"
git push origin feature/my-new-environment

# Open Pull Request on GitHub

๐Ÿ“– Examples

Train and Evaluate Agent

import rl_arena

# Train DQN agent
model = rl_arena.train_dqn("pong", total_timesteps=50000)

# Evaluate performance
agent = rl_arena.create_agent(model)
results = rl_arena.evaluate(agent, "pong", n_episodes=20)
print(f"Win rate: {results['mean_reward']:.2%}")

Interactive Play (Human vs AI)

# Requires pygame: pip install pygame
player = rl_arena.play("pong", fps=60)
player.play(
    player1_agent=None,  # Human player
    player2_agent=agent,  # Your trained AI
)

Record and Replay Matches

from rl_arena.utils.replay import save_replay, replay_to_html

# Record match
recorder = rl_arena.MatchRecorder()
env = rl_arena.make("pong")
env.set_recorder(recorder)

# ... play game ...

# Save replay
recording = recorder.get_recording()
save_replay(recording, "match.json")

# Generate HTML replay
html = replay_to_html(recording, "pong", "replay.html")

Create Submission File

# Create submission for competition
rl_arena.create_submission(
    agent=agent,
    output_path="submission.py",
    agent_name="MyPongMaster",
    author="your_name",
    description="DQN agent trained for 50K steps"
)

# Validate submission
result = rl_arena.validate("submission.py")
if result['valid']:
    print("โœ… Ready to submit!")

๐ŸŽ“ Use Cases

  • Research: Study multi-agent RL algorithms
  • Education: Learn RL in competitive settings
  • Competitions: Host RL tournaments and competitions
  • Benchmarking: Compare agent performance across environments
  • Fun: Build and battle AI agents!

๐Ÿ—๏ธ Project Structure

rl-arena-env/
โ”œโ”€โ”€ rl_arena/              # Main package
โ”‚   โ”œโ”€โ”€ core/              # Base classes and interfaces
โ”‚   โ”œโ”€โ”€ envs/              # Environment implementations
โ”‚   โ”‚   โ”œโ”€โ”€ pong/          # Pong environment
โ”‚   โ”‚   โ””โ”€โ”€ __template__/  # Template for new environments
โ”‚   โ””โ”€โ”€ utils/             # Utilities (replay, logging, etc.)
โ”œโ”€โ”€ tests/                 # Test suite
โ”œโ”€โ”€ examples/              # Example scripts
โ”œโ”€โ”€ docs/                  # Documentation
โ””โ”€โ”€ .github/               # CI/CD workflows

๐Ÿ™ Acknowledgments

๐Ÿ“ฌ Contact & Support

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

โญ Star History

If you find RL Arena useful, please consider starring the repository!


Made with โค๏ธ by the RL Arena community

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

rl_arena-0.1.1.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rl_arena-0.1.1-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file rl_arena-0.1.1.tar.gz.

File metadata

  • Download URL: rl_arena-0.1.1.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for rl_arena-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5a4d9f56965a4a39877f426fd92dcbbd711f644b4bea785f93ba235db6a23f40
MD5 373bbe5a40956277e97e1b2cc7ac2d9d
BLAKE2b-256 991e0d8df1dfa03a6d5739c158858f5a851aac6c3051f5285d5a7a7c93c0dd88

See more details on using hashes here.

File details

Details for the file rl_arena-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rl_arena-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for rl_arena-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4bdbce4ce5257ddfac5404a37f4e272b55b5098078d118b8143a4310a6a5b372
MD5 f977da8b3fd1fe5f86a8b70f371da2c4
BLAKE2b-256 41cd8f1aea40369a24aa0b04e40e34fa1430164c84b7ec893ecb9cc57071b7e7

See more details on using hashes here.

Supported by

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