Skip to main content

Dominion but make it python

Project description

Pyminion

tests codecov

pyminion-logo

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

Installation

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.expansions.intrigue import intrigue_set
from pyminion.game import Game
from pyminion.bots.examples import BigMoney
from pyminion.human import Human

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

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

# Play game
game.play()

Creating Bots

Defining new bots is relatively straightforward. Inherit from the BotDecider 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, BotDecider
from pyminion.expansions.base import gold, province, silver, smithy
from pyminion.player import Player
from pyminion.game import Game

class BigMoneySmithyDecider(BotDecider):
    """
    Big money + smithy

    """

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

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

class BigMoneySmithy(Bot):
    def __init__(
        self,
        player_id: str = "big_money_smithy",
    ):
        super().__init__(decider=BigMoneySmithyDecider(), player_id=player_id)

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.bots.examples import BigMoney, BigMoneySmithy
from pyminion.expansions.base import base_set, smithy
from pyminion.game import Game
from pyminion.simulator import Simulator

bm = BigMoney()
bm_smithy = BigMoneySmithy()

game = Game(players=[bm, bm_smithy], expansions=[base_set], kingdom_cards=[smithy], log_stdout=False)
sim = Simulator(game, iterations=1000)
result = sim.run()
print(result)

with the following terminal output:

~$ python simulation.py
Simulation Result: ran 1000 games
big_money won 110, lost 676, tied 214
big_money_smithy won 676, lost 110, tied 214

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.4.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

pyminion-0.4.0-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyminion-0.4.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for pyminion-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b0a523cfeec1ff54027d834a83db30dc0ab10e54af365a69488d242c5796a066
MD5 4113cd8bb9b1dde3bc0fd58385c439f0
BLAKE2b-256 bbb9cf5bda12e2cee970f8ff406a958d6148e55a88f7d8a4300bd69984a50c22

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyminion-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for pyminion-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88e1265ee7803a20514bbf36a2fb262ec24b960976700718aad7b43fad739f2a
MD5 a3802415742880ee78b313ec91388072
BLAKE2b-256 83a7b0e40f00910c8290e4f0ac12b622b64e419acf623e7205fb3140f45d32ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page