Skip to main content

A library to enable AI agent training on board game

Project description

AzulMARL

codecov PyPI version

PettingZoo AI env for Azul multiplayer board game to enable AI agent training.

AzulRendering

Most important libraries used

  • GitHub
  • GitHub

Usage

Initiating the env via PettingZoo

from azul_marl_env import azul_v1_2players, azul_v1_3players, azul_v1_4players

env_2players = azul_v1_2players()
env_3players = azul_v1_3players()
env_4players = azul_v1_4players()

env_2players_custom_max_moves = azul_v1_2players(max_moves=100)

Initiating the env directly

from azul_marl_env import AzulEnv

env = AzulEnv(player_count=2)
env = AzulEnv(player_count=3)
env = AzulEnv(player_count=4) 

env = AzulEnv(player_count=2, max_moves=100)

Making moves

from azul_marl_env import azul_v1_2players
import random

# Create and reset the environment
env = azul_v1_2players()
observation, info = env.reset()

for agent in env.agent_iter():
    valid_moves = info["valid_moves"]
    action = random.choice(valid_moves)
    # Execute the move
    observation, reward, terminated, truncated, info = env.step(action)
    # Render the environment
    env.render()
    if terminated or truncated:
        break

env.close()

Example of a complete game using random valid moves

from azul_marl_env import azul_v1_2players
import random

def play_random_game():
    env = azul_v1_2players()
    observation, info = env.reset()
    
    for agent in env.agent_iter():
        valid_moves = info["valid_moves"]            
        action = random.choice(valid_moves)
        observation, reward, terminated, truncated, info = env.step(action)
        
        if terminated or truncated:
            print(f"Game finished! Final scores: {[player['score'] for player in observation['players']]}")
            break
    
    env.close()

play_random_game()

Environment Details

Factory count (num_factories):
- 2 player game -> 5
- 3 player game -> 7
- 4 player game -> 9
  • Action Space: MultiDiscrete([num_factories + 1, 5, 20, 5])

    • First value: Factory index. Index 0 is taken for the center so the factory indexes are: 0 based factory index + 1.
    • Second value: Tile color (0-4 representing different colors)
    • Third value: Number of tiles to place on floor (0-19)
    • Fourth value: Pattern line index (0-4)
  • Observation Space: Dictionary containing:

    • factories: Box(0, 4, (num_factories, 5), int32) - Tile counts in each factory
    • center: Box(0, 3 * num_factories, (5,), int32) - Tile counts in center
    • players: Tuple of player states, each containing:
      • pattern_lines: Box(0, 5, (5, 5), int32) - Current pattern lines
      • wall: Box(0, 5, (5, 5), int32) - Wall state
      • floor: Box(0, 5, (7,), int32) - Floor tiles
      • is_starting: Discrete(2) - First player marker
      • score: Discrete(241) - Player's score
    • bag: Box(0, 100, (5,), int32) - Remaining tiles in bag
    • lid: Box(0, 100, (5,), int32) - Discarded tiles
  • Reward:

    • -1 for each step until game end
    • -2 for invalid moves
    • Final Azul score is added to cumulative reward at game end
  • Done: True when:

    • Game is completed (at least one player filled at least one horizontal wall)

    • False otherwise

    • Truncated: True when:

    • Maximum moves reached (player_count * 150 by default)

    • False otherwise

  • Info: Contains valid_moves list for the current player

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

azul_marl_env-1.0.3.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

azul_marl_env-1.0.3-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file azul_marl_env-1.0.3.tar.gz.

File metadata

  • Download URL: azul_marl_env-1.0.3.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for azul_marl_env-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9ce3a8f1442f734b16a844267a5a6c91e4328e4722ef1f77824ac89406d4eb13
MD5 0e487be7db3150142dd1473d6c5629d2
BLAKE2b-256 d6f0198656f32ac287c0cdddcfe3799506e27eacddfcf625ef298f462d9b8e07

See more details on using hashes here.

File details

Details for the file azul_marl_env-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: azul_marl_env-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for azul_marl_env-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 01c5637d5441d2d06da9b8c39d30b999296a25a58e83317d21a62f5ff806f5e7
MD5 354b5217fc41750d8885c84426045823
BLAKE2b-256 2bed2b03349c916d8a09e112fe36d6fb98f30da7a4dd208d12c91c0a5e4ede77

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