{"id":20309395,"url":"https://github.com/tq3940/expectiminimax-backgammon","last_synced_at":"2026-02-24T05:50:19.439Z","repository":{"id":242219224,"uuid":"808983604","full_name":"tq3940/Expectiminimax-Backgammon","owner":"tq3940","description":"基于 Expectiminimax 的西洋双陆棋博弈，参考了alexandremartens 、chanddu等大佬的有关项目 ","archived":false,"fork":false,"pushed_at":"2024-06-01T10:56:41.000Z","size":13098,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T02:15:20.654Z","etag":null,"topics":["alpha-beta-pruning","artificial-intelligence","backgammon","expectiminimax","graphviz","minimax-algorithm","pygame-application"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tq3940.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-01T10:53:58.000Z","updated_at":"2024-06-01T11:22:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"82b40b87-768b-44d5-9eb6-da246319890e","html_url":"https://github.com/tq3940/Expectiminimax-Backgammon","commit_stats":null,"previous_names":["tq3940/expectiminimax-backgammon"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tq3940/Expectiminimax-Backgammon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tq3940%2FExpectiminimax-Backgammon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tq3940%2FExpectiminimax-Backgammon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tq3940%2FExpectiminimax-Backgammon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tq3940%2FExpectiminimax-Backgammon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tq3940","download_url":"https://codeload.github.com/tq3940/Expectiminimax-Backgammon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tq3940%2FExpectiminimax-Backgammon/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262870872,"owners_count":23377312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpha-beta-pruning","artificial-intelligence","backgammon","expectiminimax","graphviz","minimax-algorithm","pygame-application"],"created_at":"2024-11-14T17:27:04.758Z","updated_at":"2025-10-24T14:46:55.847Z","avatar_url":"https://github.com/tq3940.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 基于 Expectiminimax 的西洋双陆棋博弈\n\n### 西洋双陆棋规则简介\n看完这两个基本上能了解个大概了\n\n[规则介绍 by bilibili@夏枫Nuster](https://www.bilibili.com/read/cv13667392/)\n\n[实战演示 by bilibili@瑞成男中音](https://www.bilibili.com/video/BV14D4y197By/)\n\n\n## 本项目实现功能\n1. 使用 `pygame` 实现图形化界面，用来输入当前棋盘状态与展示计算结果，使用了 [alexandremartens](https://github.com/alexandremartens) 的 [Backgammon](https://github.com/alexandremartens/Backgammon) 项目的图片作为资源 (backgammon.py) ；\n   \n2. 使用带 Alpha-beta 剪枝的 Expectiminimax 算法进行计算，在达到最大深度后对当前状态进行评估，以限定搜索深度，大部分代码实现来自 [chanddu](https://github.com/chanddu) 的 [Backgammon-python-numpy-](https://github.com/chanddu/Backgammon-python-numpy-) 项目 ~~（但貌似他并没有用到numpy~~ (expectiminimax.py) ；\n\n3. 使用 `graphviz` 画出博弈树 (draw_tree.py) 。\n   \n\n## 安装\n```\n    pip install pygame==2.5.2\n    pip install graphviz==0.20.3\n```\npython 版本：3.9\n\n项目已自带 `Graphviz-11.0.0-win64` （请在解压到当前文件夹下），且会自动设置环境变量，无需单独安装\n\n\n## 详细使用说明\n\n### 1. 输入棋盘状态\n\n(1). 在本项目文件夹下使用 ``python backgammon.py`` 启动；\n\n![启动示例图](img/start_example.png)\n\n\n(2). 选择当前行动玩家；\n\n(3). 左键单击添加棋子，右键单击移除棋子，堆、槽、中间横杆均可放置；\n\n(4). 左侧骰子，左键单击+1，右键单击-1，点击右侧 `DICE ROLL` 可随机掷骰子；\n\n(5). 点击开始即可计算\n\n### 2. 展示博弈树\n    \n计算结束后自动展示博弈树图，同时保存到当前路径下的 Expectiminimax-Tree.gv.png \n    \n由于博弈树较大，计算以及绘制时间可能较长\n![博弈树示意图](img/tree_example.png)\n```\n       绿色正三角: max节点\n       橙色倒三角: min节点\n       黄色圆形:   chance节点(计算期望值)\n       蓝色矩形:   终止节点(使用eval_fn对当前状态进行评估)\n       红色星形:   代表其之后的子叔被 Alpha-beta 剪枝掉了\n```\n\n### 3. 结果展示\n   \n![结果示意图](img/result_example.png)\n```\n    红色虚线：原来位置\n    红色实现：移入位置\n    蓝色虚线：吃掉对手\n    蓝色实线：被吃放到横栏上\n```\n\n## 一些实现细节\n    \n1. 使用 `pygame` 中 `Rect` 对象对每个交互元素进行定位，通过 `Rect.collidepoint(event.pos)` 来判断鼠标点击时是否在该 `Rect` 对象中\n\n2. 评估当前状态的函数可仔细看下 expectiminimax.py 中 `eval_fn` 函数，好像还可以用神经网络来学习 ~~但本菜鸡一时半会也搞不出来~~\n\n---\n### Others\n\n搞这玩意主要是博弈论期末要整个应用博弈论的项目  ~~本来就没听懂几节课，幸好不是考试~~\n\n讨论半天加上参考前人学长的项目最终决定把《人工智能原理》课中学过的和博弈论看起来占点边的 minimax 拿来搞，又找来找去找到书上这个西洋双陆棋 ~~(应该没有学长搞过这门冷门的东西吧)~~\n\n最后，非常感谢 [alexandremartens](https://github.com/alexandremartens) 、[chanddu](https://github.com/chanddu) 等大佬的开源项目和教程，本人第一次自己亲手写这么长的代码(虽然 expectiminimax.py 主要还是copy chanddu 大佬的)，如果有哪里不妥当的，请多包涵\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftq3940%2Fexpectiminimax-backgammon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftq3940%2Fexpectiminimax-backgammon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftq3940%2Fexpectiminimax-backgammon/lists"}