chess-puzzles.html - www.codemadness.org - www.codemadness.org saait content files
 (HTM) git clone git://git.codemadness.org/www.codemadness.org
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       chess-puzzles.html (10561B)
       ---
            1 <!DOCTYPE html>
            2 <html dir="ltr" lang="en">
            3 <head>
            4         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            5         <meta http-equiv="Content-Language" content="en" />
            6         <meta name="viewport" content="width=device-width" />
            7         <meta name="keywords" content="chess, puzzles, lichess" />
            8         <meta name="description" content="Chess puzzle book generator" />
            9         <meta name="author" content="Hiltjo" />
           10         <meta name="generator" content="Static content generated using saait: https://codemadness.org/saait.html" />
           11         <title>Chess puzzle book generator - Codemadness</title>
           12         <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
           13         <link rel="stylesheet" href="print.css" type="text/css" media="print" />
           14         <link rel="alternate" href="atom.xml" type="application/atom+xml" title="Codemadness Atom Feed" />
           15         <link rel="alternate" href="atom_content.xml" type="application/atom+xml" title="Codemadness Atom Feed with content" />
           16         <link rel="icon" href="/favicon.png" type="image/png" />
           17 </head>
           18 <body>
           19         <nav id="menuwrap">
           20                 <table id="menu" width="100%" border="0">
           21                 <tr>
           22                         <td id="links" align="left">
           23                                 <a href="index.html">Blog</a> |
           24                                 <a href="/git/" title="Git repository with some of my projects">Git</a> |
           25                                 <a href="/releases/">Releases</a> |
           26                                 <a href="gopher://codemadness.org">Gopherhole</a>
           27                         </td>
           28                         <td id="links-contact" align="right">
           29                                 <span class="hidden"> | </span>
           30                                 <a href="feeds.html">Feeds</a> |
           31                                 <a href="pgp.asc">PGP</a> |
           32                                 <a href="mailto:hiltjo@AT@codemadness.DOT.org">Mail</a>
           33                         </td>
           34                 </tr>
           35                 </table>
           36         </nav>
           37         <hr class="hidden" />
           38         <main id="mainwrap">
           39                 <div id="main">
           40                         <article>
           41 <header>
           42         <h1>Chess puzzle book generator</h1>
           43         <p>
           44         <strong>Last modification on </strong> <time>2025-05-03</time>
           45         </p>
           46 </header>
           47 
           48 <p>This was a christmas hack for fun and non-profit.
           49 I wanted to write a chess puzzle book generator.
           50 Inspired by <a href="https://archive.org/details/1001deadlycheckm0000nunn">1001 Deadly Checkmates by John Nunn, ISBN-13: 978-1906454258</a>,
           51 <a href="https://www.stappenmethode.nl/en/">Steps Method workbooks</a> and other puzzle books.</p>
           52 <h1>Example output</h1>
           53 <ul>
           54 <li>English version: <a href="https://codemadness.org/downloads/puzzles/">https://codemadness.org/downloads/puzzles/</a></li>
           55 <li>Dutch version: <a href="https://hiltjo.nl/puzzles/">https://hiltjo.nl/puzzles/</a></li>
           56 </ul>
           57 <p>Terminal version:</p>
           58 <pre><code>curl -s 'https://codemadness.org/downloads/puzzles/index.vt' | less -R
           59 </code></pre>
           60 <p>I may or may not periodially update this page :)</p>
           61 <p>Time flies (since Christmas), here is a valentine edition with <a href="https://lichess.org/practice/intermediate-tactics/attraction/">attraction</a>
           62 puzzles (not only checkmates) using the red "love" theme.
           63 It is optimized for his and her pleasure:</p>
           64 <p><a href="https://codemadness.org/downloads/puzzles-valentine/">https://codemadness.org/downloads/puzzles-valentine/</a></p>
           65 <h2>Clone</h2>
           66 <pre><code>git clone git://git.codemadness.org/chess-puzzles
           67 </code></pre>
           68 <h2>Browse</h2>
           69 <p>You can browse the source-code at:</p>
           70 <ul>
           71 <li><a href="https://git.codemadness.org/chess-puzzles/">https://git.codemadness.org/chess-puzzles/</a></li>
           72 <li><a href="gopher://codemadness.org/1/git/chess-puzzles">gopher://codemadness.org/1/git/chess-puzzles</a></li>
           73 </ul>
           74 <h1>Quick overview of how it works</h1>
           75 <p>The generate.sh shellscript generates the output and files for the puzzles.</p>
           76 <p>The puzzles used are from the lichess.org puzzle database:
           77 <a href="https://database.lichess.org/#puzzles">https://database.lichess.org/#puzzles</a></p>
           78 <p>This database is a big CSV file containing the initial board state in the
           79 Forsyth-Edwards Notation (FEN) format and the moves in Universal Chess
           80 Interface (UCI) format. Each line contains the board state and the initial and
           81 solution moves.</p>
           82 <p>The generated index page is a HTML page, it lists the puzzles.  Each puzzle on
           83 this page is an SVG image. This scalable image format looks good in all
           84 resolutions.</p>
           85 <h1>Open puzzle data</h1>
           86 <p>Lichess is an <a href="https://lichess.org/source">open-source</a> and gratis website to play on-line chess. There are
           87 no paid levels to unlock features.  All the software hosting Lichess is
           88 open-source and anyone can register and play chess on it for free. Most of the
           89 data about the games played is also open.</p>
           90 <p>However, the website depends on your donations or contributions. If you can,
           91 <a href="https://lichess.org/about">please do so</a>.</p>
           92 <h1>generate.sh</h1>
           93 <p>Reads puzzles from the database and shuffle them. Do some rough sorting and
           94 categorization based on difficulty and assign score points.</p>
           95 <p>The random shuffling is done using a hard-coded <a href="https://en.wikipedia.org/wiki/Random_seed">random seed</a>. This means on the
           96 same machine with the same puzzle database it will regenerate the same sequence
           97 of random puzzles in a deterministic manner.</p>
           98 <p>It outputs HTML, with support for CSS dark mode and does not require Javascript.
           99 It includes a plain-text listing of the solutions in PGN notation for the
          100 puzzles.
          101 It also outputs .vt files suitable for the terminal. It uses unicode symbols
          102 for the chess pieces and RGB color sequence for the board theme</p>
          103 <h1>fen.c</h1>
          104 <p>This is a program written in C to read and parse the board state in FEN format
          105 and read the UCI moves. It can output to various formats.</p>
          106 <p>See the man page for detailed usage information.</p>
          107 <p>fen.c supports the following output formats:</p>
          108 <ul>
          109 <li>ascii - very simple ASCII mode.</li>
          110 <li><a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation">fen</a> - output FEN of the board state (from FEN and optional played moves).</li>
          111 <li><a href="https://en.wikipedia.org/wiki/Portable_Game_Notation">pgn</a> - Portable Game Notation.</li>
          112 <li>speak - mode to output a description of the moves in words.</li>
          113 <li><a href="https://en.wikipedia.org/wiki/SVG">SVG</a> - Scalable Vector Graphics image.</li>
          114 <li>tty - Terminal output with some markup using escape codes.</li>
          115 </ul>
          116 <p>fen.c can also run in <a href="https://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI</a> mode. This can be used on a HTTP server:</p>
          117 <p><img src="https://codemadness.org/onlyfens?fen=6k1/ppq3bp/2n2np1/5p2/2P2P2/4rBN1/PP3K1P/RQ6%20w%20-%20-%200%2023&amp;moves=f2e3&amp;flip=1" alt="Position from game: Rene Letelier Martner - Robert James Fischer, 1960-10-24" /></p>
          118 <ul>
          119 <li><a href="https://codemadness.org/onlyfens">https://codemadness.org/onlyfens</a></li>
          120 <li><a href="https://codemadness.org/onlyfens?fen=6k1/ppq3bp/2n2np1/5p2/2P2P2/4rBN1/PP3K1P/RQ6%20w%20-%20-%200%2023&amp;moves=f2e3&amp;flip=1">https://codemadness.org/onlyfens?fen=6k1/ppq3bp/2n2np1/5p2/2P2P2/4rBN1/PP3K1P/RQ6%20w%20-%20-%200%2023&amp;moves=f2e3&amp;flip=1</a></li>
          121 <li><a href="https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;flip=1&amp;theme=green&amp;output=svg">https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;flip=1&amp;theme=green&amp;output=svg</a></li>
          122 <li><a href="https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=pgn">https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=pgn</a></li>
          123 <li><a href="https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=speak">https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=speak</a></li>
          124 <li><a href="https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=ascii">https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=ascii</a></li>
          125 <li><a href="https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=fen">https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=fen</a></li>
          126 </ul>
          127 <p>Terminal output:</p>
          128 <pre><code>curl -s 'https://codemadness.org/onlyfens?moves=e2e4%20e7e5&amp;output=tty'
          129 </code></pre>
          130 <h1>Support for Dutch notated PGN and output</h1>
          131 <p>For pgn and "speak mode" it has an option to output Dutch notated PGN or speech
          132 too.</p>
          133 <p>For example:</p>
          134 <ul>
          135 <li>Queen = Dame (Q -&gt; D), translated: lady.</li>
          136 <li>Rook = Toren (R -&gt; T), translated: tower.</li>
          137 <li>Bishop = Loper (B -&gt; L), translated: walker.</li>
          138 <li>Knight = Paard (N -&gt; P), translated: horse.</li>
          139 </ul>
          140 <h1>Example script to stream games from Lichess</h1>
          141 <p>There is an included example script that can stream Lichess games to the
          142 terminal. It uses the <a href="https://lichess.org/api">Lichess API</a>.  It will display the board using terminal
          143 escape codes. The games are automatically annotated with PGN notation and with
          144 text how a human would say the notation. This can also be piped to a speech
          145 synthesizer like <a href="https://github.com/espeak-ng/espeak-ng/">espeak</a> as audio.</p>
          146 <p>pgn-extract is a useful tool to convert Portable Game Notation (PGN) to
          147 Universal Chess Interface (UCI) moves (or do many other useful chess related
          148 things!).</p>
          149 <h1>Example script to generate an animated gif from PGN</h1>
          150 <p>Theres also an example script included that can generate an animated gif from
          151 PGN using <a href="https://ffmpeg.org/">ffmpeg</a>.</p>
          152 <p>It creates an optimal color palette from the input images and generates an
          153 optimized animated gif. The last move (typically some checkmate) is displayed
          154 slightly longer.</p>
          155 <h1>References and chess related links</h1>
          156 <ul>
          157 <li><p>chess-puzzles source-code:<br />  
          158 <a href="https://www.codemadness.org/git/chess-puzzles/file/README.html">https://www.codemadness.org/git/chess-puzzles/file/README.html</a></p>
          159 </li>
          160 <li><p>Lichess FEN puzzle database:<br />  
          161 <a href="https://database.lichess.org/#puzzles">https://database.lichess.org/#puzzles</a></p>
          162 </li>
          163 <li><p>lichess.org:<br />  
          164 <a href="https://lichess.org/">https://lichess.org/</a></p>
          165 </li>
          166 <li><p>SVG of the individual pieces used in fen.c:<br />  
          167 <a href="https://github.com/lichess-org/lila/tree/master/public/piece/cburnett">https://github.com/lichess-org/lila/tree/master/public/piece/cburnett</a></p>
          168 </li>
          169 <li><p>pgn-extract:<br />  
          170 A great multi-purpose PGN manipulation program with many options:<br />  
          171 <a href="https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/">https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/</a></p>
          172 <p>An example to convert PGN games to UCI moves:<br />  
          173 <code>pgn-extract --notags -Wuc</code></p>
          174 </li>
          175 <li><p>Lichess API:<br />  
          176 <a href="https://lichess.org/api">https://lichess.org/api</a></p>
          177 </li>
          178 <li><p>Stockfish:<br />  
          179 Strong open-source chess engine and analysis tool:<br />  
          180 <a href="https://stockfishchess.org/">https://stockfishchess.org/</a></p>
          181 </li>
          182 </ul>
          183 
          184                         </article>
          185                 </div>
          186         </main>
          187 </body>
          188 </html>