Skip to main content

Dominion but make it python

Project description

Pyminion

tests codecov

Pyminion is a library for executing and analyzing games of Dominion. At its core, pyminion implements the rules and logic of Dominion and provides an API to interact with the game engine. In addition, it enables interactive games through the command line and simulation of games between bots.

Table of Contents

Getting Started

Pyminion requires at least Python 3.8 and can easily be installed through pypi

python3 -m pip install pyminion

Usage

Setting up a game

To play an interactive game through the command line against a bot, initialize a human and a bot and assign them as players. Alternatively, games can be created between multiple humans or multiple bots.

from pyminion.expansions.base import base_set 
from pyminion.game import Game
from pyminion.bots.examples import BigMoney
from pyminion.players import Human

# Initialize human and bot
human = Human()
bot = BigMoney()

# Setup the game
game = Game(players=[human, bot], expansions=[base_set])

# Play game
game.play()

Creating Bots

Defining new bots is relatively straightforward. Inherit from the Bot class and implement play and buy strategies in the action_priority and buy_priority methods respectively.

For example, here is a simple big money + smithy bot:

from pyminion.bots.bot import Bot
from pyminion.game import Game
from pyminion.expansions.base import silver, gold, province, smithy

class BigMoneySmithy(Bot):

    def __init__(
        self,
        player_id: str = "big_money_smithy",
    ):
        super().__init__(player_id=player_id)

    def action_priority(self, game: Game):
        yield smithy

    def buy_priority(self, game: Game):
        money = self.state.money
        if money >= 8:
            yield province
        if money >= 6:
            yield gold
        if money == 4:
            yield smithy
        if money >= 3:
            yield silver

To see other bot implementations with more advanced decision trees, see /bots

Running Simulations

Simulating multiple games is good metric for determining bot performance. To create a simulation, pass a pyminion game instance into the Simulator class and set the number of iterations to be run.

from pyminion.simulator import Simulator

bm = BigMoney()
bm_smithy = BigMoneySmithy()

game = Game(players=[bm, bm_smithy], expansions=[base_set])
sim = Simulator(game, iterations=1000)
sim.run()

with the following terminal output:

~$ python simulation.py
Simulation of 1000 games
big_money wins: 16.8% (168)
big_money_smithy wins: 57.5% (575)
Ties: 25.7% (257)

Please see /examples to see demo scripts.

Support

Please open an issue for support.

Contributing

Install this library, test it out, and report any bugs. A welcome contribution would be to create new bots, especially an implementation that uses machine learning to determine optimal play.

If you would like to contribute, please create a branch, add commits, and open a pull request.

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

pyminion-0.2.2.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

pyminion-0.2.2-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file pyminion-0.2.2.tar.gz.

File metadata

  • Download URL: pyminion-0.2.2.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for pyminion-0.2.2.tar.gz
Algorithm Hash digest
SHA256 562aafece6f7e59d014798c49bfccef4a953ad987f07354c61686b8fc38eaad4
MD5 21935d21b4a1bc8b3d3a5212ae7b16d2
BLAKE2b-256 5f65cd8e49ba1d677e3748dbf5bd1d9b42ab2a493c2d8642f9fe37ec0542332b

See more details on using hashes here.

File details

Details for the file pyminion-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyminion-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for pyminion-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8fab6a7cd7a9b4c0a2f74275be18e493f15be438341a17c0aad909b78b822e9f
MD5 3bd3a45b0f82af1d1b1f88146eb52e97
BLAKE2b-256 9e40fb3126d91da6adfb691f8149443b127e8c720392779846cf032915e38001

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