Skip to main content

A simple Weiqi (Go) library for Python

Project description

weiqi.py - Library for the game of Go

This is a library for the game of Go. It is written in Python and is designed to be easy to understand and use. It is also designed to be easy to extend and modify.

Usage

To use this library, you need to have Python installed on your computer.

To install the library, you can use the following command:

pip install weiqi

To use the library, you can import it in your Python code like this:

from weiqi import Board, WeiqiGame, Player, Stone


# Example user implementation
class User:
    def __init__(self, name: str):
        self.name = name

# If you want to adapt the Player class to your User class
# you can create an adapter class like this
class PlayerAdapter(User, Player):
    def __init__(self, name: str, stone: Stone):
        User.__init__(self, name)
        Player.__init__(self, stone)

    # Override the __eq__ method to compare the user
    def __eq__(self, other):
        if not isinstance(other, PlayerAdapter):
            return NotImplemented
        return self.name == other.name and self.figure == other.figure


player_black = PlayerAdapter("Alice", Stone.BLACK)
player_white = PlayerAdapter("Bob", Stone.WHITE)

# 19x19 board
board = Board.generate_empty_board(19)

game: WeiqiGame[User] = WeiqiGame(
    player_black=player_black, player_white=player_white, board=board
)

# Then you can implement user interaction with the game
# through various interfaced (Example: CLI, GUI, etc.)
# You can also implement AI players

Testing

To run the tests, you can use the following command:

python -m unittest discover -s tests

Example

Example of the library in use

You can see an example with a simple Pygame GUI in the example/pygame_example.py file.

For starting the example, you can run the following command:

poetry install --only example
python example/pygame_example.py

After running the command, you should see a window pop up with a Go board. You can click on the board to place stones.

TODO

  • New example pygame for v0.2.0 (with the new features)
  • Implement the time control system
  • Implement the AI players

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

weiqi-0.2.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

weiqi-0.2.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file weiqi-0.2.1.tar.gz.

File metadata

  • Download URL: weiqi-0.2.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.6-arch1-1

File hashes

Hashes for weiqi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1d8a07810d1436c62f381b5cc28d6cbcc5be5ef920b28f67df88f272683a7c64
MD5 b8e1037370a29577342c028be76b3f3c
BLAKE2b-256 85c3ec90b25bc948606256360af0ae28744fd773d6047884b35f74e7008a71b3

See more details on using hashes here.

File details

Details for the file weiqi-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: weiqi-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.6-arch1-1

File hashes

Hashes for weiqi-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6462c7102bdb7459da5cbbfb621f1637774d61c2d9089f8c434c963e93fc76a
MD5 c760201e2d07b23cd01905059bbc598b
BLAKE2b-256 a9df63ab29b47b871a2dc01f66a7cf1e3d8ddfff60c8be470f200ec2c791e18c

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