Skip to main content

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).

How to Build / Test

The commands for building the Python3 extension module and testing it properly are wrapped as a Docker image. Therefore just build the Dockerfile and use the image as base for your Python3 application importing the module.

Alternatively you could run the commands from the Dockerfile onto an Ubuntu-like machine and build the binaries on your own. I'm using the default distutils tools, so making your own builds should not be too hard to achieve.

# install docker (e.g. Ubuntu 18.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
git clone https://github.com/Bonifatius94/ChessLib.Py
cd ChessLib.Py

# build the chesslib Python3 module using the commands from the Dockerfile
# this also includes running the unit tests (Docker build fails if tests don't pass)
docker build . -t "chesslib-python3:1.0"

# run a test command using the chesslib
docker run "chesslib-python3:1.0" python3 test.py

Usage

The following sample outlines the usage of the ChessLib:

import chesslib
import numpy as np
import random


test():

    # 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 ChessLib/test.py file for more examples

Roadmap

Following features are planned for the near future:

  • change Board_ToHash() / Board_FromHash() exchange format to Python type 'bytes' or 'bytearray' for better compatibility
  • improve code coverage of unit tests
  • implement CI/CD GitHub pipelines for DockerHub and PyPi releases
  • fix all memory leaks of the lib
  • think of performence testing / performance improvements (especially draw-gen)

Following optional / fancy improvements are to be considered:

  • add fancy travis build labels, beautify README
  • add API documentation compatible with common Python linters

Copyright

You may use this project under the MIT licence's conditions.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chesslib-1.0.329342134.tar.gz (25.2 kB view details)

Uploaded Source

File details

Details for the file chesslib-1.0.329342134.tar.gz.

File metadata

  • Download URL: chesslib-1.0.329342134.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for chesslib-1.0.329342134.tar.gz
Algorithm Hash digest
SHA256 1027cc2b18b5041a3e704e27d657727a829dadae4ded85de680d325d531fb4c2
MD5 0b43a4958beede627a9d54dbf7493ced
BLAKE2b-256 407aa253baf84d47e9f3cf76f876f596af73a87a4ac7fc28b3a15df434f36806

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.340454915

12 files

1.0.340226118

12 files

1.0.340201150

12 files

1.0.340199386

12 files

1.0.340183814

12 files

1.0.340181575

12 files

1.0.340011501

12 files

1.0.340009677

12 files

1.0.333892741

12 files

1.0.333892592

2 files

1.0.333892348

3 files

1.0.333890387

6 files

1.0.333764636

15 files

1.0.333230494

15 files

1.0.329564886

15 files

1.0.329519073

15 files

1.0.329518997

15 files

1.0.329515153

15 files

1.0.329512032

15 files

1.0.329488934

15 files

1.0.329488327

15 files

1.0.329487848

15 files

1.0.329487606

9 files

1.0.329486841

3 files

1.0.329486840

1 file

1.0.329486839

1 file

1.0.329485867

5 files

1.0.329485673

2 files

1.0.329485032

1 file

1.0.329484926

1 file

1.0.329342436

1 file

This release

1.0.329342134 This release

1 file

1.0.329341051

1 file

1.0.329340798

1 file

1.0.329340261

1 file

1.0.329338076

1 file

1.0.329314133

1 file

1.0.329313826

1 file

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