Installation
Run the following command to install the most recent version of draughts.js from NPM:
npm install draughts.jsNode.js 18 or newer.
Importing
Section titled “Importing”Import (as ESM)
Section titled “Import (as ESM)”import { Draughts } from 'draughts.js'ECMAScript modules can be imported in a browser:
<script type="module"> import { Draughts } from 'draughts.js'</script>Import (as CommonJS)
Section titled “Import (as CommonJS)”const { Draughts } = require('draughts.js')Example Code
Section titled “Example Code”The code below plays a random game of draughts:
import { Draughts } from 'draughts.js'
const game = new Draughts()
while (!game.isGameOver()) { const moves = game.moves() const move = moves[Math.floor(Math.random() * moves.length)] game.move(move)}
console.log(game.pdn())