🎲 Liar's Dice by Self-Play — a Reinforcement Learning case study
An AI that teaches itself to play (and bluff at) Liar's Dice, using
Deep Reinforcement Learning in PyTorch. It starts knowing nothing and
learns purely by playing 60,000 games against itself — in about
30 seconds on a normal laptop CPU (no GPU needed).
Built as a teaching example: small, self-contained, and fully runnable.
What is Liar's Dice?
A bluffing game of hidden information (a cousin of Poker).
- Two players each secretly roll 2 dice.
- They take turns making a bid — a claim about all 4 dice on the table,
e.g. "three fours" means "there are at least three 4s in total".
- Each new bid must be strictly higher than the previous one.
- Instead of bidding, a player can shout "LIAR!" to challenge the last bid.
All dice are revealed:
- if the real count meets the bid → the bid was true, the challenger loses;
- otherwise it was a bluff, the bidder loses.
Because you can't see the opponent's dice, every move is a decision under
uncertainty — the perfect playground for reinforcement learning.
ML vs DL vs RL (the concept)
- Machine Learning (ML) — learn patterns from data/examples.
- Deep Learning (DL) — ML using neural networks.
- Reinforcement Learning (RL) — an agent takes actions, gets a
reward, and learns by trial-and-error what leads to winning.
This project is Deep RL = DL + RL: a neural network is the brain, trained by
the reward of winning games.
RL pieces, mapped onto this game
| RL concept | In Liar's Dice |
|---|
| Agent | the AI player (a small neural network) |
| Environment | the dice game + the opponent |
| State | my 2 dice + the bids made so far |
| Action | raise the bid, or call "LIAR!" |
| Reward | +1 if the agent wins the round, −1 if it loses |
| Policy | the learned strategy: state → which action |
| Self-play | the agent plays itself thousands of times |
The learning rule (the REINFORCE algorithm): after each game, make the
winner's moves more likely and the loser's moves less likely. Repeat.
The files
| File