Skip to main content

A game engine for Azul board game

Project description

Azul game engine

A game engine for Azul board game.

Original game: https://en.wikipedia.org/wiki/Azul_(board_game).

PyPI version

Functionality

As a client of this game engine the only class you need to use is game.py.

Initializing 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])

Using game.py

game.py class has 3 main methods for clients to use:

  • json_object
  • execute_factory_offer_phase_with_factory
  • execute_factory_offer_phase_with_center

json_object()

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 active
    • Factory displays: List of factory display states
    • Center: Current center tile state
    • Players: List of all player states (including pattern lines, wall, floor)
    • Bag: Current bag tile counts
    • Lid: Current lid tile counts
    • Winners: 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 factory
  • amount_to_place_on_floor (int): Number of tiles to place on the floor
  • pattern_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)

execute_factory_offer_phase_with_center(tile_to_take, amount_to_place_on_floor, pattern_line_index)

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 center
  • amount_to_place_on_floor (int): Number of tiles to place on the floor
  • pattern_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)

Installing the project

Inside the directory this file is located run pip install .

Running tests

After you have installed the project, run this command pytest -vv in the same directory as this file.

codecov

License

Please read a LICENSE file.

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_game_engine-1.0.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

azul_game_engine-1.0.2-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file azul_game_engine-1.0.2.tar.gz.

File metadata

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

File hashes

Hashes for azul_game_engine-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1aacb622fcfed8f8df6f1c328810c9d95986655c992248987ad684450b57c1ad
MD5 916e8a324d85216f19edd1d9e9c16ded
BLAKE2b-256 9b930aaf4d713725aedc47c0437556ae7986cfa8a9c7f7112b9abc8a12e7500a

See more details on using hashes here.

File details

Details for the file azul_game_engine-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for azul_game_engine-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ee72234750e61a2fb36bee9b25ccc36d0a0ee706ad936e28393d7983e8085f53
MD5 2b4b5cd1c9d59849042391aca467d37a
BLAKE2b-256 0008d2cbcf4bacc5be18b6ce1c34c64edb692fe42d57e9647c146157e0f7dc2a

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