· 3 min read
I coded my friends' card game so we could keep playing from far away
Nine to One exists nowhere. No app, no rules online, just a game we played among friends. When we ended up scattered between France, New Caledonia and Australia, I built it.
- AI
- Game
There is a card game I play a lot with my friends. It is called Nine to One, nobody knows it, and it exists on no phone. For years it was evenings around a table. Then everyone went their own way: some to France, others to New Caledonia, me to Australia.
So I did what I know how to do. I coded it. At first, Le Spot was only that: a Nine to One table on the phone, so we could meet up like before. Today there are six games on it, and my friends spend time there. It is the project I enjoyed the most, and that is no coincidence.
A multiplayer card game is a trust problem
As soon as there are hidden cards, the question is: who decides what is true? Not the player's phone. The phone only sends intentions, "I play this card", "I pass", and the server answers with what that player is allowed to see, nothing more. The server is the sole judge. It is the same logic as business software: what matters is checked at the centre, not on the user's side.
And because real life gets in the way, the game handles absent players. Someone who stops responding has their move played for them, and after three missed turns a bot takes their seat so the game goes on for everyone else.
Marcel, Odette and Ginette
The bots carry grandparents' first names, followed by "bot". Marcel bot, Odette bot, Ginette bot. We don't hide that they are machines, but we give them a face and a rhythm.
Rhythm matters more than I thought. A bot that plays instantly breaks the game. Ours wait between one and two seconds before each move, and a little longer, two and a half seconds, in situations where a human could still react. Not to fool anyone, but so the table breathes.
A bot trained to play, without cheating
The strongest bot learned by playing against itself, hours of games, with a reinforcement learning method. During training it had access to everything. In play, it only sees its hand and what happened on the table, like any other player, and reasons about the cards it does not know by reshuffling them at random in its head.
The fun constraint is the server. Everything runs on a small machine rented by the month, which also hosts other projects. No way I was installing a machine learning library weighing several hundred megabytes on it. So the bot's brain was rewritten as a handful of matrix operations, its weights fit in a little over two megabytes, and the whole game server, bots included, uses about 75 MB of memory.
What this project taught me
That a phone is a hostile environment. The app has to be installed like a real app, the in-app browsers of Instagram or Snapchat break it, and iPhone has its own ideas about what a flipped card should do.
And that a project made for specific people, with a specific use, moves forward better than any project "for everyone". I knew exactly who was going to play, on which phone, and at what time.
That is also how I like to build for my clients.