Skip to content

Installation

Run the following command to install the most recent version of draughts.js from NPM:

Terminal window
npm install draughts.js

Node.js 18 or newer.

import { Draughts } from 'draughts.js'

ECMAScript modules can be imported in a browser:

<script type="module">
import { Draughts } from 'draughts.js'
</script>
const { Draughts } = require('draughts.js')

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())