一个用深度强化学习(自我对弈)训练AI玩“大话骰”的微型项目,在CPU上仅需约30秒即可完成60,000局自我对弈训练。

Stars

9

7 天增长

暂无数据

Fork 数

10

开放 Issue

0

开源协议

暂无数据

最近更新

2026-07-05

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

这是一个自包含、可教学的深度强化学习与自我对弈实例,无需GPU即可在普通笔记本上快速运行,并包含展示AI思考过程的浏览器演示。

适合谁使用

  • 学习强化学习的学生
  • 教授机器学习的教育者
  • 对游戏AI感兴趣的爱好者
  • 希望获得紧凑PyTorch强化学习演示的开发者

典型使用场景

  • 教学强化学习核心概念(智能体、状态、动作、奖励、策略)
  • 演示自我对弈训练及胜率提升过程
  • 在浏览器或终端中与训练好的AI对战
  • 通过修改游戏参数(骰子数、面数)重新训练进行实验

项目优势

  • 在CPU上不到30秒即可从零开始训练(无需GPU)
  • 代码极小,游戏逻辑、模型、训练代码分离清晰
  • 包含预训练模型和显示动作概率的交互式浏览器UI
  • 易于修改游戏规则并重新训练以进行实验

使用前须知

  • 仅限于非常简单的游戏(每玩家2个六面骰子),可能无法扩展到更复杂的游戏
  • 使用基础的REINFORCE算法,未采用现代强化学习改进(PPO、DQN等)
  • 需要安装PyTorch和matplotlib(虽然依赖很少)

README 快速开始

🎲 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

项目描述

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.

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

lopopolo
精选
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 与机器学习AI 智能体
2,390
slvDev
精选
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 与机器学习大语言模型
1,960
littledivy
精选
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 与机器学习
1,482