UNPKG

cm-chessboard

Version:

A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.

85 lines (81 loc) 3.77 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>cm-chessboard</title> <link rel="stylesheet" href="assets/chessboard.css"/> <link rel="stylesheet" href="examples/styles/examples.css"/> <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/> </head> <body> <h1>cm-chessboard</h1> <p>A JavaScript chessboard which is</p> <ul> <li>lightweight and ES6 module based</li> <li>responsive and SVG rendered</li> <li><b>without dependencies</b> 🥳</li> <li>tested and it works</li> </ul> <p>cm-chessboard is the chessboard of <b><a href="https://www.chessmail.de">chessmail.de</a></b> and is used every day by <b>thousands of players</b>.</p> <p class="text-info">cm-chessboard is easy to use: <a href="https://github.com/shaack/cm-chessboard">Repository and documentation on GitHub</a></p> <div> <h2>Examples</h2> <ul> <li><a href="examples/extensions/right-click-annotator.html">Draw Arrows and Markers with right-click</a> 🆕🔥</li> <li><a href="examples/simple-boards.html">Simple chessboards, view only</a></li> <li><a href="examples/responsive-board.html">Responsive chessboard</a></li> <li><a href="examples/enable-input.html">Input enabled without validation</a></li> <li><a href="examples/validate-moves.html">Input enabled, with move validation and promotion dialog</a> 🔥</li> <li><a href="examples/pieces-animation.html">Set different positions, with animation</a></li> <li><a href="examples/different-styles.html">Different styles and piece sets</a> 🎨</li> <li><a href="examples/destroy-many-boards.html">Stress test, 5000 boards created and destroyed</a> 🤓 👍</li> </ul> <h3>Examples for the shipped cm-chessboard extensions</h3> <ul> <li> Draw arrows and markers on the board with <a href="examples/extensions/right-click-annotator.html">RightClickAnnotator extension</a> 🆕🔥 <ul> <li><a href="examples/extensions/markers-extension.html">Markers extension</a></li> <li><a href="examples/extensions/arrows-extension.html">Arrows extension</a></li> </ul> </li> <li>Draw HTML over the board with the <a href="examples/extensions/html-layer-extension.html">HTML Layer extension</a></li> <li>Allow displaying a promotion dialog with the <a href="examples/extensions/promotion-dialog-extension.html">PromotionDialog extension</a></li> <li>Make the board accessible, add screen-reader support with the <a href="examples/extensions/accessibility-extension.html">Accessibility extension</a></li> </ul> </div> <h2>Chessboard</h2> <div class="board" id="board"></div> <script type="module"> import {Chessboard} from "./src/Chessboard.js" import {FEN} from "./src/model/Position.js" import {Chess} from "https://cdn.jsdelivr.net/npm/chess.mjs@1/src/chess.mjs/Chess.js" const chess = new Chess() const board = new Chessboard(document.getElementById("board"), { position: FEN.start }) const interval = setInterval(() => { makeRandomMove() board.setPosition(chess.fen(), true) }, 500) function makeRandomMove() { if(chess.game_over()) { chess.reset() } const possibleMoves = chess.moves() if (possibleMoves.length === 0) { clearInterval(interval) return } const randomIndex = Math.floor(Math.random() * possibleMoves.length) chess.move(possibleMoves[randomIndex]) } </script> <div class="clearfix"></div> <h2>Tests</h2> <ul> <li><a href="test/">Run the unit tests</a></li> </ul> </body> </html>