← Back to Docs
Recipe

Chess position analyzer

Build a local-first chess board that evaluates any FEN position using Stockfish compiled to WebAssembly.

Overview

This recipe walks through embedding a chess engine directly in the browser. You will render an interactive board, accept FEN strings, and display engine evaluations — all without a backend.

Ingredients

  • Stockfish 16 WASM build (single-threaded)
  • chessboard-element web component
  • Meridian FEN parser utility
  • Web Worker for engine communication

Steps

  1. Load the WASM engine. Instantiate Stockfish inside a dedicated Web Worker to keep the main thread responsive.
  2. Initialize the board. Mount chessboard-element with a default starting position and wire drag-and-drop move input.
  3. Parse FEN input. Accept a FEN string from a text field, validate it with the Meridian parser, and update the board.
  4. Send UCI commands. Post the position command to the worker and listen for the evaluation response.
  5. Display the eval. Render the centipawn score and principal variation below the board in real time.

Result

You now have a zero-latency chess analyzer that runs entirely client-side. Paste any FEN, move pieces freely, and get instant engine feedback — no server round-trips required.

Full source code and the Meridian FEN parser are available in the documentation repository.