Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Bitboard based chess engine and toolkit

Project description

Shatranj is an bitboard-based, Open-Source, interactive chess programming module which allows manipulation of chess positions and experimentation with search algorithms and evaluation techniques. The project goal is to write a toolkit to aid in implementing Shannon Type B chess programs. As such, execution speed becomes less important then code clarity and expressive power of the implementation language. Having been written in an interpreted language, this module allows the chess programmer to manipulate bitboards in a natural, interactive manner much like signal processing toolkits allow communication engineers to manipulate vectors of sounds samples in MATLAB. The module currenly implements a simple recursive minimax search with alphabeta pruning, iterative deepening, uses short algebraic notation, handles repetition check, and the 50 move rule. Features lacking are quiescent checks, transition tables, negascout and MTD searching.

This toolkit is available in the form of a Python module called shatranj.py. You will also likely need the opening book as well as some of the pre-built hash tables that are used throughout the module (these will be recalculated if the module cannot find the data file). Place all three files in the same directory and simply run python on the python module (“python shatranj.py”). As far as requirements, all that is needed is a recent version of the interpreted, high level language called Python (anything after version 2.3 should work fine).

Shatranj will also work as a chess engine with GUIs such as Xboard and Winboard. Both are free and and available from Tim Mann’s Chess pages. Simply send Shatranj a command line option “-xboard”. For example, with Xboard, one can use the following to play against Shatranj:

xboard -debug -size medium -fcp “/sw/bin/python -u shatranj.py -xboard “

(Note: for this to work, you need to be in the same directory as where shatranj was installed (shatranj.py, shatranj-book.bin, and shatranj-data.bin). You may also need to change the path to your python executable.)

Winboard users can use the following text saved in a batch file (kindly provided by Eber Ramirez) making sure to leave the quotes in:

“c:winboard-4.2.7winboard” -debug -size medium -fcp “c:python25python -u c:shatranjshatranj.py -xboard “

(Note: again, you’ll need to change the paths to where you installed python, winboard and shatranj. You can either type this into a shell (DOS window) or save it as a batch file and create a shortcut to this file.)

Until more documentation becomes available, here is a short paper (PDF) that explains the move generation (from the ICGA Journal Vol. 30 No.2) which is in this same repository.

Project details


Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page