bridgepy
bridgepy is a Python package for playing floating bridge!
Game state
The heart of this project is in the game state below
Quick Guide
from bridgepy.datastore import Datastore
from bridgepy.player import PlayerId, PlayerAction
from bridgepy.game import GameId, Game
from bridgepy.card import Card
from bridgepy.bid import Bid
from bridgepy.bridge import BridgeClient
Step 1: Create your own datastore for Game and override insert, update, delete, and query
In this example, is a local datastore
class GameLocalDataStore(Datastore[GameId, Game]):
def __init__(self) -> None:
self.games: list[Game] = []
def insert(self, game: Game) -> None:
i = self.__query_index(game.id)
if i is not None:
return
self.games.append(game)
def update(self, game: Game) -> None:
i = self.__query_index(game.id)
if i is None:
return
self.games = self.games[:i] + [game] + self.games[i+1:]
def delete(self, id: GameId) -> None:
i = self.__query_index(id)
if i is None:
return
self.games = self.games[:i] + self.games[i+1:]
def query(self, id: GameId) -> Game | None:
i = self.__query_index(id)
if i is None:
return None
return self.games[i]
def __query_index(self, id: GameId) -> int | None:
for i in range(len(self.games)):
if self.games[i].id == id:
return i
return None
Step 2: Inject your game datastore to bridge client
In this example, is injecting the local datastore to the bridge client
game_datastore = GameLocalDataStore()
client = BridgeClient(game_datastore)
Step 3: Let 1 player create a game, and let 3 other players join the game
game_id = GameId("1")
player_id1 = PlayerId("111")
player_id2 = PlayerId("222")
player_id3 = PlayerId("333")
player_id4 = PlayerId("444")
client.create_game(player_id1, game_id)
client.join_game(player_id2, game_id)
client.join_game(player_id3, game_id)
client.join_game(player_id4, game_id)
Step 4: Let players bid, choose partner, and trick
player_id = player_id2 # replace with player_id1, player_id2, player_id3, player_id4
# player polls for their game snapshot (maybe every 5 seconds)
snapshot = client.view_game(player_id, game_id)
print(snapshot)
if PlayerAction.BID in snapshot.player_actions:
print("bid turn")
bid_input = input() # 1C for 1 club, 2NT for 2 no trump, None for pass
bid = None if bid_input == "" else Bid.from_string(bid_input)
client.bid(player_id, game_id, bid)
if PlayerAction.CHOOSE_PARTNER in snapshot.player_actions:
print("choose partner")
partner_input = input() # AC for ace club, 2H for 2 heart, 10S for 10 spade
client.choose_partner(player_id, game_id, Card.from_string(partner_input))
if PlayerAction.TRICK in snapshot.player_actions:
print("trick turn")
trick_input = input() # AC for ace club, 2H for 2 heart, 10S for 10 spade
client.trick(player_id, game_id, Card.from_string(trick_input))
if PlayerAction.RESET in snapshot.player_actions:
print("reset")
reset_input = input() # y for yes
if reset_input == "y":
client.reset_game(player_id, game_id)
Metadata
Release files for bridgepy 0.0.13
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 | Actions |
|---|---|---|---|---|
| bridgepy-0.0.13.tar.gz | 12.2 kB | Without provenance | Details for bridgepy-0.0.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bridgepy-0.0.13-py3-none-any.whl | Python 3 | none | any | Details for bridgepy-0.0.13-py3-none-any.whl |
Total release size: 23.3 kB
Release files / bridgepy-0.0.13.tar.gz
| Download URL | bridgepy-0.0.13.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d259a760a125b366da30cc690267caa7277f4803f7a4f86dfd22c26f1f53360
|
|
BLAKE2b-256 checksum How to use checksums |
97db8d51d9dedd8554288eca5f06c437bfa9734814a885395ec9020623367447
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.13
|
Release files / bridgepy-0.0.13-py3-none-any.whl
| Download URL | bridgepy-0.0.13-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73534776308b774330035d452ec38366121f2505c73f7fa9977cc7dec13cb351
|
|
BLAKE2b-256 checksum How to use checksums |
0d257d6b8c5c1663de86d5f16bf5aa938edb4da3bcf9228f5866b05b34a0ed1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.13
|
Security for bridgepy 0.0.13
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.