Building a better Hearts game
Sometimes I zone out with a game of Hearts on my phone. It’s a good mix of simple rules and light strategy. The point is often just to fill time. I don’t enjoy watching ads or buying tokens to play, but those are pretty much the options. So I decided to build something better.
Playing against other people raised a second problem. An online card game normally has a dealer: a server that shuffles, knows every hand, and tells each player theirs. You trust it not to peek, not to stack the deck, and not to leak. For a casual game that’s fine. But there’s no way to check.
Mental poker
It turns out this is a solved problem, and an old one. Shamir, Rivest and Adleman named it mental poker: can people who don’t trust each other deal cards with no dealer, so that the shuffle is fair and each player sees only their own hand? The answer is yes, and the modern versions are practical enough to run on a phone.
Open Hearts uses Barnett–Smart with a Bayer–Groth shuffle argument, built on an existing open-source implementation. Roughly:
- Every seat holds a share of the table’s key. A card opens only with help from every seat.
- Each seat shuffles the whole deck in turn and publishes a proof that it really shuffled, without revealing the order.
- Each seat helps open the other seats’ cards for them, and only for them.
- After the last trick, every seat reveals its secret, and the whole hand can be replayed and checked by anyone.
What it guarantees, and what it doesn’t
The deal can’t be rigged: one honest shuffler at the table is enough. Nobody can play a card they weren’t dealt. Every game can be verified end to end after the fact.
Nobody can see your cards either, with one caveat. When a seat is a bot, someone has to hold its hand without the players seeing it. That job goes to jurors: other players online, drawn at random. One plays the bot’s seat and sees only that hand; the others each hold a piece of it, in case that one drops. When too few people are online, our own backup jurors fill in, and for those hands you are trusting us not to collude with someone at your table. The code is open source, so you can read exactly what they do.
Cryptography doesn’t help with players sharing hands over a phone call, or using a solver. Those are out of scope, but pairing is random and Hearts involves enough luck that they aren’t highly practical.
Challenges
Mental poker can be challenging in circumstances like proving that you don’t have a card. For example, in Hearts the player holding the 2♣ leads first. What if they just say they don’t have it? There’s no proof you can demand for a card someone claims not to hold. Everyone says “not me,” and nobody can lead.
The answer is to open that hand on the spot. Nothing is scored, the hand is re-dealt, and the opened cards show exactly who was holding the 2♣, so that seat is removed. A majority can’t use this to throw away a hand they don’t like, because only the seat that lied could have caused it.
The cryptography isn’t free: a shuffle and its proof take about a tenth of a second natively, and a few times that in a browser. Across a four-person hand that’s under a second of work per seat, two or three times that on a phone. Playing a card is cheap. The heavy work runs off the page’s main thread, so the game doesn’t stutter while it happens.
Try it
Solo play against the bots is free, works offline, and has no ads. Live tables with other people are a paid subscription. The source is on GitHub, including a write-up of the fair deal with what’s guaranteed in more detail than here.
There are other card games using mental poker, like SecureSkat. Let me know if you find (or wrote) any others and I’ll include them here. Also, please play and share feedback, especially if you find bugs or a way to cheat.