All Projects → linrock → chess-puzzle-maker

linrock / chess-puzzle-maker

Licence: MIT license
Creates chess puzzles from chess games and positions

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to chess-puzzle-maker

chess
An R package to read, write, create and explore chess games
Stars: ✭ 60 (+76.47%)
Mutual labels:  chess, pgn, stockfish
pgn-tactics-generator
Generate chess puzzles / tactics from a pgn file
Stars: ✭ 83 (+144.12%)
Mutual labels:  chess, chess-puzzle, stockfish
stockfish-chess-web-gui
Responsive chess web GUI to play against the Stockfish 10 chess engine. Multiple web GUI implementations have also been included.
Stars: ✭ 21 (-38.24%)
Mutual labels:  chess, stockfish
blitz-tactics
Fast-paced chess tactics trainer
Stars: ✭ 137 (+302.94%)
Mutual labels:  chess, chess-puzzle
rust-pgn-reader
Fast non-allocating and streaming reader for chess games in PGN notation
Stars: ✭ 46 (+35.29%)
Mutual labels:  chess, pgn
php-chess
A chess library for PHP.
Stars: ✭ 42 (+23.53%)
Mutual labels:  chess, pgn
chessalyzer.js
A JavaScript library for batch analyzing chess games
Stars: ✭ 14 (-58.82%)
Mutual labels:  chess, pgn
liPGN
This program uses the lichess REST API to retrieve all the games of a user and transform them into a big PGN file that you can then import into your favourite game analysis tool (ie. scid)
Stars: ✭ 14 (-58.82%)
Mutual labels:  chess, pgn
kokopu
A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.
Stars: ✭ 18 (-47.06%)
Mutual labels:  chess, pgn
cm-pgn
Parse and create PGNs (Portable Game Notation for chess games)
Stars: ✭ 16 (-52.94%)
Mutual labels:  chess, pgn
stockfish.js
The strong open source chess engine Stockfish compiled to JavaScript and WebAssembly using Emscripten
Stars: ✭ 140 (+311.76%)
Mutual labels:  chess, stockfish
Realtime-OpenCV-Chess
♔ Chess-playing with Open-CV [Human vs AI (Stockfish engine)]
Stars: ✭ 18 (-47.06%)
Mutual labels:  chess
FDChessboardView
An iOS / Mac view controller for chess boards
Stars: ✭ 75 (+120.59%)
Mutual labels:  chess
jerry
Jerry - Chess Program
Stars: ✭ 79 (+132.35%)
Mutual labels:  chess
chessops
Chess and chess variant rules and operations in TypeScript
Stars: ✭ 66 (+94.12%)
Mutual labels:  chess
NextCommunity.github.io
Join FREE: Community of open-source programmers and software engineers.
Stars: ✭ 29 (-14.71%)
Mutual labels:  chess
ssh-chess
Chess over a ssh connection
Stars: ✭ 13 (-61.76%)
Mutual labels:  chess
shakmaty-syzygy
A Rust library to probe Syzygy endgame tablebases
Stars: ✭ 14 (-58.82%)
Mutual labels:  chess
OpenChess
A cross-platform chess game.
Stars: ✭ 18 (-47.06%)
Mutual labels:  chess
Batch-First
A JIT compiled chess engine which traverses the search tree in batches in a best-first manner, allowing for neural network batching, asynchronous GPU use, and vectorized CPU computations.
Stars: ✭ 27 (-20.59%)
Mutual labels:  chess

Chess puzzle maker

This is a command-line program that creates chess puzzles from positions with clear sequences of best moves. It looks for positions where a player can:

  • Checkmate the opponent in a forced sequence
  • Convert a position into a material advantage
  • Equalize a losing position

Give it a PGN with any number of games or positions and it will look for positions to convert into puzzles:

./make_puzzles.py --pgn games.pgn

Or give it a position (FEN) and it will try to create a puzzle:

./make_puzzles.py --fen "6rr/1k3p2/1pb1p1np/p1p1P2R/2P3R1/2P1B3/P1BK1PP1/8 b - - 5 26"

For a list of options:

./make_puzzles.py -h

Requirements

This requires Python 3 and a UCI-compatible chess engine such as Stockfish.

Install the required python libraries:

pip3 install -r requirements.txt

Make sure you have a version of Stockfish available in your $PATH or local directory:

  • You can install a Stockfish binary using Homebrew if you're on macOS (brew install stockfish)
  • Or install an old version of Stockfish using apt if you're on Ubuntu Linux (sudo apt install stockfish)
  • Or download an official Stockfish release from the Stockfish website
  • Or run ./build-stockfish.sh to compile the latest official Stockfish development build
  • Or run inv update-stockfish to get the latest multi-variant Stockfish fork used by Lichess

Creating puzzles

Created puzzles are printed in PGN format to standard output while errors and log messages are printed to standard error.

If you want to write created puzzles to a file, redirect standard output:

./make_puzzles.py --pgn games.pgn >> puzzles.pgn

How it works

It scans the moves of a game for mistakes, represented by large swings in position evaluation.

For each of these positions, it looks for move sequences where the player can make one clear best move.

If it finds that the position could become a puzzle, it will output the puzzle as a PGN.

Example PGN output

[FEN "6rr/1k3p2/1pb1p1np/p1p1P2R/2P3R1/2P1B3/P1BK1PP1/8 b - - 5 26"]
[PuzzleCategory "Material"]
[PuzzleEngine "Stockfish 2018-11-29 64 Multi-Variant"]
[PuzzleWinner "Black"]
[SetUp "1"]

26... Nxe5   { Nxe5  [-1.68] }
27.   Rxg8   { Rxg8  [-1.66] Rgh4 [-2.51]  Re4  [-3.51] }
27... Nxc4+  { Nxc4+ [-1.78] Rxg8 [ 3.82]  Nf3+ [ 4.79] }
28.   Kd3    { Kd3   [-1.55] Ke2  [-1.83]  Kd1  [-2.85] }
28... Nb2+   { Nb2+  [-1.78] Rxg8 [ 2.11]  Ne5+ [ 3.44] }
29.   Ke2    { Kd2   [-1.64] Ke2  [-1.74]               }

Each move in the puzzle is annotated with the best 3 candidate moves considered by the chess engine.

Example commands

To scan a PGN for positions that might be candidate puzzles without investigating any of the positions:

./make_puzzles.py --scan-only --pgn games.pgn

To start at the n-th PGN in a PGN file with lots of games:

./make_puzzles.py --start-index 1234 --pgn games.pgn

To fetch a Lichess game and save it as a PGN:

inv fetch-lichess -g 12345

To fetch all games from a Lichess tournament and save the games to PGN:

inv fetch-lichess -t 67890

You can run the whole test suite with:

inv test

Acknowledgements

This program is based on:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].