gunyarakun / python-shogi

A pure Python shogi library with move generation and validation and handling of common formats.
GNU General Public License v3.0
179 stars 43 forks source link

python-shogi: a pure Python shogi library

.. image:: https://coveralls.io/repos/gunyarakun/python-shogi/badge.svg :target: https://coveralls.io/r/gunyarakun/python-shogi

.. image:: https://badge.fury.io/py/python-shogi.svg :target: https://pypi.python.org/pypi/python-shogi

.. image:: https://github.com/gunyarakun/python-shogi/actions/workflows/pythonpackage.yml/badge.svg :target: https://github.com/gunyarakun/python-shogi/actions/workflows/pythonpackage.yml

.. image:: https://github.com/gunyarakun/python-shogi/actions/workflows/codeql-analysis.yml/badge.svg :target: https://github.com/gunyarakun/python-shogi/actions/workflows/codeql-analysis.yml

Introduction

This is the module for shogi written in Pure Python. It's based on python-chess commit <https://github.com/niklasf/python-chess/commit/6203406259504cddf6f271e6a7b1e04ba0c96165>__

This is the scholars mate in python-shogi:

.. code:: python

>>> import shogi

>>> board = shogi.Board()

>>> board.push(shogi.Move.from_usi('7g7f'))

>>> board.push_usi('3c3d')
Move.from_usi('3c3d')
>>> board.push_usi('8h2b+')
Move.from_usi('8h2b+')
>>> board.push_usi('4a5b')
Move.from_usi('4a5b')
>>> board.push_usi('B*4b')
Move.from_usi('B*4b')
>>> board.push_usi('5a4a')
Move.from_usi('5a4a')
>>> board.push_usi('2b3a')
Move.from_usi('2b3a')
>>> board.is_checkmate()
True

Features

Performance

python-shogi is not intended to be used by serious shogi engines where performance is critical. The goal is rather to create a simple and relatively highlevel library.

You can install the gmpy2 <https://pypi.org/project/gmpy2> or gmpy <https://pypi.org/project/gmpy> modules in order to get a slight performance boost on basic operations like bit scans and population counts.

python-shogi will only ever import very basic general (non-shogi-related) operations from native libraries. All logic is pure Python. There will always be pure Python fallbacks.

Installing

How to test

::

make test

If you want to print lines from the standard output, execute nosetests like following.

::

poetry run nosetests -s

How to release

::

poetry config repositories.testpypi https://test.pypi.org/legacy/

poetry config pypi-token.testpypi "Test PyPI API Token"

make test-upload

poetry config pypi-token.pypi "PyPI API Token"

make upload

ToDo