Skip to main content

Sente: a Python 3 native library for the game of Go.

Project description

drawing

PyPI version docs tests pip

Sente (from the Japanese せんて/先手) is a general-purpose open-source python library for the ancient chinese board game Go/Badok/Weiqi. It allows for python code to simulate and play a game of Go and also read, edit and create SGF files. Sente is designed to be a Python 3 replacement for the gomill library. In addition to supporting Python 3, Sente is written in C++ which allows AIs that use Sente to take advantage of C++'s superior performance.

Installation & Requirements

Sente runs on any operating system with python 3.8+ and can be installed via pip.

$ pip install sente

-- or --

$ python3 -m pip install sente

Getting Started

The Basic element in Sente is the sente.Game object which represents a Simple Game.

>>> import sente
>>> game = sente.Game()

By default, sente creates a 19x19 game with Chinese Rules. 9x9 and 13x13 board sizes and Japanese rules can be specified if desired.

note: japanese rules are not reccomended as sente does not currently include automatic dead stone removal.

>>> game = sente.Game(13)
>>> game = sente.Game(19, sente.rules.JAPANESE)

moves can be played on the game using the play() method, and the board can be printed using the python print() function.

>>> game.play(4, 4)
>>> game.play(4, 16)
>>> game.play(17, 4)
>>> print(game)
 1  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 2  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 3  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 4  .  .  .  ⚫ .  .  .  .  .  *  .  .  .  .  .  *  ⚫ .  .
 5  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 6  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 7  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 8  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 9  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
10  .  .  .  *  .  .  .  .  .  *  .  .  .  .  .  *  .  .  .
11  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
12  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
13  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
14  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
15  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
16  .  .  .  ⚪ .  .  .  .  .  *  .  .  .  .  .  *  .  .  .
17  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
18  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
19  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
    A  B  C  D  E  F  G  H  J  K  L  M  N  O  P  Q  R  S  T

The text created by printing a Sente board is designed to be similar to the gomill ascii boards output. Unlike Gomill however, Sente uses unicode characters to represent black and white stones to make complex board positions more visible and also plots star points.

Finally, Sente also provides utilities for reading and saving SGF files using the sente.SGF module

>>> from sente import sgf
>>> game = sgf.load("Lee Sedol ladder game.sgf")
>>> move_sequence = game.get_default_sequence()[:95]
>>> game.play_sequence(move_sequence)
>>> print(game)
1  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
2  . .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
3  .  . .  .  .  .  .  .  .  . .  .  .  .  .
4  .  .  . . .  .  .  *  .  .  .  .  . .  .  .
5  .  . .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
6  .  . .  .  .  .  .  .  .  .  .  .  .  .  .  .
7  .  . .  .  .  .  .  .  .  .  .  .  .  .  .
8  .  .  . .  .  .  .  .  .  .  .  .  .  .  .
9  .  .  .  . .  .  .  .  .  .  .  .  .  .  .
10  .  .  .  *  . *  .  .  .  .  .  *  . .
11  .  .  .  .  .  . .  .  .  . . .
12  .  .  .  .  .  .  . . . .
13  .  .  .  .  .  .  .  . .
14  .  .  .  .  .  .  .  .  .
15  .  . .  .  .  .  .  .  .  .
16  .  .  .  *  .  .  .  .  .  *  .  . .  . .
17  .  .  . .  .  .  . .  .  .  .
18  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
19  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . .
    A  B  C  D  E  F  G  H  J  K  L  M  N  O  P  Q  R  S  T

Further Reading

Building & Contributing

Sente uses CMake, git and C++17. In order to build the library, you will need CMake, and a C++ compiler that supports C++17. You can install these using a software package installer like homebrew or apt.

OSx

$ brew install git
$ brew install cmake
$ xcode-select --install  # installs Apple clang++

Debian/Ubuntu

$ sudo apt-get install git
$ sudo apt-get install cmake
$ sudo apt-get install g++

A sente binary can be built by running the setup script.

$ python3 setup.py develop

To import the resulting .so file, simply import sente in a local python interpreter

$ python3 setup.py develop
$ python3
Python 3.8.10 (v3.8.10:3d8993a744, May  3 2021, 09:09:08) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sente
>>> 

Building documentation

in order to build the documentation, you will need to have sphinx installed and build a development version of sente.

$ pip install -r requirements.txt # install sphinx
$ python setup.py develop # build a development version of sente
$ cd docs
$ make html # make the html

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

sente-0.4.2.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distributions

sente-0.4.2-pp39-pypy39_pp73-win_amd64.whl (265.2 kB view hashes)

Uploaded PyPy Windows x86-64

sente-0.4.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (361.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

sente-0.4.2-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (386.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

sente-0.4.2-pp39-pypy39_pp73-macosx_11_0_x86_64.whl (329.3 kB view hashes)

Uploaded PyPy macOS 11.0+ x86-64

sente-0.4.2-pp38-pypy38_pp73-win_amd64.whl (266.4 kB view hashes)

Uploaded PyPy Windows x86-64

sente-0.4.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (361.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

sente-0.4.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (386.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

sente-0.4.2-pp38-pypy38_pp73-macosx_11_0_x86_64.whl (329.2 kB view hashes)

Uploaded PyPy macOS 11.0+ x86-64

sente-0.4.2-cp310-cp310-win_amd64.whl (267.7 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

sente-0.4.2-cp310-cp310-win32.whl (228.7 kB view hashes)

Uploaded CPython 3.10 Windows x86

sente-0.4.2-cp310-cp310-musllinux_1_1_x86_64.whl (872.2 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

sente-0.4.2-cp310-cp310-musllinux_1_1_i686.whl (952.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

sente-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (363.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

sente-0.4.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (388.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

sente-0.4.2-cp310-cp310-macosx_11_0_x86_64.whl (314.3 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ x86-64

sente-0.4.2-cp310-cp310-macosx_11_0_universal2.whl (596.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ universal2 (ARM64, x86-64)

sente-0.4.2-cp39-cp39-win_amd64.whl (267.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

sente-0.4.2-cp39-cp39-win32.whl (228.8 kB view hashes)

Uploaded CPython 3.9 Windows x86

sente-0.4.2-cp39-cp39-musllinux_1_1_x86_64.whl (872.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

sente-0.4.2-cp39-cp39-musllinux_1_1_i686.whl (952.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

sente-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (364.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

sente-0.4.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (388.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

sente-0.4.2-cp39-cp39-macosx_11_0_x86_64.whl (314.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ x86-64

sente-0.4.2-cp39-cp39-macosx_11_0_universal2.whl (596.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ universal2 (ARM64, x86-64)

sente-0.4.2-cp38-cp38-win_amd64.whl (267.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

sente-0.4.2-cp38-cp38-win32.whl (228.5 kB view hashes)

Uploaded CPython 3.8 Windows x86

sente-0.4.2-cp38-cp38-musllinux_1_1_x86_64.whl (871.6 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

sente-0.4.2-cp38-cp38-musllinux_1_1_i686.whl (951.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

sente-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (363.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

sente-0.4.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (387.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

sente-0.4.2-cp38-cp38-macosx_11_0_x86_64.whl (314.1 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ x86-64

sente-0.4.2-cp38-cp38-macosx_11_0_universal2.whl (596.2 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page