Chess Widget Demo

Tactical Puzzles by ELO Rating

Choose Difficulty Level

Select your skill level to see appropriate puzzles. Try to solve each puzzle by finding the best move!

Back-Rank Mate

Lichess #jbwGi - Back-rank mate: Black plays Rb1, White must defend with Re1

Endgame Mate in 2

Lichess #RLHH3 - White plays Ra7, black must respond Rd1+, then Kc2 and Ne3#

Mate in 2

Lichess #diRlH - Black plays Kf8, White responds Ba3 to control c5

Rook Endgame Mate

Lichess #oqrBK - Black plays Kg5, White responds Rg4+ then Rh1#

Hook Mate

Lichess #BveME - White plays Rc5, Black responds Rd1+, then Kf2 and Rf1#

Fork Endgame

Lichess #sYcXL - White plays Rxf2, Black responds Qxf2+, then Kh2 and Qg2#

Mate in 2 Middlegame

Lichess #qGdZQ - White plays Kf4, Black responds Qh2+, then g3 and Qxg3#

Master Endgame

Lichess #nR6zG - Master vs Master: White plays Ke1, Black responds Qe3+, then Kd1 and Bb3#

Kingside Attack Mate in 3

Lichess #U5No7 - Attraction pattern: Black plays ...Rxf4, White Qxh8+, then Kf7, g6+, Kg6, and Qh5#

Complex Endgame Mate in 3

Lichess #rfaGy - White plays Bb4, Black responds Rxf2+, then Kg1, Rg2+, Kf1, and Rxf2#

Back-Rank Mate

Checkmate in 1

White to move and deliver checkmate. The black king is trapped by its own pawns on the back rank. Solution: Re8#

Fork Tactic

Knight Fork

Lichess #NOb2c (ELO 900) - Black plays ...Qxd4, White responds Ne6, then Kf6, and Nxd4

Pin Tactic

Pin Leading to Mate

Lichess #sTLMK (ELO 1260 Master Game) - Black plays ...Qxf6, White Re8+, then Kg7, and Nh5#

Discovered Attack

Discovered Attack Wins Material

Lichess #fOtTP (ELO 1050 Master Game) - White plays Nd4, Black responds ...Bxa2, then Nxa2, and ...Qxd6

Auto-Flip Board (Black to Move)

Board Flips with Turn

This board automatically rotates when it's black's turn. Try making moves to see the flip!

Free Play Mode

Standard Starting Position

No solution defined - free play mode. Make any legal moves you want!

Different Board Sizes

πŸ†• Alternative Solutions (Phase 1 Feature!)

Multiple Paths to Victory

This puzzle accepts multiple correct solutions! After Re1, both Qh5 and Qf3 lead to checkmate.

<div class="chess-puzzle"
     data-solution="f1e1,e5e4,d1h5|f1e1,e5e4,d1f3">
<!-- Use pipe | to separate alternative solutions -->
</div>

πŸ†• Stockfish Counter-Move with Arrows (Phase 3 Feature!)

AI-Powered Feedback with Visual Arrows

When you make a wrong move, Stockfish shows you why it's wrong by playing its best counter-move with a red arrow! Try making a wrong move to see it in action.

<div class="chess-puzzle"
     data-stockfish-enabled="true"
     data-stockfish-depth="10"
     data-stockfish-show-arrow="true">
<!-- Stockfish will show counter-moves with red arrows -->
</div>

πŸ†• Internationalization (Phase 1 Feature!)

Multi-Language Support

Widgets now support multiple languages! Try these puzzles in English and German.

English (default)

Deutsch (German)

<div class="chess-puzzle"
     data-lang="de"> <!-- German language -->
</div>

🎯 Phase 5: State Management & Wrong Move Retention

New Features Overview

The widget now includes external state management with event tracking and optional wrong move retention for deeper analysis!

πŸ“Š State Management & Event Tracking

Watch real-time events as you solve this puzzle. The console below shows all state changes and move attempts.

Lichess Puzzle #1400 ELO - Mate in 2, Middlegame Fork

Current State: not_started
// Events will appear here...

⏸️ Wrong Move Retention

Try making a wrong move! The position will be retained with a question mark indicator. Use the "Undo Wrong Move" button to continue.

Lichess Puzzle #1400 ELO - Mate in 2, Middlegame Fork

πŸ’‘ Tip: Notice the yellow arrow (your move) and red arrow (Stockfish counter-move) when you make a mistake!

πŸ’» API Usage Example

Here's how to subscribe to events programmatically:

// Get the widget state instance
const puzzle = document.getElementById('my-puzzle').widgetState;

// Subscribe to all state changes
puzzle.on('stateChange', ({ previous, current, metadata }) => {
  console.log(`State changed: ${previous} β†’ ${current}`);
});

// Subscribe to specific events
puzzle.on('wrongMove', ({ move }) => {
  console.warn(`Wrong move: ${move}`);
});

puzzle.on('puzzleSolved', () => {
  console.log('Congratulations! πŸŽ‰');
});

// Get current state
const currentState = puzzle.getState(); // 'not_started' | 'in_progress' | 'wrong_move' | 'solved'

// Get state history
const history = puzzle.getStateHistory();

How to Use

To add a chess widget to your website, simply include the CSS and JavaScript files, then add a div with the appropriate data attributes:

<!-- Include the widget files -->
<link rel="stylesheet" href="chess-widget.min.css">
<script src="chess-widget.min.js"></script>

<!-- Create a puzzle -->
<div class="chess-puzzle" 
     data-fen="r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3"
     data-solution="d2d4,e5d4,c2c3"
     data-width="400">
</div>

Data Attributes

The widget is completely standalone with all dependencies (chessground and chess.js) bundled - no CDN calls required!