Skip to content

About

A desktop chess opening trainer and analysis board for Linux.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

94 Commits

Folders and files

Repository files navigation

SharpBlunder

A desktop chess opening trainer and analysis board for Linux, written in C++23 with SFML 3 and Dear ImGui. The rules of chess come from Stockfish, which runs as a child process.

Status: work in progress. The analysis board works. The other pages are placeholders.

Features

Working today:

  • Analysis board with the Lichess cburnett pieces
  • Move pieces by drag and drop or by clicking the piece and then the target square
  • Legal moves, check, checkmate and stalemate come from Stockfish
  • Draws by the FIDE laws, worked out by the program: insufficient material, fivefold repetition and the 75-move rule are shown as the end of the game ("Draw - insufficient material"). Threefold repetition and the 50-move rule are shown as a hint that a player can claim the draw. The game can still be played on
  • Highlights for the last move, the king in check and the target squares of the selected piece
  • Pawn promotion with a choice of the new piece
  • Move list in Standard Algebraic Notation (Nbd7, exd6, O-O-O, Rd8#), click a move to jump to it
  • Variations like on lichess: take a move back and play another one, and the game keeps both. The main line is a table, variations are written below the move they belong to (nested ones in parentheses). A right click on a move makes its line the main line or deletes it
  • Comments, as in PGN: on single moves (a speech bubble next to the move, shown when the mouse rests on it or after a click), on a variation (in its header) and on the whole game. A check box shows all of them at once
  • Games are read and written as PGN, with variations, comments, the lichess clock and evaluation commands ([%clk ...], [%eval ...] are kept as they are) and the glyphs ($1, !, ?). The PGN button copies the game to the clipboard, pastes a game from it, and saves or opens a file. Files go to ~/SharpBlunder/games by default
  • FEN: copy the FEN of the position on the board, and start a game from a FEN. A FEN that cannot be played (no king, a pawn on the last rank, the side that is not to move in check) is refused with the reason
  • Details of the game as in chess.com (a pencil above the move list): names and ratings of White and Black, result, event, place, round, date, time control and how the game ended. They are PGN tags and are saved with the game. The date and the time are typed the way people write them and are saved the way the PGN standard wants them: 24.11.2026 becomes 2026.11.24, and a time control like 15+10 (15 minutes, 10 seconds per move) becomes 900+10 (seconds). Without a unit the first number is minutes and the second is seconds, 90 s and 1h 30min work too, and a list offers the usual controls (Bullet, Blitz, Rapid, Classical)
  • The players are shown above and below the board with a picture, name, rating and the pieces they have captured
  • Step through the game, flip the board (the labels a-h and 1-8 outside the board turn with it), start a new game
  • Live analysis with a second Stockfish process: evaluation bar next to the board and an arrow for the best move. The three best moves are listed as rows: a colored dot (how much weaker than the best move), the score and the move with the icon of the piece. A click on a row plays the move, a magnifying glass opens the whole line. One line says in words who is better ("Equal", "White is slightly better", ...). A check box switches the analysis off
  • Name and ECO code of the opening (for example B90 Sicilian Defense: Najdorf Variation), found by position, so transpositions work too. After the game leaves the book, the last known name stays. The opening is also written to the PGN tags ECO, Opening, Variation and SubVariation
  • The settings page (Einstellungen) changes the language at once and says whether the engine starts switched on. The settings are kept in ~/SharpBlunder/settings.json, which can be edited by hand, too. A file that is broken is kept as settings.json.bak and the defaults are used
  • English and German. The language is chosen on the settings page (auto follows the system). The chess notation is not translated: moves stay Nc6 and PGN files always use English tags and values, so they work everywhere. Terms such as Remis, Matt and Patt are used in German
  • The page My Games (Meine Partien) fetches your games from chess.com with its public API and lists them: result, the color you played, opponent, time control, accuracy (as reported by chess.com, if the game was analyzed there), number of moves, date and opening. Tabs filter by Bullet, Blitz, Rapid and Daily, a search field looks for opponent or opening. The button Analyze opens the game on the analysis page, with your side at the bottom, and a button leads back to the list. See chess.com below
  • The analysis of a game from the list has its own page (Partieanalyse), separate from the analysis board. The engine looks at every position of the game, in the background with a progress bar, and the page shows how many inaccuracies (?!), mistakes (?) and blunders (??) each side made and the average loss in centipawns. The marks are written behind the moves in the list, the evaluation bar shows what the engine said about each position, and two buttons jump to the next or the previous mistake. A tutor box writes a short comment on the move on the board, for example "Mistake: 2.d4 loses about 13% of the winning chances. Better was 2.exd5." (fixed templates that only use what the engine has found; no language model yet). "Try the better move" plays the move of the engine as a variation, and "Continue on board" takes the position to the analysis board. See Analysis below
  • The analysis board has no tutor and no marks: it is for free analysis, openings and games that you paste
  • The search depth is set on the settings page: for the live analysis (the engine stops there, 0 means no limit) and for the analysis of a game
  • Sidebar navigation between the pages

Planned, not implemented yet:

  • Import and analysis of your games from lichess.org
  • Training of your own opening repertoire with spaced repetition
  • Synchronization of the learning data with a server, and an Android app that uses it

Requirements

  • Linux (the engine is started with fork and pipe2; Windows and macOS are not supported)
  • A C++23 compiler with std::ranges::to and std::views::join_with: GCC 14 or newer
  • CMake 3.22 or newer
  • SFML 3.x (Graphics, Window, System)
  • OpenGL
  • libcurl with TLS support (for the connection to chess.com)
  • Stockfish
  • An internet connection for the first CMake run, which downloads Dear ImGui 1.91.8, ImGui-SFML 3.0 and nlohmann/json 3.11.3

Building

Arch Linux / CachyOS

sudo pacman -S --needed base-devel cmake git sfml stockfish curl

The sfml package must be version 3.x. Check it with pacman -Qi sfml.

Debian / Ubuntu

The SFML packages of Debian and Ubuntu are version 2.x (Ubuntu 24.04 has 2.6.1), but SharpBlunder needs SFML 3. Build SFML 3 from source:

sudo apt install build-essential cmake git g++-14 stockfish libcurl4-openssl-dev \
    libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev libfreetype-dev

git clone --branch 3.0.0 --depth 1 https://github.com/SFML/SFML.git
cmake -S SFML -B SFML/build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON \
    -DSFML_BUILD_AUDIO=OFF -DSFML_BUILD_NETWORK=OFF -DSFML_BUILD_EXAMPLES=OFF -DSFML_BUILD_DOC=OFF
cmake --build SFML/build -j
sudo cmake --install SFML/build
sudo ldconfig

SharpBlunder

git clone https://github.com/stwe/SharpBlunder.git
cd SharpBlunder
cmake -B build -DCMAKE_BUILD_TYPE=Release          # on Ubuntu add: -DCMAKE_CXX_COMPILER=g++-14
cmake --build build -j

Running

./build/SharpBlunder [path/to/stockfish]

The Stockfish executable is taken from the first argument. Without an argument, the environment variable STOCKFISH is used, and without that the name stockfish is looked up in the PATH. If that fails, the program also tries /usr/games/stockfish, where the Debian/Ubuntu package installs it.

The program finds its images and fonts in the assets directory of the source tree. CMake stores the absolute path of that directory in the executable, so run CMake again if you move the source directory.

Controls

Input Action
Drag a piece, or click piece, target Move
Right click Cancel the selection
Left / Right One move back / forward
Home / End Go to the start / end of the game
F Flip the board
Esc Quit
Click on a move in the list Jump to that position

Project layout

assets/        piece images (pieces/cburnett), GUI font (fonts), opening names (openings), translations (i18n),
               each with its license
src/core/      chess model without any graphics: Position, Move, Piece, SAN notation, GameState, RulesProvider,
               Score, OpeningBook, DrawRules, TimeControl, PgnTags, Settings, I18n, GameSummary, ChessComParser, GameList,
               and for the analysis of a game: Assessment (judges the moves), GameAnalysis (the saved file),
               AnalysisJob (the main line of a game and the run over it), PositionEvaluator (interface), TutorText
src/engine/    Stockfish as a child process (Engine), the rules from Stockfish (StockfishRules), the live
               analysis (Analyzer), the parser for its UCI lines, StockfishEvaluator (one position after the other for
               the analysis of a game) and AnalysisWorker (runs it in a thread)
src/net/       the connection to web servers: HttpClient (interface), CurlHttpClient (libcurl), ChessComClient (the
               games of a user, with a cache), GamesSyncer (does the work in a thread)
src/ui/        window, Dear ImGui layer, navigation, board view, evaluation bar, mouse input, pages (screens/).
               GameBoard is what the pages with a game on a board have in common (board, engine, list of moves).
               The analysis board and the analysis of a game (GameAnalysisScreen) each have a side panel of their own
tests/         test programs, run them with ctest in the build directory
tools/         render_pieces.sh turns the SVG pieces into the PNG files the program loads,
               update_openings.sh builds assets/openings/openings.tsv again from the Lichess data,
               update_translations.sh collects the texts of the program and updates the .po files

core does not depend on anything else (the parser of chess.com uses nlohmann/json). The rest of the program only knows the RulesProvider interface, so the source of the rules (today Stockfish) can be replaced.

chess.com

The page My Games uses the published-data API of chess.com. It needs no account and no token, and only the documented endpoints are used: the list of archives of a user and the games of a month.

  • The requests are made one after the other, never in parallel, and every request has a User-Agent that names the program and this repository. When chess.com says that there are too many requests, the program waits and tries again a few times.
  • The answers are kept in ~/SharpBlunder/chesscom/<user>/. A month that is over is fetched only once. The latest months are asked for again with the ETag of the last answer, so nothing is downloaded when nothing has changed. Without a network the saved games are shown. You can delete the folder at any time.
  • The first fetch gets the latest three months. The button "Load older games" adds six more months each time.
  • Games of variants (for example Chess960) cannot be shown and are skipped. The page says how many.
  • The user name is set on the settings page. It is only the default of the text field on My Games: another name can be typed there for one session.
  • The accuracy numbers are the ones that chess.com has calculated, and they are shown as such. They exist only for games that were analyzed on chess.com.

SharpBlunder is not affiliated with or endorsed by chess.com. It uses neither its name as a feature name nor its logos, pieces, avatars or other design.

Analysis

How the moves of a game are judged:

  • The engine (Stockfish, in a process of its own) evaluates every position of the main line to the depth from the settings. The score of a position is how good it is when both sides play their best.
  • A move costs what the score loses between the position before and the position after it, from the point of view of the side that moved. It is measured as the part of the chance to win that is lost, not in centipawns: the same loss counts for more in an equal position than in a position that is decided anyway. The chance to win is worked out with the formula that lichess.org publishes on its page about accuracy: win % = 50 + 50 * (2 / (1 + exp(-0.00368208 * centipawns)) - 1).
  • A loss of 5, 10 or 15 percentage points is an inaccuracy, a mistake or a blunder. These limits are the ones that lichess.org is said to use on its scale from -1 to +1 (0.1, 0.2, 0.3). They come from posts of its users, not from a document. The code of SharpBlunder is its own: nothing was taken from the source code of lichess.org.
  • The average loss in centipawns uses scores and losses that are cut at 1000, so that one move into a mate does not spoil the number. The numbers will not be the same as on other sites: the engine, its version and the depth are different.
  • An analysis is kept in ~/SharpBlunder/analysis/<source>/<id>.json with the engine, the depth, the moves and the evaluations. It is checked when it is read, and it is used again only if it is for the same game and at least as deep as the setting. You can delete the folder at any time.

Translations

Every text that the user sees is written in English in the source code, as tr("Save"). The translations are assets/i18n/<code>.po files in the format of GNU gettext (the program reads them itself and does not use the gettext library, so the language can be changed while it runs). To translate or to add a language:

  1. tools/update_translations.sh collects the texts into assets/i18n/sharpblunder.pot and updates every .po file (needs GNU gettext)
  2. A new language: msginit --no-translator -i assets/i18n/sharpblunder.pot -l <code> -o assets/i18n/<code>.po, and set the header X-Native-Name to the name of the language in that language
  3. Translate the entries with an editor such as Poedit. Entries that are marked fuzzy or are empty are not used

Not translated on purpose: chess notation (Nc6), PGN tags and values, and the names of openings. A text with values uses places like {} or {0}, as in tr_format("Depth {}", depth); a translation may change their order.

Code style

The formatting is defined in .clang-format, the naming rules are in .clang-tidy. In short:

  • Types and methods in CamelCase, global functions in lower_case, functions in anonymous namespaces in CamelCase
  • Enum constants and constants in UPPER_CASE, namespaces in lower_case
  • Parameters start with t_, members with m_
  • Every class, method and function has a Doxygen comment

License

SharpBlunder is free software under the GNU General Public License, version 3 or (at your option) any later version. See LICENSE.md.

It uses these third-party works, which keep their own licenses:

Work License Where
Piece set cburnett by Colin M. L. Burnett (via Lichess) GPL 2 or later assets/pieces/cburnett
Font Roboto Medium by Christian Robertson Apache License 2.0 assets/fonts
Opening names by Lichess CC0 assets/openings
SFML zlib/libpng linked, installed on your system
Dear ImGui MIT downloaded by CMake
ImGui-SFML MIT downloaded by CMake
nlohmann/json MIT downloaded by CMake
libcurl curl (MIT-like) linked, installed on your system
Stockfish GPL 3 separate program, not included

About

A desktop chess opening trainer and analysis board for Linux.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages