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
mk2liband presentation abstraction, you can build any UI on top of it easily. - Rule enforcement:
mk2libtracks 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)
pytestfor 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(None, "convenience_store")
# 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:
- Fork the repository.
- Create a branch with bugfix or feature.
- Make changes and cover them with tests.
- 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.
Metadata
Release files for mk2lib 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mk2lib-1.1.2.tar.gz | 88.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mk2lib-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 130.2 kB
Release files / mk2lib-1.1.2.tar.gz
| Download URL | mk2lib-1.1.2.tar.gz |
|---|---|
| Size | 88.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
220f1b9f879eff8ecc88f4bd13c200ac720801f67a55a09d477f76566c3084ac
|
|
BLAKE2b-256 checksum How to use checksums |
f63d96ca48efdf7b470ebd2d3f2fb6e4aa178d476387abd0a8d62735ba6904cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / mk2lib-1.1.2-py3-none-any.whl
| Download URL | mk2lib-1.1.2-py3-none-any.whl |
|---|---|
| Size | 41.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
74bc05a103eb46686ff54fc81a58ba77ef0615acd731206e7ba710247e3ca072
|
|
BLAKE2b-256 checksum How to use checksums |
3428d15711c56a7652fc70319baee8bcdc02368cf61a814ef40cac7dc8dad801
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for mk2lib 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.