Giter VIP home page Giter VIP logo

mahjongcopilot's Introduction

麻将 Copilot / Mahjong Copilot

麻将 AI 助手,基于 mjai (Mortal模型) 实现的机器人。会对游戏对局的每一步进行指导。现支持雀魂三人、四人麻将。 QQ群:834105526 加入QQ群
Join Discord

Mahjong AI Assistant for Majsoul, based on mjai (Mortal model) bot impelementaion. When you are in a Majsoul game, AI will give you step-by-step guidance. Now supports Majsoul 3-person and 4-person game modes.

下载、帮助和更多信息请访问网站 Please see website for download, help, and more information
帮助信息 Help Info | https://mjcopilot.com


特性:

  • 对局每一步 AI 指导,可在游戏中覆盖显示
  • 自动打牌,自动加入游戏
  • 多语言支持
  • 支持本地 Mortal 模型和在线模型,支持三麻和四麻

Features:

  • Step-by-step AI guidance for the game, with optional in-game overlay.
  • Auto play & auto joining next game
  • Multi-language support
  • Supports Mortal local models and online models, 3p and 4p mahjong modes.

使用方法 / Instructions

开发

  1. 克隆 repo
  2. 安装 Python 虚拟环境。Python 版本推荐 3.11.
  3. 安装 requirements.txt 中的依赖。
  4. 安装 Playwright + Chromium
  5. 主程序入口: main.py

To Develope

  1. Clone the repo
  2. Install Python virtual environment. Python version 3.11 recommended.
  3. Install dependencies from requirements.txt
  4. Install Playwright + Chromium
  5. Main entry: main.py

示例脚本 Sample script:

git clone https://github.com/latorc/MahjongCopilot.git
cd MahjongCopilot
python -m venv venv
CALL venv\Scripts\activate.bat
pip install -r requirements.txt
set PLAYWRIGHT_BROWSERS_PATH=0
playwright install chromium
python main.py

配置模型

本程序支持几种模型来源。其中,本地模型(Local)是基于 Akagi 兼容的 Mortal 模型。要获取 Akagi 的模型,请参见 Akagi Github 的说明。

Model Configuration

This program supports different types of AI models. The 'Local' Model type uses Mortal models compatible with Akagi. To acquire Akagi's models, please refer to Akagi Github .

截图 / Screenshots

界面 / GUI

游戏中覆盖显示 (HUD)/ In-game Overlay (HUD)

设计 / Design

目录说明 Description for folders:

  • gui: tkinter GUI 相关类 / tkinter GUI related classes
  • game: 雀魂游戏相关类 / classes related to Majsoul game
  • bot: AI 模型和机器人实现 / implementations for AI models and bots
  • common: 共同使用的支持代码 commonly used supporting code
  • libriichi & libriichi3p: 编译完成的 libriichi 库文件 / For compiled libriichi libraries

鸣谢 / Credit

许可 / License

本项目使用 GNU GPL v3 许可协议。
协议全文请见 LICENSE

mahjongcopilot's People

Contributors

ccervus avatar d4kpps8v avatar latorc avatar yegetables avatar zxis233 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mahjongcopilot's Issues

三麻功能如何使用

我把三麻文件重命名为 mortal_3p.pth 放入 models 文件夹以及 libriichi3p.pyd 放入 libriichi3p 文件夹之后报错。显示找不到 libriichi3p-3.11-x86_64-pc-windows-msvc.pyd 文件。把文件改成这个名称后仍然报错
WARNING [BotThread]bot_local.py:38 | Cannot import libriichi3p: dynamic module does not define module export function (PyInit_libriichi3p)
已经测试过在 Akagi 上正常使用。

提示GUI更换字体

看到readme中的GUI可以正常显示麻将的彩色Emoji,请问使用的是哪一款字体?
是否可以在Python中进行指定?

建议不要打出后就清空 AI 提示,改成对局结束后再清空比较好

第 327 行 self.ai_guide_var.set("") 能不能不要这么快清空 AI 提示,比如我想自己先决定打什么,打出了之后再看看 AI 会怎么选择,这时却发现被清空了,很难受
改成对局结束后再清空比较好

# Update AI guide from Reaction
pending_reaction = self.bot_manager.get_pending_reaction()
if pending_reaction:
ai_guide_str, options = mjai_reaction_2_guide(pending_reaction, 3, self.st.lan())
ai_guide_str += '\n'
for tile_str, weight in options:
ai_guide_str += f" {tile_str:8} {weight*100:4.0f}%\n"
self.ai_guide_var.set(ai_guide_str)
else:
self.ai_guide_var.set("")

如果可以的话我可以提一个 PR

主程序无法启动

主程序偶然会发生无法初始化的问题,一旦出现无法初始化的问题接下去如何操作均无法再次正常启动主程序

2024-04-21 10:54:41,265 INFO [MainThread]settings.py:65 | Settings initialized and saved to settings.json
2024-04-21 10:54:41,622 INFO [BotThread]bot_manager.py:221 | Starting mitm proxy server, port=10999, upstream_proxy=sock5://localhost:7890
2024-04-21 10:54:41,622 INFO [BotThread]bot_manager.py:223 | Installing MITM certificate
2024-04-21 10:54:41,632 DEBUG [BotThread]mitm.py:180 | Certificate file: E:\MahjongCopilot\mitm_config\mitmproxy-ca-cert.cer
2024-04-21 10:54:41,665 INFO [UpdateHTML]updater.py:57 | Loading help html from https://mjcopilot.com/help
2024-04-21 10:54:41,726 INFO [BotThread]bot_manager.py:225 | MITM certificate installed
2024-04-21 10:54:41,726 ERROR [BotThread]bot_manager.py:263 | Bot Manager Thread Exception: Event loop is closed
Traceback (most recent call last):
File "bot_manager.py", line 225, in run
File "logging_init
.py", line 1489, in info
File "logging_init_.py", line 1634, in log
File "logging_init
.py", line 1644, in handle
File "logging_init_.py", line 1706, in callHandlers
File "logging_init_.py", line 978, in handle
File "mitmproxy\log.py", line 221, in emit
File "asyncio\base_events.py", line 806, in call_soon_threadsafe
File "asyncio\base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
2024-04-21 10:54:42,546 DEBUG [Check_update]updater.py:105 | Check update: Local version=0.5.5, Web version=0.5.5
2024-04-21 10:54:42,546 ERROR [Check_update]updater.py:113 | Event loop is closed

开启自动打牌时超时切换自动模式

不知道是不是必须一直焦点在游戏里造成的,反正如果时不时切出去干点别的忘了切回去再回去看的时候就显示变成自动模式了,反正X+20秒肯定是没了

ImportError

ImportError: DLL load failed while importing libriichi
请问如何解决

还有requirement.txt里少了个numpy

自动播放错误?

开启自动播放后,玩家无法以较高频率打出一张牌,时间限制到期。 相关区域的日志粘贴如下。

2024-04-10 22:41:25,588 INFO [BotThread]game_state.py:594 | Bot out: {'type': 'dahai', 'actor': 2, 'pai': '9s', 'tsumogiri': True, 'meta': {'q_values': [-7.6980696, -6.8152075, -0.17997062, -5.668787, -5.942912, -4.8249125, -8.440149, -0.06938946, -7.593259, -3.0436797, -0.22938383], 'mask_bits': 13225183494, 'is_greedy': True, 'batch_size': 1, 'eval_time_ns': 67163400, 'shanten': 3, 'at_furiten': False}}
2024-04-10 22:41:25,589 DEBUG [Auto_dahai_9s]automation.py:230 | Start executing task: Auto_dahai_9s, Automating action dahai 9s (step = 8)
2024-04-10 22:41:27,506 DEBUG [Auto_dahai_9s]automation.py:243 | Finished executing task: Auto_dahai_9s
2024-04-10 22:41:29,008 INFO [BotThread]bot_manager.py:457 | Retry automating pending reaction: dahai
2024-04-10 22:41:29,008 DEBUG [Auto_dahai_9s]automation.py:230 | Start executing task: Auto_dahai_9s, Automating action dahai 9s (step = 8)
2024-04-10 22:41:30,926 DEBUG [Auto_dahai_9s]automation.py:243 | Finished executing task: Auto_dahai_9s
2024-04-10 22:41:32,426 INFO [BotThread]bot_manager.py:457 | Retry automating pending reaction: dahai
2024-04-10 22:41:32,426 DEBUG [Auto_dahai_9s]automation.py:230 | Start executing task: Auto_dahai_9s, Automating action dahai 9s (step = 8)
2024-04-10 22:41:34,567 DEBUG [Auto_dahai_9s]automation.py:243 | Finished executing task: Auto_dahai_9s
2024-04-10 22:41:36,070 INFO [BotThread]bot_manager.py:457 | Retry automating pending reaction: dahai
2024-04-10 22:41:36,070 DEBUG [Auto_dahai_9s]automation.py:230 | Start executing task: Auto_dahai_9s, Automating action dahai 9s (step = 8)
2024-04-10 22:41:37,753 DEBUG [Auto_dahai_9s]automation.py:243 | Finished executing task: Auto_dahai_9s
2024-04-10 22:41:38,590 DEBUG [MainThread]bot_manager.py:158 | Bot Manager disabling automation

MITM证书导入成功但程序未识别

已尝试管理员身份运行MahjongCopilot.exe和手动安装mitmproxy-ca-cert.cer到本地计算机受信任的根证书颁发机构,证书显示导入成功,但打开Copilot右下角仍是红叉?请问是证书未能正确安装吗?

AI提示无法返回

QQ截图20240709135543
QQ截图20240709135556
QQ截图20240709135608
QQ截图20240709135617
一切似乎都很正常,但是没有AI提示,看起来应该是在返回的时候出现了某些错误,这和我的版本号有关吗?
conda list

packages in environment at F:\anaconda3\envs\Mahjong:

Name Version Build Channel

aioquic 0.9.25 pypi_0 pypi
altgraph 0.17.4 pypi_0 pypi
asgiref 3.7.2 pypi_0 pypi
attrs 23.2.0 pypi_0 pypi
blinker 1.8.2 pypi_0 pypi
brotli 1.1.0 pypi_0 pypi
bzip2 1.0.8 h2bbff1b_6
ca-certificates 2024.3.11 haa95532_0
certifi 2024.7.4 pypi_0 pypi
cffi 1.16.0 pypi_0 pypi
charset-normalizer 3.3.2 pypi_0 pypi
click 8.1.7 pypi_0 pypi
colorama 0.4.6 pypi_0 pypi
cryptography 42.0.8 pypi_0 pypi
filelock 3.15.4 pypi_0 pypi
flask 3.0.3 pypi_0 pypi
fsspec 2024.6.1 pypi_0 pypi
greenlet 3.0.3 pypi_0 pypi
h11 0.14.0 pypi_0 pypi
h2 4.1.0 pypi_0 pypi
hpack 4.0.0 pypi_0 pypi
hyperframe 6.0.1 pypi_0 pypi
idna 3.7 pypi_0 pypi
itsdangerous 2.2.0 pypi_0 pypi
jinja2 3.1.4 pypi_0 pypi
kaitaistruct 0.10 pypi_0 pypi
ldap3 2.9.1 pypi_0 pypi
libffi 3.4.4 hd77b12b_1
markupsafe 2.1.5 pypi_0 pypi
mitmproxy 10.2.4 pypi_0 pypi
mitmproxy-rs 0.5.2 pypi_0 pypi
mitmproxy-windows 0.5.2 pypi_0 pypi
mpmath 1.3.0 pypi_0 pypi
msgpack 1.0.8 pypi_0 pypi
networkx 3.3 pypi_0 pypi
numpy 2.0.0 pypi_0 pypi
openssl 3.0.14 h827c3e9_0
packaging 24.1 pypi_0 pypi
passlib 1.7.4 pypi_0 pypi
pefile 2023.2.7 pypi_0 pypi
pillow 10.4.0 pypi_0 pypi
pip 24.0 py311haa95532_0
playwright 1.42.0 pypi_0 pypi
protobuf 4.25.3 pypi_0 pypi
publicsuffix2 2.20191221 pypi_0 pypi
pyasn1 0.6.0 pypi_0 pypi
pyasn1-modules 0.4.0 pypi_0 pypi
pycparser 2.22 pypi_0 pypi
pydivert 2.1.0 pypi_0 pypi
pyee 11.0.1 pypi_0 pypi
pyinstaller 6.9.0 pypi_0 pypi
pyinstaller-hooks-contrib 2024.7 pypi_0 pypi
pylsqpack 0.3.18 pypi_0 pypi
pyopenssl 24.0.0 pypi_0 pypi
pyparsing 3.1.2 pypi_0 pypi
pyperclip 1.8.2 pypi_0 pypi
python 3.11.9 he1021f5_0
pywin32-ctypes 0.2.2 pypi_0 pypi
requests 2.32.3 pypi_0 pypi
riichi 0.1.1 pypi_0 pypi
ruamel-yaml 0.18.6 pypi_0 pypi
ruamel-yaml-clib 0.2.8 pypi_0 pypi
service-identity 24.1.0 pypi_0 pypi
setuptools 69.5.1 py311haa95532_0
sortedcontainers 2.4.0 pypi_0 pypi
sqlite 3.45.3 h2bbff1b_0
sympy 1.13.0 pypi_0 pypi
tk 8.6.14 h0416ee5_0
tkhtmlview 0.3.0 pypi_0 pypi
torch 2.2.1 pypi_0 pypi
tornado 6.4.1 pypi_0 pypi
typing-extensions 4.12.2 pypi_0 pypi
tzdata 2024a h04d1e81_0
urllib3 2.2.2 pypi_0 pypi
urwid-mitmproxy 2.1.2.1 pypi_0 pypi
vc 14.2 h2eaa2aa_4
vs2015_runtime 14.29.30133 h43f2093_4
werkzeug 3.0.3 pypi_0 pypi
wheel 0.43.0 py311haa95532_0
wsproto 1.2.0 pypi_0 pypi
xz 5.4.6 h8cc25b3_1
zlib 1.2.13 h8cc25b3_1
zstandard 0.22.0 pypi_0 pypi

游戏窗口大小会变来变去

在结束一局游戏时,会自动循环点击确定的位置。这时候每自动点击一次,窗口大小就会变小再恢复一次,不知道是什么原因。而且就算回到主界面后不点击,还是会每2秒就缩放一次。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.