What's included
Features
About this UI Snippet
Checkers Game — Forced Captures, Multi-Jump Chains & King Promotion in Vanilla JS

Checkers (draughts) is a two-player board game played on the dark squares of an 8x8 grid, where pieces move diagonally, capture by jumping over an opposing piece into an empty square beyond it, and are promoted to kings on reaching the far row. This snippet implements the full rule set — not a simplified mockup — including the rule that captures are mandatory whenever one is available, and that a single turn can chain several jumps together if each landing square opens up another capture.
Board representation and movement
The board is a plain 8x8 array, board[r][c], holding either null or a piece object { color, king }. movesFor(r, c) computes both the simple diagonal moves and the jump captures available to the piece at that square by checking dirsFor(piece) — two forward diagonals for a regular piece (up for red, down for black) or all four diagonals once a piece is king. A capture requires an opposing piece immediately adjacent diagonally with an empty square directly beyond it in the same direction.
Forced captures — the rule most checkers implementations skip
anyCaptureAvailable(color) scans every piece of the moving color before each turn. If any piece on the board has a legal capture, mustCapture is set and clicking a piece without one shows an inline message telling the player a capture is available elsewhere and must be taken instead. This mandatory-capture rule is one of the most commonly-missed parts of checkers in casual implementations, and is central to real strategic play — it is why players can deliberately "sacrifice" a piece to force a worse trade for the opponent.
Multi-jump chains
After a capture lands, performMove() immediately calls movesFor() again from the new square. If further captures are available from that same piece, the turn does not pass — selected stays on the same piece, legalMoves is replaced with only the follow-up captures, and the player must continue jumping with that piece before the turn ends. This correctly implements the standard checkers rule that a capturing move must be completed as far as it will go in one turn.
King promotion
When a regular piece's landing row is the opponent's back row (row 0 for red, row 7 for black), piece.king = true promotes it in place, rendering a star glyph over the piece via the .king::after CSS pseudo-element and unlocking backward diagonal movement through dirsFor().
Win detection
The game ends the moment either color's piece count reaches zero, or the side to move has no legal moves at all (hasAnyMove) — both a real, complete win condition, not just a piece-count check, since checkers can also be won by immobilizing the opponent even with pieces still on the board.
Click-to-select interaction
Like other click-based board games in this library, moves are made by clicking a piece (highlighting its legal destinations, with capture destinations tinted differently from quiet moves) and then clicking a highlighted destination square — fully usable on touch devices without drag-and-drop.
Build with AI
Build, Understand, Optimize, and Extend It With AI
Paste this snippet's HTML, CSS, and JS into an AI coding assistant like Claude and ask it to explain exactly how mustCapture is recomputed before every render and why that single flag is enough to enforce the mandatory-capture rule across the whole board, plus how the multi-jump chain avoids passing the turn while follow-up captures remain. It's also a strong candidate for extension — ask the assistant to add a simple greedy-capture AI opponent using the existing movesFor() function, add move highlighting that also shows which of the opponent's pieces are currently vulnerable, or add an undo button that replays the move history from scratch.
Prompt to recreate it
Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:
Build a full 8x8 Checkers (draughts) game in plain HTML, CSS, and JavaScript — no libraries, click-to-select interaction only.
Requirements:
- Model the board as a plain 2D array, with pieces placed on the dark squares of the first three rows for one color and the last three rows for the other, red moving toward row 0 and black moving toward row 7 by default.
- Compute legal simple diagonal moves and legal jump captures separately for whichever piece is clicked, based on the piece's color and whether it has been promoted to a king (kings may move and capture in all four diagonal directions; regular pieces only in their forward two).
- Enforce mandatory captures: before allowing a piece to be selected for a quiet move, check whether ANY piece belonging to the current player has an available capture anywhere on the board, and if so, block quiet moves and require a capturing piece to be selected instead, with a clear inline message explaining why.
- Implement multi-jump chains: after a capture lands, check whether that same piece has a further capture available from its new square, and if so, keep it selected and require the chain to continue before the turn passes to the other player.
- Promote a regular piece to a king the instant it reaches the opponent's back row, after which it can move and capture backward as well as forward, with a distinct visual marker (e.g. a star) on kinged pieces.
- Detect the win condition when either color has zero pieces remaining, or when the player to move has no legal moves at all even with pieces still on the board.
- Visually highlight the selected piece and its legal destination squares, distinguishing capturing-jump destinations from quiet-move destinations.
- Include a live piece-count display for both colors and a "New Game" button that resets the full board state.Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.
Step by step
How to Use
- 1Click a piece to select itLegal destination squares light up — a red-tinted dot marks a capturing jump, an indigo dot marks a quiet move.
- 2Click a highlighted square to moveIf the move is a capture, the jumped piece is removed from the board immediately.
- 3Watch for forced capturesIf any piece of your color can capture, you must select and play a capturing piece — the game blocks quiet moves in that situation.
- 4Chain multiple jumpsLanding a capture that opens another capture from the same piece keeps that piece selected so you can continue the chain in one turn.
- 5Reach the far row to king a pieceA regular piece reaching the opponent's back row is promoted to a king (marked with a star) and can then move and capture backward too.
- 6Start a new gameClick "New Game" to reset both the board and the piece counts to the starting position.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
Yes. Before rendering each turn, anyCaptureAvailable(color) checks whether any piece of the moving color has a legal jump. If one exists, selecting a piece without a capture available shows a warning and does not allow a quiet move — matching standard checkers rules.
After a capture completes, performMove() checks the landing square for further captures with the same piece. If one exists, the turn does not pass — the same piece stays selected and only its follow-up captures are highlighted, so the player must continue the chain before the turn ends.
A regular piece is promoted the instant it lands on the opponent's back row — row 0 for red, row 7 for black. Once king: true, dirsFor() returns all four diagonal directions instead of only the two forward ones, so kings can move and capture backward.
Either a color's piece count reaches zero (all captured), or the side to move has no legal moves at all — checked by hasAnyMove() — even if pieces remain on the board.
Yes — movesFor() and anyCaptureAvailable() already expose everything a minimax or greedy-capture AI needs. A simple bot could call movesFor() across every AI-colored piece, prefer any available capture (especially multi-jump chains), and otherwise pick a random simple move.
Click-to-select works identically on mouse and touch without the added complexity of tracking drag offsets over a diagonal grid, while still feeling direct: click a piece, then click one of its highlighted legal destinations.