A minimal deep reinforcement learning project that trains an AI to play Liar's Dice by playing 60,000 games against itself in about 30 seconds on a CPU.

Stars

9

7-day growth

No data

Forks

10

Open issues

0

License

No data

Last updated

2026-07-05

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It is a self-contained, teachable example of deep RL with self-play, running quickly on laptop hardware, and includes a browser demo showing the AI's thought process.

Who it is for

  • Students learning reinforcement learning
  • Educators teaching ML/RL concepts
  • Hobbyists interested in game AI
  • Developers seeking a compact PyTorch RL demo

Use cases

  • Teaching the core ideas of RL (agent, state, action, reward, policy)
  • Demonstrating self-play training and win-rate improvement
  • Playing against a trained AI in a browser or terminal
  • Experimenting by changing game parameters (dice count, sides) and retraining

Strengths

  • Trains from scratch in under 30 seconds on CPU (no GPU needed)
  • Tiny codebase with clear separation of game logic, model, and training
  • Includes a pre-trained model and an interactive browser UI with action probabilities
  • Easy to modify game rules and re-train for experimentation

Considerations

  • Limited to a very simple game (2 dice per player, 6 sides) – may not scale to more complex games
  • Uses basic REINFORCE algorithm without modern RL improvements (PPO, DQN, etc.)
  • Requires PyTorch and matplotlib installation (though minimal dependencies)

README quick start

🎲 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).

  1. Two players each secretly roll 2 dice.
  2. 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".
  3. Each new bid must be strictly higher than the previous one.
  4. 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 conceptIn Liar's Dice
Agentthe AI player (a small neural network)
Environmentthe dice game + the opponent
Statemy 2 dice + the bids made so far
Actionraise the bid, or call "LIAR!"
Reward+1 if the agent wins the round, −1 if it loses
Policythe learned strategy: state → which action
Self-playthe 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

Description

Liar's Dice by self-play — a Deep Reinforcement Learning teaching case study. An AI learns to bluff from scratch in PyTorch, playable in the browser.

Related repositories

Similar projects matched by category, topics, and programming language.

lopopolo
Featured
lopopolo GitHub avatar

harness-engineering

Harness Engineering is a methodology for improving coding agent outputs by carefully crafting the environment around them—providing curated context, tools, and executable constraints that encode an organization’s nonfunctional requirements and cumulative lessons.

AI & Machine LearningAI Agents
2,390
slvDev
Featured
slvDev GitHub avatar

esp32-ai

A 28.9 million parameter language model runs on an $8 ESP32-S3 microcontroller entirely on-device, generating simple stories at about 9.5 tokens per second.

AI & Machine LearningLarge Language Models
1,960
littledivy
Featured
littledivy GitHub avatar

mimic

mimic captures traffic from any iOS or web app and automatically generates a Python client library that lets you call the app's API like a regular library.

AI & Machine Learning
1,482