Skip to content

yotaroy/bridge_env

Repository files navigation

Contract Bridge Environment for Python

bridge_env is a python package for contract bridge. bridge_env supports a network bridge used in the World Computer Bridge Championships.

Install bridge_env

Run on the root directory of this repository.

pip install .

Install with packages for development, run

pip install '.[dev]'

Network bridge

Protocol is version 18.

Server

Run server.

bridge-server [-h] [-p PORT] [-i IP_ADDRESS] [-b BOARD_SETTING] \
    [-r RESTART_INDEX] [-o OUTPUT_FILE]

# optional arguments:
#   -h, --help            show this help message and exit
#   -p PORT, --port PORT  Port number. (default=2000)
#   -i IP_ADDRESS, --ip_address IP_ADDRESS
#                         IP address. (default=localhost)
#   -b BOARD_SETTING, --board_setting BOARD_SETTING
#                         Board settings file (.json or .pbn).
#   -r RESTART_INDEX, --restart_index RESTART_INDEX
#                         Index of board settings to restart. (0-idx, default=0)
#   -o OUTPUT_FILE, --output_file OUTPUT_FILE
#                         Output file path (.json or .pbn file).
#                         File will be overwritten. (default="output.json")

If a board settings file is not set, randomly generated 100 boards setting is used.

Use docker

Build an image from a Dockerfile.

docker build -t yotaroy/bridge-server:v0.2.0 \
  -f ./docker/network_bridge/Dockerfile .

Run a container for bridge-server.

docker run -it --rm yotaroy/bridge-server:v0.2.0 [OPTIONAL ARGUMENTS]

Optional arguments are same as the above.

Client

Run an example client.

bridge-client-ex [-h] [-p PORT] [-i IP_ADDRESS] [-l LOCATION] [-t TEAM_NAME]

# optional arguments:
#   -h, --help            show this help message and exit
#   -p PORT, --port PORT  Port number. (default=2000)
#   -i IP_ADDRESS, --ip_address IP_ADDRESS
#                         IP address. (default=localhost)
#   -l LOCATION, --location LOCATION
#                         Player location. (N, E, S or W)
#   -t TEAM_NAME, --team_name TEAM_NAME
#                         Team name.

Board setting and log formats

Server can read board settings in PBN or JSON file. Game log outputted by server follows PBN or JSON formats below.

Board setting in JSON is defined in json schema. Game log in JSON is defined in json schema. See README for more information about JSON format.

Board setting in PBN (v2.1) is defined in http://www.tistis.nl/pbn/pbn_v21.txt as "import format". Game log in PBN (v2.1) is defined in http://www.tistis.nl/pbn/pbn_v21.txt as "export format". See http://www.tistis.nl/pbn/ for more information about PBN format.

Requirements

  • Python >= 3.7
  • numpy

For development

Requirements for development

  • flake8
  • mypy
  • pytest
  • pytest-mock

You can install them from requirements.txt.

pip install -r requirements.txt

Test

pytest -vv

Type check

mypy --ignore-missing-imports .

Lint

flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

flake8 . --count --exit-zero --max-complexity=10 --max-line-length=80 --statistics

License

MIT License

About

Contract Bridge Environment package in Python

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors