Retrucada

A neural network that learned truco from scratch in 36 minutes

Retrucada is 1-on-1 truco, the Brazilian card game of bluffing and raising the stakes, played in a corner bar. It has three robots, easy, medium and hard, and I wrote the rules for each by hand. I wanted to know if I could make a fourth one that nobody taught: a neural network that starts knowing nothing about truco and learns only by playing. It worked. In 36 minutes, on nothing but a Mac's CPU, it went on to beat the hard robot 6 times in 10. It is now a new level at the Table, and its weights are open on Hugging Face.

Really from scratch

"From scratch" means three things here:

The result is a small network: 48,651 numbers, about 200 KB. A language model has billions. This one only knows how to do one thing.

What the network sees

The network follows the same rule as the robot and every Retrucada player: it only gets what you would see sitting at the table. Its own cards, the turned card (the vira), the cards played face up, the raises, the score, and how often the opponent raised or folded in this match. The opponent's hand never goes in.

All of that becomes a list of 239 numbers. A test swaps the opponent's cards for others and checks that the list doesn't change at all. If the network ever starts "seeing" what it shouldn't, the test says so.

On the other side come 10 possible moves: play the weakest, middle or strongest card (face up or face down), raise, accept, fold, and play the hand of eleven. The network gives each one a chance, and the move is drawn by those chances. That's how it bluffs sometimes, and not always.

How it learns

The method is called reinforcement learning. It works like this:

  1. The network plays 384 matches: almost half against itself, a quarter against its past versions, and the rest against the three robots.
  2. At the end of each match it gets +1 if it won and -1 if it lost. That's all. Nobody tells it that raising with the strongest card in hand is good.
  3. The moves from the matches it won become a little more likely; the ones from the matches it lost, a little less.
  4. Repeat.

The problem is step 3: in a match of 25 decisions, which one won it? That's what a critic is for: a second network that tries to guess, at each moment, who is going to win. If a move left things better than the critic expected, it was a good move.

And there's a trick. During training only, the critic sees the opponent's hand. It's like a coach watching the game with the cards face up: it can judge your move better, but it never plays for you. The network that plays still sees nothing. With this coach, the network got to the same level sooner: at the same point in training, 57% against the hard robot, against 52% without it.

The raising war

At first, the network won 3% of its matches against the hard robot. It was basically random.

Within a few minutes it learned something, but also a bad habit: it raised on 20% of its moves and, when it got a raise, raised back 34% of the time. Playing against itself, both halves got into a raising war. Against the robots, that only gave them points.

Training really took off when I put more robot matches in the mix and made the learning step bigger. In the first run, each round barely moved the network. With a step 3 times bigger, it tied the medium robot within a few minutes.

How well it plays

Each number below comes from 2,000 matches to 12 points, alternating who starts, with deals the training never saw. The 95% confidence interval is about ±2 points.

Paulista Easy Medium Hard
Version 1 (41 min of training) 58% 61% 59%
Version 2 (36 min of training) 67% 64% 60%

Version 2 changed two things: the learning step starts big and shrinks until the end, and the three robots show up equally in training. It wins 56% of its matches against version 1.

For mineiro, the other style (fixed trump cards), I trained another network from scratch with the same recipe, in 20 minutes:

Mineiro Easy Medium Hard
Mineiro network 59% 59% 55%

Mineiro numbers sit closer to 50% because matches are short (about 6 hands, against 10 in paulista) and luck weighs more. The robots are the same: hard beats medium 66% of the time in paulista and 58% in mineiro.

What didn't help

It can be exploited

Beating the robots doesn't mean playing well against everyone. To measure that, I trained a second network, the hunter, only against the frozen network, which couldn't change.

The hunter gets to win 57% of its matches against it. And it's terrible against everything else: it loses to all three robots, even the easy one (22%). It didn't learn to play truco; it learned to play against that network.

So it has weak spots that an opponent who adapts can find. People adapt. If you find the way to beat it, tell me.

On the AI leaderboard

Retrucada has a leaderboard for AI models: language models play through the same agent API, against the robots, for rating. I had the network play there, as one more model, getting only what the API sends.

It took first place in paulista, with 1241 points after 238 matches (134 wins), tied in rating with Claude Opus 5.5, which played 6. It's not a head-to-head, and a rating after 6 matches still moves a lot. But it's fun to see a 200 KB network that only knows truco side by side with a model that knows everything.

Play against it

At the Table, the Neural net level comes after Hard, in both styles. It's rated like the others: beating it counts as beating a 1350 rating. The weights (260 KB) only download when you pick that level.

AI agents can play it through the API too, with level neural.

Where it falls short

For programmers

It's all in Retrucada's code, in TypeScript, with no machine learning library: the network, the gradients (checked by a test against finite differences) and PPO, the training algorithm. Matches run in parallel on the CPU cores, straight on the game engine.

pnpm ml:train --iters=250 --lr-end=1e-4   # trains (about 36 min)
pnpm ml:eval ml/runs/<folder>/latest.json 2000   # measures against the robots
pnpm ml:train --exploit=<model.json>   # the hunter
pnpm ml:ship ml/runs/<folder>/latest.json   # ships it in the game

The models are on Hugging Face under the MIT license: retrucada-zero-paulista and retrucada-zero-mineiro. Each one comes with the weights in safetensors, an example of loading it in PyTorch, and an encode.js that turns what the player sees into the 239 input numbers.

If you have a game with clear rules and a way to simulate matches, the recipe works:

  1. Give the network only what the player sees, and test it.
  2. Reward only the result (won or lost), without teaching moves.
  3. Mix opponents: itself, its past versions and the robots you already have.
  4. Measure with matches the training never saw, with the confidence interval next to each number.
  5. Train a hunter to see what the robot yardstick doesn't show.