Skip to main content

Python Implementation of Marjapussi.

Project description

MarjaPussi

Python implementation of MarjaPussi, mostly following the rules from Wurzel e. V., exactly following the rules on marjapussi.de.

This package is used by the backend of marjapussi.de.

Installation

Requires Python >= 3.12.

pip install marjapussi

or

pixi add --pypi marjapussi

Quick start

import random
from marjapussi.game import MarjapussiGame

# Cards are shuffled and dealt automatically
game = MarjapussiGame(player_names=("Alice", "Bob", "Charlie", "Diana"))

# Start all players, then play until the game ends
while not game.finished:
    action = random.choice(game.legal_actions())
    game.apply_action(action)

# Serialisable result with scores, tricks, and outcome
info = game.to_finished_info()
print(info.model_dump_json(indent=2))

Core concepts

Game loop

Every game follows the same pattern:

  1. Create a MarjapussiGame with player names and dealt hands.
  2. Call game.legal_actions() to get the list of valid actions for the current state.
  3. Pick one and pass it to game.apply_action(action).
  4. Repeat until game.finished is True.

Phases

The game progresses through these phases automatically:

Phase Description
WaitingForStart Players confirm readiness
Bidding Players bid for the right to play
PassingForth / PassingBack Partners exchange 4 cards each
Raising Playing player may raise the game value
StartTrick Trick leader may announce trump or ask partner before playing
Trick Remaining players follow suit
AnsweringPair / AnsweringHalf Partner responds to trump questions
Ended Game is over

Actions

All actions are Pydantic models (GameAction) with a typed action_type and a player seat. Action types include Start, StopBidding, NewBid, Pass, CardPlayed, AnnounceTrump, Question, and Answer.

Replay

Any game can be reconstructed from its metadata and action log:

from marjapussi.game import MarjapussiGame

replayed = MarjapussiGame.replay(info.info, game.actions)
assert replayed.to_finished_info() == info

Types

Type Module Description
Card marjapussi.types Immutable card with suit and value, serialises as "r-A"
Suit marjapussi.types Green, Acorns, Bells, Red
Value marjapussi.types Six through Ace
PlaceAtTable marjapussi.types Seat index 0-3 with .partner(), .next(), .prev()
Points marjapussi.types Integer wrapper with arithmetic support
GameFinishedInfo marjapussi.state Full game result including tricks, scores, and events

Development

pixi install
pixi run test

Contributing

Pull requests and feedback are welcome. If you think something is wrong or could be improved, feel free to open an issue or reach out.


Legacy implementation (v1)

The original implementation is still available under marjapussi.legacy. It uses plain Python classes with string-based actions and is fully preserved for backward compatibility.

import random
from marjapussi.legacy.game import MarjaPussi

game = MarjaPussi(["Name1", "Name2", "Name3", "Name4"])

while not game.phase == "DONE":
    action = random.choice(game.legal_actions())
    game.act_action(action)

Actions are strings in the format "<player>,<phase>,<value|card>", for example "0,PROV,120" or "2,TRCK,r-A".

A compatibility layer in marjapussi.compat provides converters between the two formats:

from marjapussi.compat import v1_action_to_v2, v2_action_to_v1, v1_actions_to_v2

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

marjapussi-1.1.0.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

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

marjapussi-1.1.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file marjapussi-1.1.0.tar.gz.

File metadata

  • Download URL: marjapussi-1.1.0.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for marjapussi-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a70ed983253322fd4db988b3508801c6c51f7c701eec56f477b1a1727cf28a66
MD5 f1718794c46782332aee5bb943d0c796
BLAKE2b-256 b4155807f7c7c52c63676481bfea6afd70e615599b649127b8f0a987dc3f3789

See more details on using hashes here.

File details

Details for the file marjapussi-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: marjapussi-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for marjapussi-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b05a2bf974b6b99d9778ece673af385b296e7a49823ba429b4ade93decad6c18
MD5 d237af52d7b839daad77a4d9deafabbb
BLAKE2b-256 d15ca88555f42f4f8bd8466d21119d0436970a748dd4605d61a68652b630f313

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