← All writing

Three Tunisian card games, one engine

After Chkobba, I wanted Rami and Belote online too. Instead of writing the online part twice more, I took it out of Chkobba and gave each new game only its own rules.

·3 min read
Rami and Belote side by side on green felt: a Rami hand of fifteen cards with a bot's melds on the table, and a Belote trick in the middle of four players.

My Chkobba was already online. Most of its code isn’t the card rules at all; it’s everything around them: rooms, seats, players who drop and come back, bots that take over, the host leaving halfway through.

None of that is about Chkobba. So when I wanted Rami and Belote too, I didn’t write it twice more.

Taking the engine out

Chkobba’s referee was split in two. The game-specific half stayed with the game; the generic half became a small shared engine:

  • seats and seat tokens, so a reload puts you back in your seat with your hand
  • a 60-second seat hold when someone drops (the same idea as in my other online games); after that, the others can let a bot play the seat or claim the win, and the player still gets it back
  • host hand-over when the host leaves
  • bot timing, the turn timer, private snapshots, and saving and restoring a room

A game plugs into it with one object: how to start a game, whose turn it is, each move and how it’s checked, how a bot plays, and what each seat is allowed to see. The rules and the bots stay with the game. Chkobba itself wasn’t changed.

Online, each room is one Cloudflare Durable Object, and it is the referee: it shuffles, deals, checks every move and keeps score. Each browser only ever receives its own hand. For a game against bots, the same referee code runs inside the page, so the offline game and the online game can’t drift apart.

Rami, where every rule is a setting

Rami follows the Tunisian rules by default: two decks and four jokers (108 cards), 14 cards each, and an opening (the nzoul) of 71 points or more, including a clean run with no joker. Lay your whole hand at once and it’s a rami sec: the others pay double. The player whose throw you took to go out pays 50 more: the zl3a.

But no two tables play Rami quite the same way. So every rule is a house rule: open with 90 instead of 71, ask for two clean runs, play with no jokers, allow K-A-2, change the card values. That’s 42 settings, each with a one-line explanation, plus ready-made presets and your own.

The House rules screen: the opening set to 90 points with one clean run of 3 or more, a custom preset next to the ready-made ones, and a short explanation under every setting.

Online, the host’s rules go to the room. The server checks every value again, clamps anything out of range, and locks the rules once a game starts, so nobody can change them in the middle of a hand.

Bots that follow any rules

Rules you can bend are only fun if the bots bend with them. The bots check their melds with the same rules code as the referee, so they play correctly whatever is set.

To make sure, a test plays whole games under random mixes of rules and fails on any refused move: 120 games, 3,314 rounds, no illegal bot move. And the levels mean something: the hard bot beats the easy one in 89% of games.

Belote, from thin sources

Belote is the card game of Tunisian cafés. This version plays contrée by default: bids from 90 to 160 or capot, contré ×2, surcontré ×4. The classic game with the turned card is an option.

The hard part was the rules. There is no Tunisian federation and no written national rulebook. So the game starts from the French federation’s rules, and takes its Tunisian values from the clearest Tunisian source I found: the written rules of an online Belote made for a café in Oudhref, near Gabès, where the players there agreed each rule. Where that source is silent, the French base fills in, and the main differences are options. One article claimed Tunisian Belote uses 40 cards; no other source said so, so the game doesn’t follow it.

Every café plays a little differently. If yours does, change the setting.

The Belote bots look ahead: the hard one deals out the cards it can’t see many times, using only what a player at the table could know, and plays each deal to the end. It beats the easy bot in 93% of matches.

Play them

In all three you can play bots right in the page, or share a link and play friends online. No account needed.