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.

Copyright

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

Metadata

Release files for chesslib 1.0.340699405

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.340699405
File
chesslib-1.0.340699405-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.340699405-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.340699405-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.340699405-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.340699405-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.340699405-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.5+ x86-64, Linux glibc 2.12+ x86-64 Details
chesslib-1.0.340699405-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.340699405-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.340699405-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.340699405-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.340699405-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.340699405-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.5+ x86-64, Linux glibc 2.12+ x86-64 Details

Total release size: 746.5 kB

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

Download URL chesslib-1.0.340699405-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 62.8 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1d55f7746630b1f4960dd15fd6319c631dcc38e048a0b677a40431e3702f7cc5
BLAKE2b-256 checksum
How to use checksums
4c84248dbfa853378dbd52c37235fd2bc168e2337b82a7b4b2ddb8cf3e2dffe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

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

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

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

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

Download URL chesslib-1.0.340699405-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 63.0 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a70a65153303e336939af6533ba60b81d043db156a10fedec624345cf71b4f1c
BLAKE2b-256 checksum
How to use checksums
6aa89b0202797694fc8792e7afd6c6e12c162735ee894981292a824bec3b520d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

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

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

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

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

Download URL chesslib-1.0.340699405-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 62.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
73764a01997d2320448f48cc57051676f04f36255c250ff2b66d94a66657fe36
BLAKE2b-256 checksum
How to use checksums
db6d639b51aee90ea8358e46a5350149037c1fe0a0e7713b1745a2dd317fe96f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

Download URL chesslib-1.0.340699405-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 56.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
6c058da907596872196755f57420fd95990f35eaf3d1bfb32ab75a609ed77d54
BLAKE2b-256 checksum
How to use checksums
9bd4ca3ce7a5614e44fbed6c474588d0090eae48d0759f44de2416884c1674d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

Download URL chesslib-1.0.340699405-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 67.6 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
8338b295a7293e52ab30ce16d87a8362d886d97683f56b46c54ac24cc493c813
BLAKE2b-256 checksum
How to use checksums
f21cfb2858596e8c22fed7956b24c3a97e625aab5e41100cd20961b5782f14cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

Download URL chesslib-1.0.340699405-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 62.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9c79ac7ac1506b276bd5a9ca0bff06823f07a1d02deb77e6a781684edb943b12
BLAKE2b-256 checksum
How to use checksums
4a93e1042b714de3445c60bf3f1cec384df603735f361bc06fab0c773d72f2bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

Download URL chesslib-1.0.340699405-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Size 56.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
23d15f96a6468682c005cd3c4a90c457ba4a4367949e2ac994531be266d478b6
BLAKE2b-256 checksum
How to use checksums
884f66b63ce098a5ccee91562f72bec4d2fd45091cf5bdaf55979925389c9700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

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

Download URL chesslib-1.0.340699405-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 66.6 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
8d58a540f4c03b846a3b6ee93999fe5c16d8ff131b53fd606958688b1d8a90c2
BLAKE2b-256 checksum
How to use checksums
749c02b9ff32aa2be37e32cead0a223ce50ff1b06ad1bc31f85b5641e7c7e439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

Release history Release notifications | RSS feed

This release

1.0.340699405 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