retrucada-zero-paulista
A mini model for playing Truco
2 min readupdated
This compact policy/value model is built for playing Paulista Truco (1v1), a card game featured in the Retrucada project. The model was trained from scratch using self-play (PPO) without human intervention or distillation from other models, relying solely on the game rules. Its architecture is a compact multilayer perceptron (MLP) with two hidden layers of 128 neurons and around 48,000 parameters. The AI model outperforms built-in bots of varying difficulty and runs entirely on the CPU.
Key features
- Trained from scratch via self-play using PPO based on the game engine.
- Compact size: just 48,651 parameters in float32 format (`model.safetensors`).
- Solid win rate against bots: around 58-60% against easy, medium, and hard robots.
- Training took less than an hour on a standard CPU thanks to TypeScript and Python implementations.
What you can do
- Integrate the model into custom bots or card game environments.
- Run and test network inference locally with minimal system requirements.
- Use the MLP architecture for reinforcement learning experiments in other tabletop games.
Example
Loading and initializing the model in PyTorch:
import torch, torch.nn as nn
from safetensors.torch import load_file
class RetrucadaNet(nn.Module):
def __init__(self, inputs=239, hidden=(128, 128), actions=10):
super().__init__()
dims = [inputs, *hidden]
self.torso = nn.ModuleList(nn.Linear(a, b) for a, b in zip(dims, dims[1:]))
self.policy = nn.Linear(dims[-1], actions)
self.value = nn.Linear(dims[-1], 1)
def forward(self, x, mask):
for layer in self.torso:
x = torch.relu(layer(x))
logits = self.policy(x).masked_fill(~mask, float("-inf"))
return logits, torch.tanh(self.value(x)).squeeze(-1)
net = RetrucadaNet()
net.load_state_dict(load_file("model.safetensors"))Read more
DetailsBenchmarks: 58% win rate against easy, 60.8% against medium, 58.6% against hard (matches up to 12 points).
Hardware requirements: extremely low, both training and inference run on CPU.
Limitations: the model is trained only for the standard Paulista version and has not been tested against humans.










Comments