A game engine for Azul board game.
Original game: https://en.wikipedia.org/wiki/Azul_(board_game).
As a client of this game engine the only class you need to use is game.py.
lid = Lid()
player1 = Player(Board(wall=Wall(), floor=Floor(lid)), f"Player Name 1")
player2 = Player(Board(wall=Wall(), floor=Floor(lid)), f"Player Name 2")
game = Game([player1, player2])game.py class has 3 main methods for clients to use:
json_objectexecute_factory_offer_phase_with_factoryexecute_factory_offer_phase_with_center
Returns a dictionary representation of the current game state, suitable for JSON serialization.
Returns:
dict: A dictionary containing:isRunning: Boolean indicating if the game is still activeFactory displays: List of factory display statesCenter: Current center tile statePlayers: List of all player states (including pattern lines, wall, floor)Bag: Current bag tile countsLid: Current lid tile countsWinners: List of winner names (only present when game has ended)
Example:
state = game.json_object()execute_factory_offer_phase_with_factory(factory_index, tile_to_take, amount_to_place_on_floor, pattern_line_index)
Executes the current player's turn by taking tiles from a specified factory display.
Parameters:
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.tile_to_take(Tile): The specific tile color to take from the factoryamount_to_place_on_floor(int): Number of tiles to place on the floorpattern_line_index(int): Index of the pattern line to place tiles on (0-4)
Behavior:
- Takes all tiles of the specified color from the chosen factory display
- Places remaining tiles from that factory into the center
- Places tiles on the specified pattern line (and floor on some cases)
- Advances to the next player's turn
- Triggers wall tiling phase if all factories and center are empty
Raises:
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).
Example:
# Player takes red tiles from factory 0, places 2 on floor, rest on pattern line 1
game.execute_factory_offer_phase_with_factory(0, Tile.RED, 2, 1)Executes a player's turn by taking tiles from the center area.
Parameters:
tile_to_take(Tile): The specific tile color to take from the centeramount_to_place_on_floor(int): Number of tiles to place on the floorpattern_line_index(int): Index of the pattern line to place tiles on (0-4)
Behavior:
- Takes all tiles of the specified color from the center
- First player to take from center receives the starting player marker (-1 point penalty)
- Places tiles on the specified pattern line (and floor on some cases)
- Advances to the next player's turn
- Triggers wall tiling phase if all factories and center are empty
Raises:
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).
Example:
# Player takes blue tiles from center, places 1 on floor, rest on pattern line 0
game.execute_factory_offer_phase_with_center(Tile.BLUE, 1, 0)Inside the directory this file is located run pip install .
After you have installed the project, run this command pytest -vv in the same directory as this file.
Please read a LICENSE file.