PHPackages                             photogabble/draughts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. photogabble/draughts

ActiveLibrary

photogabble/draughts
====================

PHP port of shubhendusaurabh/draughts.js

11011[5 issues](https://github.com/photogabble/draughts/issues)[1 PRs](https://github.com/photogabble/draughts/pulls)PHP

Since Nov 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/photogabble/draughts)[ Packagist](https://packagist.org/packages/photogabble/draughts)[ RSS](/packages/photogabble-draughts/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Draughts
========

[](#draughts)

*A PHP port of [draughts.js](https://github.com/shubhendusaurabh/draughts.js)*

 [![Build Status](https://camo.githubusercontent.com/e00c32db18cb3824d38b662017850e72ef50b1b7ad513a54fb5cacdfc0968e98/68747470733a2f2f7472617669732d63692e6f72672f70686f746f676162626c652f64726175676874732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/photogabble/draughts) [![License](https://camo.githubusercontent.com/503a2c6da8380d0d62b100379df2058a5fbc4745535ee75f892017e66ed3bc72/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686f746f676162626c652f7068702d636f6e66757361626c652d686f6d6f676c797068732e737667)](LICENSE) [![Gitmoji](https://camo.githubusercontent.com/f07121352802f2c4d8e5b866c3b9bfac9814b125d6df7985e721d285b458b4af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769746d6f6a692d253230f09f989c253230f09f988d2d4646444436372e737667)](https://gitmoji.carloscuesta.me/)

About this package
------------------

[](#about-this-package)

A PHP checkers library for move generation/validation, piece placement/movement and draw detection. Useful for writing the server side implementation of a multi-player checkers game. It has been ported from a JavaScript implementation by [@shubhendusaurabh](https://github.com/shubhendusaurabh). You can see a list of the contributors to this project [here](CONTRIBUTORS.md).

Install
-------

[](#install)

Install using composer: `composer require photogabble/draughts`

Example Usage
-------------

[](#example-usage)

The code below will play a complete game of draughts, outputting the result of each move with each move being picked randomly:

```
$draughts = new Draughts();
echo $draughts->ascii();
while (!$draughts->gameOver())
{
    $moves = $draughts->generateMoves();
    $move = $moves[array_rand($moves, 1)];
    $draughts->move($move);
    echo $draughts->ascii();
}
```

### PDN Viewer

[](#pdn-viewer)

During my time developing this port I have found this [PDN Viewer](http://svg_experimenten.deds.nl/draughtboard2/pdn_viewer_a.html) to be invaluable at helping me understand the PDN structure and as a visual debugger of the PDN that this library generates.

Public API
----------

[](#public-api)

### Constructor

[](#constructor)

The `Draughts` class `__construct` method takes an optional `string` parameter that defines the initial board configuration in [Forsyth-Edwards Notation](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation).

```
// Board defaults to the starting position when call with no parameter
$draughts = new Draughts;

// Pass in a FEN string to load a particular position
$draughts = new Draughts('W:W31-50:B1-20');
```

### ascii(bool $unicode = false): string

[](#asciibool-unicode--false-string)

Returns a string containing an ASCII diagram of the current position.

### reset(): void

[](#reset-void)

Reset the board to the initial starting position.

### generateFen(): string

[](#generatefen-string)

Returns the [Forsyth-Edwards Notation](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation) (FEN) string for the current position.

### gameOver(): bool

[](#gameover-bool)

Returns `true` if the game has ended via no moves left, or no pieces rule. Otherwise, returns `false`.

### inDraw(): bool

[](#indraw-bool)

Under development, see issue [\#4](https://github.com/photogabble/draughts/issues/4)

### inThreefoldRepetition()

[](#inthreefoldrepetition)

Under development, see issue [\#5](https://github.com/photogabble/draughts/issues/5)

### move(Move $move): ?Move

[](#movemove-move-move)

Attempts to make a move on the board, returning a `Move` object if the move was legal, otherwise `null`.

### generateMoves(int $square = null): array

[](#generatemovesint-square--null-array)

Returns a list of legals moves from the current position. The function takes an optional parameter which controls the single-square move generation.

### turn(): string

[](#turn-string)

Returns the current side to move.

### undo(): ?Move

[](#undo-move)

Takeback the last half-move, returning a `Move` object if successful, otherwise `null`.

### get($square): string

[](#getsquare-string)

Returns the piece on the square.

### remove(int $square): string

[](#removeint-square-string)

Removes the piece on the square.

### put(string $piece, int $square): bool

[](#putstring-piece-int-square-bool)

Puts the piece on the square and returns `true` if valid placement. Otherwise, returns `false`.

### getHistory(bool $verbose = false): array

[](#gethistorybool-verbose--false-array)

Returns a list containing the moves of the current game.

### setHeader(array $values = \[\]): array

[](#setheaderarray-values---array)

Update the header properties.

### loadPDN(string $pdn, array $options = \[\])

[](#loadpdnstring-pdn-array-options--)

Load the moves of a game stored in [Portable Draughts Notation](https://en.wikipedia.org/wiki/Portable_Draughts_Notation). Options is a optional parameter that contains a 'newline\_char' which is a string representation of a RegExp (and should not be pre-escaped) and defaults to '\\r?\\n'). Returns `true` if the pdn was parsed successfully, otherwise `false`.

Not invented here
-----------------

[](#not-invented-here)

This started as a PHP port of [shubhendusaurabh/draughts.js](https://github.com/shubhendusaurabh/draughts.js).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 95.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/32e6199648ca613ea8451f73c0b13977c35f98cfc0f369316ba7e10eb9c5e9c8?d=identicon)[carbontwelve](/maintainers/carbontwelve)

---

Top Contributors

[![carbontwelve](https://avatars.githubusercontent.com/u/464699?v=4)](https://github.com/carbontwelve "carbontwelve (62 commits)")[![ins0](https://avatars.githubusercontent.com/u/2622534?v=4)](https://github.com/ins0 "ins0 (3 commits)")

---

Tags

portwip

### Embed Badge

![Health badge](/badges/photogabble-draughts/health.svg)

```
[![Health](https://phpackages.com/badges/photogabble-draughts/health.svg)](https://phpackages.com/packages/photogabble-draughts)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
