Skip to content

Commit 5f81bc5

Browse files
committed
Improve docs
1 parent 1152132 commit 5f81bc5

2 files changed

Lines changed: 109 additions & 3 deletions

File tree

README.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,112 @@
11
# Azul game engine
22

3+
A game engine for Azul board game.
4+
35
Original game: [https://en.wikipedia.org/wiki/Azul_(board_game)](Azul).
46

5-
[![codecov](https://codecov.io/gh/AzulImplementation/AzulGameEngine/branch/main/graph/badge.svg)](https://codecov.io/gh/AzulImplementation/AzulGameEngine)
67
[![PyPI version](https://badge.fury.io/py/azul-game-engine.svg)](https://pypi.org/project/azul-game-engine/)
8+
9+
## Functionality
10+
11+
As a client of this game engine the only class you need to use is `game.py`.
12+
13+
### Initializing `game.py`
14+
15+
```python
16+
lid = Lid()
17+
player1 = Player(Board(wall=Wall(), floor=Floor(lid)), f"Player Name 1")
18+
player2 = Player(Board(wall=Wall(), floor=Floor(lid)), f"Player Name 2")
19+
game = Game([player1, player2])
20+
```
21+
22+
### Using `game.py`
23+
24+
`game.py` class has 3 main methods for clients to use:
25+
- `json_object`
26+
- `execute_factory_offer_phase_with_factory`
27+
- `execute_factory_offer_phase_with_center`
28+
29+
#### `json_object()`
30+
31+
Returns a dictionary representation of the current game state, suitable for JSON serialization.
32+
33+
**Returns:**
34+
- `dict`: A dictionary containing:
35+
- `isRunning`: Boolean indicating if the game is still active
36+
- `Factory displays`: List of factory display states
37+
- `Center`: Current center tile state
38+
- `Players`: List of all player states (including pattern lines, wall, floor)
39+
- `Bag`: Current bag tile counts
40+
- `Lid`: Current lid tile counts
41+
- `Winners`: List of winner names (only present when game has ended)
42+
43+
**Example:**
44+
```python
45+
state = game.json_object()
46+
```
47+
48+
#### `execute_factory_offer_phase_with_factory(factory_index, tile_to_take, amount_to_place_on_floor, pattern_line_index)`
49+
50+
Executes the current player's turn by taking tiles from a specified factory display.
51+
52+
**Parameters:**
53+
- `factory_index` (int): Index of the factory display to take tiles from. Starting index 0. Ending index: 4 on two player game, 6 on 3 player game, 8 on 4 player game.
54+
- `tile_to_take` (Tile): The specific tile color to take from the factory
55+
- `amount_to_place_on_floor` (int): Number of tiles to place on the floor
56+
- `pattern_line_index` (int): Index of the pattern line to place tiles on (0-4)
57+
58+
**Behavior:**
59+
- Takes all tiles of the specified color from the chosen factory display
60+
- Places remaining tiles from that factory into the center
61+
- Places tiles on the specified pattern line (and floor on some cases)
62+
- Advances to the next player's turn
63+
- Triggers wall tiling phase if all factories and center are empty
64+
65+
**Raises:**
66+
- `ActionNotAllowedException`: If the game has already ended or move is illegal (e.g. user wants to take a Blue tile from a factory but the factory does not have blue tiles).
67+
68+
**Example:**
69+
```python
70+
# Player takes red tiles from factory 0, places 2 on floor, rest on pattern line 1
71+
game.execute_factory_offer_phase_with_factory(0, Tile.RED, 2, 1)
72+
```
73+
74+
#### `execute_factory_offer_phase_with_center(tile_to_take, amount_to_place_on_floor, pattern_line_index)`
75+
76+
Executes a player's turn by taking tiles from the center area.
77+
78+
**Parameters:**
79+
- `tile_to_take` (Tile): The specific tile color to take from the center
80+
- `amount_to_place_on_floor` (int): Number of tiles to place on the floor
81+
- `pattern_line_index` (int): Index of the pattern line to place tiles on (0-4)
82+
83+
**Behavior:**
84+
- Takes all tiles of the specified color from the center
85+
- First player to take from center receives the starting player marker (-1 point penalty)
86+
- Places tiles on the specified pattern line (and floor on some cases)
87+
- Advances to the next player's turn
88+
- Triggers wall tiling phase if all factories and center are empty
89+
90+
**Raises:**
91+
- `ActionNotAllowedException`: If the game has already ended or move is illegal (e.g. user wants to take a Blue tile from the center but there is no blue tile in it).
92+
93+
**Example:**
94+
```python
95+
# Player takes blue tiles from center, places 1 on floor, rest on pattern line 0
96+
game.execute_factory_offer_phase_with_center(Tile.BLUE, 1, 0)
97+
```
98+
99+
## Installing the project
100+
101+
Inside the directory this file is located run `pip install .`
102+
103+
## Running tests
104+
105+
After you have installed the project, run this command `pytest -vv` in the same directory as this file.
106+
107+
[![codecov](https://codecov.io/gh/AzulImplementation/AzulGameEngine/branch/main/graph/badge.svg)](https://codecov.io/gh/AzulImplementation/AzulGameEngine)
108+
109+
110+
## License
111+
112+
Please read a `LICENSE` file.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[project]
22
name = "azul_game_engine"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
authors = [{name = "Evaldas Visockas", email = "developersediary@gmail.com"}]
5-
description = "Game engine for enabling Azul game being used by API and AI agents"
5+
description = "A game engine for Azul board game "
66
readme = "README.md"
77
requires-python = ">=3.12"
88
license = {text = "GPL-3.0-or-later"}

0 commit comments

Comments
 (0)