{"id":20522204,"url":"https://github.com/piperliu/five-in-a-row-ai","last_synced_at":"2025-09-22T23:06:36.440Z","repository":{"id":118614908,"uuid":"464157192","full_name":"PiperLiu/five-in-a-row-AI","owner":"PiperLiu","description":"♟️ Deploy a AI five-in-a-row game. Including front-end, back-end \u0026 deep RL code. 基于 vue3 与 flask 部署的强化学习五子棋 AlphaGo 实践。","archived":false,"fork":false,"pushed_at":"2022-03-16T09:56:38.000Z","size":13033,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T02:53:43.542Z","etag":null,"topics":["mcts","mcts-algorithm","python","reinfrocement-learning","vue"],"latest_commit_sha":null,"homepage":"https://piperliu.github.io/five-in-a-row-AI/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PiperLiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-02-27T14:19:11.000Z","updated_at":"2024-08-30T04:01:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"c32aa8b8-e597-4e10-af63-4d6bec59ff82","html_url":"https://github.com/PiperLiu/five-in-a-row-AI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PiperLiu/five-in-a-row-AI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PiperLiu%2Ffive-in-a-row-AI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PiperLiu%2Ffive-in-a-row-AI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PiperLiu%2Ffive-in-a-row-AI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PiperLiu%2Ffive-in-a-row-AI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PiperLiu","download_url":"https://codeload.github.com/PiperLiu/five-in-a-row-AI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PiperLiu%2Ffive-in-a-row-AI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276487484,"owners_count":25651133,"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","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["mcts","mcts-algorithm","python","reinfrocement-learning","vue"],"created_at":"2024-11-15T22:34:31.018Z","updated_at":"2025-09-22T23:06:36.418Z","avatar_url":"https://github.com/PiperLiu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# five-in-a-row-AI\n♟️ Deploy a AI five-in-a-row game. Including front-end, back-end \u0026amp; deep RL code.\n\n前端基于 Vue3 构建，后端由 flask 提供简单的 restful 接口，调用 AlphaGo 算法（基于强化学习 + 蒙特卡洛树搜索）。\n\nPython 建议 3.6+ 版本， npm 建议 14.0+ 版本。棋盘大小、AI参数等均可自行配置（注意，更改棋盘大小后，需要重新训练对应棋盘大小的神经网络权重）。\n\n\u003cp style=\"text-align: center;\"\u003e\u003ca href=\"https://piperliu.github.io/five-in-a-row-AI/\"\u003e✨GitHub Demo Page✨\u003c/p\u003e\n\n![](./readme.gif)\n\n## ⚙️How to use | 如何一键使用\n\n下载本项目至你的服务器：\n\n```bash\ngit clone https://github.com/PiperLiu/five-in-a-row-AI.git\n```\n\n### 📄生成前端页面\n\n在 [./front-end/aichess/src/hooks/useChessRequestHook](./front-end/aichess/src/hooks/useChessRequestHook) 中更改你的接口。\n\n```typescript\n...\n      axios.post(url, data, {\n        baseURL: 'https://aichess.piperliu.xyz',  // 你的 API\n        headers: {\n          'Content-Type': 'application/json'\n        }\n...\n```\n\n生成页面需要一点前端基础，具体可见 [./front-end/aichess/README.md](./front-end/aichess/README.md) 。\n\n```bash\ncd front-end\\aichess\nnpm install\nnpm run build\n```\n\n### ⚗️部署后端服务\n\n注意，后端项目和 AI 训练使用的 Python 环境相同，具体依赖在 [./requirements.txt](./requirements.txt) 中。可以使用如下 pip 命令安装。\n\n```bash\npip install -r requirements.txt\n```\n\n运行 [./back-end/main.py](./back-end/main.py) 。\n\n```bash\ncd back-end\npython3 main.py\n```\n\n### 🤖训练你的 AI\n\n训练 AI 涉及到：你是像继续训练同一个神经网络，还另开一个炉灶。你可以通过命令行来告诉脚本，可以参考 [./ai/main.py](./ai/main.py) 。\n\n```bash\ncd ai\npython main.py\n```\n\n## 🤔思考\n\n前端总体没啥难的。但引入 live2d.js 时发现没有 npm ，只能在 index.html 里通过 script 引入一个 js 文件。于是就在 live2d 对应的 [./front-end/aichess/src/components/LiveGirlComponent.vue](./front-end/aichess/src/components/LiveGirlComponent.vue) 组件内：\n\n```typescript\n(window as unknown as Record\u003c'loadlive2d', (arg1: string, arg2: string) =\u003e void\u003e)\n    .loadlive2d('live2d', 'live2d/model/tia/model.json')\n```\n\n后端最为简单，毕竟这里也没有数据库操作、没有并发处理，就是用 flask 暴露了一个 post 接口，你把棋盘的样子传给我，我把下一步下在那里告诉你。\n\n但后端也是最费时的：在浏览器中被要求请求必须是 https 的，于是去给域名申请 ssl 。主要用到了 [acme.sh](https://github.com/acmesh-official/acme.sh) + nginx 。此外，我的后端跑在我的阿里云服务器的 docker 里，在里面再套上 tmux 保证运行的稳定性。 nginx 实现了一个转发：我的 flask 服务是 localhost:5000 ，我将 aichess.piperliu.xyz 转发到了 localhost:5000 。\n\n最后，阿里云对没有备案的域名（我的 piperliu.xyz ）进行了拦截。所以还要老老实实备案。\n\n关于 AI 训练： 8 × 8 的版本早就训练好了，见 [./back-end/models/current_policy_1.model](./back-end/models/current_policy_1.model) ，但是 15 × 15 的十分吃力 ：\n\n![](./ai/images/15_15_01.png)\n\n如上是熵值（MCTS最优动作与神经网络决策的熵），熵值越低 AI 越强大。训练了大概有 9 天，发现其熵值是突发性地降低的——这说明强化学习的训练很大程度与采样有关，采样平平无奇，则一直没有进步；采用突发奇想，可能会带来巨大的进步。\n\n具体的讨论我放在 [./ai/README.md](./ai/README.md) 中了。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiperliu%2Ffive-in-a-row-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiperliu%2Ffive-in-a-row-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiperliu%2Ffive-in-a-row-ai/lists"}