Giter Site home page Giter Site logo

lichess_puzzles_to_pdf's Introduction

Chess Puzzles to PDF booklet1

What this site provides

  • a collection of PDF files (A4), evtl. for your personal printout as a booklet1,
  • some scripts that has been used for its generation, and
  • this readme with a description about the PDF compilation.

My intention

... was to support myself learning chess.

Starting chess learning at lichess.org which has a good entry point for online-training, I like to have a couple (e.g. ten) of these puzzles as a printout, to take them with me for later offline-walkthrough.

After some googling I found the lichess puzzle database giving us access to lots of the puzzle as a free download of the CSV-formated data.

Steps

... to prepare the PDF-collection

  1. Install a MySQL or MariaDB database, for later accessing the puzzles' data, etvl. plus an apache Webserver, a PHP and the phpMyAdmin - alternatively you may use XAMPP, which has that environment in one package.
  2. Download the puzzle's CSV-file from lichess puzzle database
  3. (optionally) split the large file into multiple smaller files with split command, e.g. split -l 1000 <input-filename>
  4. Import the CSV-file into your database
  5. add some columns e.g. for tuning the access to a group of puzzles by its theme. The CSV-file has a column that lists for each puzzle the themes belonging to that puzzle. There are less than 64 themes, so I used the set type and made a view for each theme with the same columns
  6. use the Python script from this repository generate_theme_puzzles.py to generate for each theme (that are the views in your database) a dedicated subdirectory with ten puzzles' HTML-files
    • The Python script uses the python-chess to parse the FEN2 and UCI moves3 to generate the SVG4 chess board diagrams.
  7. use google-chrome --headless to generate for each HTML-file a PDF-file
    • e.g.
      • for one file: google-chrome --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf=underPromotion_00001.pdf underPromotion_00001.html
      • for multiple files: ls *.html | awk '{html = $1; gsub(/html/, "pdf", $1); pdf = $0; print "google-chrome --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf=",pdf, html}' | sed -e 's/= /=/g' | while read -r line; do $line; done
      • wkhtmltopdf and python-pdfkit corrupts my A4 layout; although HTML-files has the CSS @page { size: A4 }
  8. use gs ghostscript for merging / concatination ten puzzle's PDF-files to one puzzle's PDF-file
    • e.g.
      • for all PDF-files of one puzzle: gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=../zugzwang.pdf -dBATCH $(ls -a *.pdf)

Open item

  • alternatively to python-chess SVG drawing the chessboards, use free chess fonts (chess TTF examples here). Just B/W diagrams may give more contrast; anyway seems that Latex will be best choise for this (see that paper).
  • documentation of the used database structure and used import and alter scripts
  • add some manual comments or automatically generated comments to each puzzle's move; e.g. by means of python-chess accessing the Stockfish engine
  • scripts for tasks' automation (with 1.) HTML-->PDF, 2.) merging PDFs, etc.)
  • (evtl. for another project) similar script(s) for PGN5 files or a script that takes the FEN2 plus the PGN5 of a match generating such a booklet1.

Contact

@hlotze

Footnotes

  1. booklet - one A4 sheet folded takes four pages 2 3

  2. FEN - see Wikipedia Forsyth–Edwards Notation 2

  3. UCI - see Wikipedia Universal Chess Interface

  4. SVG - see Wikipedia Scalable Vector Graphics

  5. PGN - see Wikipedia Portable Game Notation 2

lichess_puzzles_to_pdf's People

Contributors

hlotze avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

arbitre125

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.