Skip to main content

PyPI Release Docker CI

ChessLib Python Extension

About

This project provides an efficient chess draw generation extension for Python3. The main purpose of this project is enabling further TensorFlow AI projects and learning how to write an efficient Python3 extension (using good old C).

Usage

Install the official Python package using pip:

pip install chesslib

For implementing a chess AI, see following example applying randomly selected actions until the chess game is over. You might use this code snippet and make your AI choose more sophisticated actions instead of random ones, that's already it - as simple as that.

import chesslib
import numpy as np


def choose_action(board, drawing_side, last_draw):
    poss_actions = chesslib.GenerateDraws(board, drawing_side, last_draw, True)
    return np.random.choice(poss_actions)


def main():

    # init cache variables
    last_draw = chesslib.ChessDraw_Null
    board = chesslib.ChessBoard_StartFormation()
    drawing_side = chesslib.ChessColor_White

    # init game state
    state = chesslib.GameState_None
    game_over_states = [chesslib.GameState_Checkmate, chesslib.GameState_Tie]

    # log the start formation to console
    print('start of game')
    print(chesslib.VisualizeBoard(board))

    # continue until the game is over
    while state not in game_over_states:

        # choose an action and apply it to the board
        next_action = choose_action(board, drawing_side, last_draw)
        board = chesslib.ApplyDraw(board, next_action)

        # update the cache variables
        last_draw = next_action
        drawing_side = 1 - drawing_side # alternate between white and black side
        state = chesslib.GameState(board, last_draw)

        # log the game progress to console
        print()
        print(chesslib.VisualizeDraw(next_action), f'state={state}')
        print(chesslib.VisualizeBoard(board))

    # log the game's outcome to console
    winning_side = "black" if drawing_side == chesslib.ChessColor_White else "white"
    print('tie' if state == chesslib.GameState_Tie else f'{winning_side} player won')


if __name__ == '__main__':
    main()

Following example outlines some of the chesslib API functionality like applying / reverting draws, creating board hashes or visualizing boards / draws properly as human-readable texts:

import chesslib
import numpy as np


def main():

    # create a new chess board in start formation
    board = chesslib.ChessBoard_StartFormation()
    
    # generate all possible draws
    draws = chesslib.GenerateDraws(board, chesslib.ChessColor_White, chesslib.ChessDraw_Null, True)
    
    # apply one of the possible draws
    draw_to_apply = draws[random.randint(0, len(draws) - 1)]
    new_board = chesslib.ApplyDraw(board, draw_to_apply)
    
    # write the draw's name
    print(chesslib.VisualizeDraw(draw_to_apply))
    
    # visualize the board before / after applying the draw
    print(chesslib.VisualizeBoard(board))
    print(chesslib.VisualizeBoard(new_board))
    
    # revert the draw (just call ApplyDraw again with the new board)
    rev_board = chesslib.ApplyDraw(new_board, draw_to_apply)
    
    # get the board's 40-byte-hash and create a new board instance from the hash
    board_hash = chesslib.Board_ToHash(board)
    board_reloaded = chesslib.Board_FromHash(board_hash)
    
    # see tests/ folder for more examples


if __name__ == '__main__':
    main()

How to Develop

For a quickstart, set up your dev machine as a VM (e.g. Ubuntu 20.04 hosted by VirtualBox). After successfully creating the VM, use following commands to install all essential dev tools (git, docker, good text editor).

# install docker (e.g. Ubuntu 20.04)
sudo apt-get update && sudo apt-get install -y git docker.io
sudo usermod -aG docker $USER && reboot

# download the project's source code (if you haven't done before)
git clone https://github.com/Bonifatius94/ChessLib.Py
cd ChessLib.Py

# install the 'Visual Studio Code' text editor (optional)
sudo snap install code --classic

The commands for dev-testing the chesslib are wrapped within a Docker environment. Therefore build the 'Dockerfile-dev' file which takes your source code and performs all required CI steps (build + install + unit tests). Afterwards you may attach to the Docker image with the bash console interactively and run commands, etc.

# make a dev build using the 'Dockerfile-dev' build environment
# this runs all CI steps (build + install + unit tests)
docker build . --file Dockerfile-dev -t "chesslib-dev"

# attach to the build environment's interactive bash console (leave the session with 'exit')
docker run -it "chesslib-dev" bash

# mount a Python test script into the build environment and run it
docker run -v $PWD:/scripts "chesslib-dev" python3 /scripts/test.py

# debug the GitHub release pipeline
docker run -v $PWD/dist:/output -v $PWD:/build -it "chesslib-dev" bash

See the GitHub wiki for more details.

This software is available under the MIT licence's terms.

Metadata

Release files for chesslib 1.0.340454915

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for chesslib 1.0.340454915
File
chesslib-1.0.340454915-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
chesslib-1.0.340454915-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.5+ x86-64 Details
chesslib-1.0.340454915-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.12+ x86-64, Linux glibc 2.5+ x86-64 Details
chesslib-1.0.340454915-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
chesslib-1.0.340454915-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details
chesslib-1.0.340454915-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64, Linux glibc 2.5+ x86-64 Details
chesslib-1.0.340454915-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
chesslib-1.0.340454915-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
chesslib-1.0.340454915-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64, Linux glibc 2.12+ x86-64 Details
chesslib-1.0.340454915-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
chesslib-1.0.340454915-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
chesslib-1.0.340454915-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64, Linux glibc 2.5+ x86-64 Details

Total release size: 750.6 kB

Release files / chesslib-1.0.340454915-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chesslib-1.0.340454915-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 65.6 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
00b0128cfcd7a9d066c8616258317d1b1c0f21b2537ce3f3cc586247984a2123
BLAKE2b-256 checksum
How to use checksums
fb01fd8bfe60a25c122e00481b803a555bb6d6c165ceeebb8cbc23e0c0c95916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL chesslib-1.0.340454915-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 55.8 kB
Tags CPython 3.9 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
c06a8b9a7a334c3ddfd00080882d511a2598a3fb168069da8b4358c2c142de2c
BLAKE2b-256 checksum
How to use checksums
1ca3e664f2f732701ccf300442a285431e7181277b8afb4ed0a7c2e4a3c71cde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl

Download URL chesslib-1.0.340454915-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 65.2 kB
Tags CPython 3.9 Linux glibc 2.12+ x86-64 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
bc295f7fba0e29206c6d39f8161ff85e02023b267863f1ec3150e3ecace9eb45
BLAKE2b-256 checksum
How to use checksums
a110ab2b5f19608cee2204bc197e35e95f28a19230c25784822a5f84d257d9ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chesslib-1.0.340454915-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 66.1 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1cffd7b4ebe2149f3319fd5cfd1b705843ecfc607e1d5becff61189a3434b02e
BLAKE2b-256 checksum
How to use checksums
dc3b2fff89e317ae5be8ea1e3aa2eb9402c1b191c8d88a71fbf7cf3247503690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL chesslib-1.0.340454915-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 56.2 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
c4ea5693adf6a53f9303bbb87045ed1c2e6a00014d812426cf994692d877e1b0
BLAKE2b-256 checksum
How to use checksums
af09378f66be003d9e4599f2c0234a912224fd25db992dde8bf0b0bad1dc8849
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl

Download URL chesslib-1.0.340454915-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 65.6 kB
Tags CPython 3.8 Linux glibc 2.12+ x86-64 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
1ad36e46d0900975f6563ab64e18b850843f3cf0ead7ae0df7c94244f177789f
BLAKE2b-256 checksum
How to use checksums
bb64cd4975212372d9e9ca1c3fc458d80ee353e719a8662410d0e9d781f42246
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chesslib-1.0.340454915-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 66.9 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e9dffcfaeacaf70eeb3a6991e7b9c41e5866c079c2919c767574e988f2b66d05
BLAKE2b-256 checksum
How to use checksums
494a459c162e8935531fe8dde6e392ccb8a0d1a34027d600e1a4777b6e817509
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL chesslib-1.0.340454915-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 55.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
df58a18191392c531845ebfd8cf150ea21894b052eea2798587ade52aede4787
BLAKE2b-256 checksum
How to use checksums
a081d4da0a21558265e70a4c5c9e91ed8d588e3d409ad2db0b1a00202f481fa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl

Download URL chesslib-1.0.340454915-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 66.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
7c67530759dd069e62d6958edaec2ec19a5b71959cb6c4a1b344d85f354bf910
BLAKE2b-256 checksum
How to use checksums
43767ea6f85ca7e31c19884e46b586ee6368f5e2af34f8ad9cadbef99566693a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chesslib-1.0.340454915-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 65.9 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c258ba2d78981214db92333e933392fd1d05fbf7b8a70c16085c11d40f21f465
BLAKE2b-256 checksum
How to use checksums
bbdf6fdb12977fc15a11e32ca3cc166348cef56a3ab05917e4c3ae9f8bece1d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl

Download URL chesslib-1.0.340454915-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 55.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
c716f547b993b11baef851236dc0fa028093743ed6649ed6a098e16f4aff253d
BLAKE2b-256 checksum
How to use checksums
ba9c2126df4990ba29ab1322c1587ab479f2442efa992de538448cc776b03df1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release files / chesslib-1.0.340454915-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl

Download URL chesslib-1.0.340454915-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 65.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
0a48f8310a77ad9c2571067b4cffdd62e39395ddfe981020925eed9f7003a3b2
BLAKE2b-256 checksum
How to use checksums
01d37f43528bfd8ce4661a0e75e6795eb9797ee78d778edfeac3636259e0549c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

Release history Release notifications | RSS feed

This release

1.0.340454915 This release

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page