Skip to main content

Machi Koro 2 Game Engine

Project description

mk2lib

Machi Koro 2 Game Engine

A Python library for modeling and simulating the rules, components, and gameplay logic of Machi Koro 2 boardgame that focuses on correctness, which could be used for AI training, trying out custom house rules or new cards, etc.


Table of Contents


Features

  • Complete implementation of core mechanics and rules of Machi Koro 2 (including landmark promo pack).
  • Full encapsulation of game logic within mk2lib and presentation abstraction, you can build any UI on top of it easily.
  • Rule enforcement: mk2lib tracks everything and checks move legality. You only need to input moves.
  • Event bus architecture that allows end application to observe game state and handle changes.
  • Support for 2-5 players.
  • Modular design: can be easily extended for new house rules, possible future addons, etc.
  • Support for fast game serialization/deserialization and AI agent friendly design.
  • Comprehensive pytest testsuite with 100% coverage to ensure implementation correctness.

What is it not

  • A standalone ready-to-play game (unless you're willing to play from interactive Python REPL).
  • Machi Koro 2 AI/Bot (although it includes random fuzzing agent in test_fuzzing.py, which could be used as baseline for measuring AI performance).

Getting Started

Requirements

  • Python 3.10+
  • (Optional) pytest for running the test suite.

Installation

Install module from PyPI:

pip install mk2lib

Or just clone this repository:

git clone https://github.com/ostrosablin/mk2lib.git
cd mk2lib

Usage

Here's a minimal example to give you an idea how to use this library.

from mk2lib import MachiKoroGame

# Initialize game with player ID 1 as owner.
game = MachiKoroGame(1)

# Player with ID 2 joins lobby.
game.join(2)

# Owner (1) starts game with landmark promo pack and random player order.
game.start(1, use_promo=True, randomize_players=True)

# Try to build a Convenience Store as current player.
game.build_card("convenience_store", None)

# Read out all game's events.
while not game.events.empty():
    print(game.events.get())

You can find more complex example of game being (auto-)played from start to end in test_fuzzing.py.


Tests

Tests are included in tests/ directory within this repo. To run them, execute:

pytest --cov=mk2lib --cov-report=html

In root of repo. Ensure all tests pass before making changes or opening pull requests.


Contributing

Contributions are welcome! If you'd like to help, please:

  1. Fork the repository.
  2. Create a branch with bugfix or feature.
  3. Make changes and cover them with tests.
  4. Open a pull request.

Please follow the existing code style, add documentation for new features and ensure tests cover your changes.


License

mk2lib is licensed under GNU General Public License, Version 3.0. See LICENSE for full license text.


Acknowledgements

DISCLAIMER: This is an unofficial fan project, based on board game ‘Machi Koro 2’. ‘Machi Koro’ is a trademark of its respective owners. This project is not affiliated with or endorsed by them in any way.

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

mk2lib-1.0.0.tar.gz (87.6 kB view details)

Uploaded Source

Built Distribution

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

mk2lib-1.0.0-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file mk2lib-1.0.0.tar.gz.

File metadata

  • Download URL: mk2lib-1.0.0.tar.gz
  • Upload date:
  • Size: 87.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for mk2lib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9a2422a21f0187f67b9eb1d1dac23f40ca0b82f771adba513f4cbdb931c6c406
MD5 8833349839efd74b323e7dc7f75b6556
BLAKE2b-256 b32aadea934c9539f086e6e1da92275d1243a5f15a801609295c104b14d44bbe

See more details on using hashes here.

File details

Details for the file mk2lib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mk2lib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 41.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for mk2lib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e88e0e6ffde880b2310a4ec287b3ca70dd81f2945a86967f76313b8a4cd5b5e3
MD5 36ed016beade312c7f73558f4281394d
BLAKE2b-256 3cf02fe6275384b2e6410cd1d34efac2b4072d99433b936ffa94565abb4335b4

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