|
3 | 3 | [](https://codecov.io/gh/AzulImplementation/AzulMARL) |
4 | 4 | [](https://pypi.org/project/parkinglotgym/) |
5 | 5 |
|
6 | | -PettingZoo AI env for Azul multiplayer board game to enable AI agent training. |
| 6 | +PettingZoo AI env for Azul multiplayer board game to enable AI agent training. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Most important libraries used |
| 11 | + |
| 12 | +- [](https://github.com/AzulImplementation/AzulGameEngine) |
| 13 | +- [](https://github.com/Farama-Foundation/PettingZoo) |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +### Initiating the env via PettingZoo |
| 18 | + |
| 19 | +```python |
| 20 | +from azul_marl_env import azul_v1_2players, azul_v1_3players, azul_v1_4players |
| 21 | + |
| 22 | +env_2players = azul_v1_2players() |
| 23 | +env_3players = azul_v1_3players() |
| 24 | +env_4players = azul_v1_4players() |
| 25 | + |
| 26 | +env_2players_custom_max_moves = azul_v1_2players(max_moves=100) |
| 27 | +``` |
| 28 | + |
| 29 | +### Initiating the env directly |
| 30 | + |
| 31 | +```python |
| 32 | +from azul_marl_env import AzulEnv |
| 33 | + |
| 34 | +env = AzulEnv(player_count=2) |
| 35 | +env = AzulEnv(player_count=3) |
| 36 | +env = AzulEnv(player_count=4) |
| 37 | + |
| 38 | +env = AzulEnv(player_count=2, max_moves=100) |
| 39 | +``` |
| 40 | + |
| 41 | +### Making moves |
| 42 | + |
| 43 | +```python |
| 44 | +from azul_marl_env import azul_v1_2players |
| 45 | +import random |
| 46 | + |
| 47 | +# Create and reset the environment |
| 48 | +env = azul_v1_2players() |
| 49 | +observation, info = env.reset() |
| 50 | + |
| 51 | +for agent in env.agent_iter(): |
| 52 | + valid_moves = info["valid_moves"] |
| 53 | + action = random.choice(valid_moves) |
| 54 | + # Execute the move |
| 55 | + observation, reward, terminated, truncated, info = env.step(action) |
| 56 | + # Render the environment |
| 57 | + env.render() |
| 58 | + if terminated or truncated: |
| 59 | + break |
| 60 | + |
| 61 | +env.close() |
| 62 | +``` |
| 63 | + |
| 64 | +### Example of a complete game using random valid moves |
| 65 | + |
| 66 | +```python |
| 67 | +from azul_marl_env import azul_v1_2players |
| 68 | +import random |
| 69 | + |
| 70 | +def play_random_game(): |
| 71 | + env = azul_v1_2players() |
| 72 | + observation, info = env.reset() |
| 73 | + |
| 74 | + for agent in env.agent_iter(): |
| 75 | + valid_moves = info["valid_moves"] |
| 76 | + action = random.choice(valid_moves) |
| 77 | + observation, reward, terminated, truncated, info = env.step(action) |
| 78 | + |
| 79 | + if terminated or truncated: |
| 80 | + print(f"Game finished! Final scores: {[player['score'] for player in observation['players']]}") |
| 81 | + break |
| 82 | + |
| 83 | + env.close() |
| 84 | + |
| 85 | +play_random_game() |
| 86 | +``` |
| 87 | + |
| 88 | +## Environment Details |
| 89 | + |
| 90 | + Factory count (num_factories): |
| 91 | + - 2 player game -> 5 |
| 92 | + - 3 player game -> 7 |
| 93 | + - 4 player game -> 9 |
| 94 | + |
| 95 | +- **Action Space**: MultiDiscrete([num_factories + 1, 5, 20, 5]) |
| 96 | + - First value: Factory index. Index 0 is taken for the center so the factory indexes are: 0 based factory index + 1. |
| 97 | + - Second value: Tile color (0-4 representing different colors) |
| 98 | + - Third value: Number of tiles to place on floor (0-19) |
| 99 | + - Fourth value: Pattern line index (0-4) |
| 100 | + |
| 101 | +- **Observation Space**: Dictionary containing: |
| 102 | + - `factories`: Box(0, 4, (num_factories, 5), int32) - Tile counts in each factory |
| 103 | + - `center`: Box(0, 3 * num_factories, (5,), int32) - Tile counts in center |
| 104 | + - `players`: Tuple of player states, each containing: |
| 105 | + - `pattern_lines`: Box(0, 5, (5, 5), int32) - Current pattern lines |
| 106 | + - `wall`: Box(0, 5, (5, 5), int32) - Wall state |
| 107 | + - `floor`: Box(0, 5, (7,), int32) - Floor tiles |
| 108 | + - `is_starting`: Discrete(2) - First player marker |
| 109 | + - `score`: Discrete(241) - Player's score |
| 110 | + - `bag`: Box(0, 100, (5,), int32) - Remaining tiles in bag |
| 111 | + - `lid`: Box(0, 100, (5,), int32) - Discarded tiles |
| 112 | + |
| 113 | +- **Reward**: |
| 114 | + - `-1` for each step until game end |
| 115 | + - `-2` for invalid moves |
| 116 | + - Final Azul score is added to cumulative reward at game end |
| 117 | + |
| 118 | +- **Done**: `True` when: |
| 119 | + - Game is completed (at least one player filled at least one horizontal wall) |
| 120 | + - `False` otherwise |
| 121 | + |
| 122 | + - **Truncated**: `True` when: |
| 123 | + - Maximum moves reached (player_count * 150 by default) |
| 124 | + - `False` otherwise |
| 125 | + |
| 126 | +- **Info**: Contains `valid_moves` list for the current player |
0 commit comments