Skip to content
Yasir Uslu
All work

Turkish backgammon in three modes

Tavla (Backgammon)

Turkish-style backgammon in the browser. Play the computer, two people on one device, or online with a room code and invite link; matches go to 1, 3, 5 or 7 points. It works in portrait and landscape and installs to the home screen.

Status
Live
Tools
Next.js 16 · React 19 · TypeScript · Supabase Realtime · Web Crypto · PWA · Vitest · Playwright
Tavla (Backgammon) screenshot

The problem

Coffeehouse tavla has its own rules: if both dice can be played both must be, if only one can the larger is played; a gammon (mars) scores two and there is no doubling cube. It needed one engine that applies these exactly and serves the bot and online rooms alike, plus fair dice.

My role

Sole developer: rules engine, bot, online rooms, UI, audio and tests.

Approach

  1. 01

    A pure rules engine

    Board, moves and match state are handled by pure functions; legal move sequences are generated under the “play both dice, otherwise the larger” rule. The UI, bot and online rooms share the same engine, and the rules are unit tested.

  2. 02

    Fair dice

    Dice come from Web Crypto with rejection sampling, so every face is equally likely. In online games only the host’s browser rolls.

  3. 03

    A bot that knows backgammon

    The bot scores every position reachable with the roll: pip difference, exposed checkers and the opponent’s chance to hit them (out of 36 dice combinations), made points, primes and hits. Once contact ends it only races.

  4. 04

    Online rooms without a game server

    The host is the single authority: it rolls, applies moves by rule and turn, and broadcasts state over Supabase Realtime. The guest only sends requests. Backgammon has no hidden information, so no encryption is needed; the invite link fills in the room code.

The hard part

Never apply a move twice

A guest move that doesn’t reach the host is resent until acknowledged. On a weak connection the old copy could arrive late and the move would be applied twice. Every request now carries an id; the host keeps the last 20 ids per player and never applies the same one again.

Quality

The rules engine and room rules are covered by Vitest; the bot game, invite links and same-device mode by Playwright on phone and desktop.