基于DouZero定制AI实战欢乐斗地主

Overview

DouZero_For_Happy_DouDiZhu: 将DouZero用于欢乐斗地主实战

Logo

  • 本项目基于DouZero
  • 环境配置请移步项目DouZero
  • 模型默认为WP,更换模型请修改start.py中的模型路径
  • 运行main.py即可
  • SL (baselines/sl/): 基于人类数据进行深度学习的预训练模型
  • DouZero-ADP (baselines/douzero_ADP/): 以平均分数差异(Average Difference Points, ADP)为目标训练的Douzero智能体
  • DouZero-WP (baselines/douzero_WP/): 以胜率(Winning Percentage, WP)为目标训练的Douzero智能体

说明

  • 将玩家角色设置为AI,需开局时手动输入玩家角色、初始手牌、三张底牌
  • 每轮手动输入其他两位玩家出的牌,AI给出出牌建议以及预计胜率
  • 暂未设计可视化界面,正考虑通过截屏自动识别开局手牌。
  • 欢乐斗地主窗口模式最大化运行,屏幕分辨率1920x1080。由于设计像素级操作,运行出错请检查截图区域坐标(位于MyPyQT_Form类中的__init__函数内)
  • 窗口移至右下角,避免遮挡手牌,历史牌,底牌区域。

使用步骤

  1. 确认环境正常,等待手牌出现、底牌出现、地主角色确认后,点击开始,耗时几秒完成识别。
  2. 窗口内显示识别结果,地主角色使用淡红色标出。识别完成自动开始记录出牌。
  3. 观察AI建议的出牌,在游戏中手动选择并打出。
  4. 游戏结束后弹出对话框提示输赢。
  5. 识别错误或无反应可通过结束按钮停止本局。至于游戏,就自己手动打完吧。

潜在Bug

  • 王炸时出牌特效时间较长,有一定几率导致只能识别出一个王。

鸣谢

  • 本项目基于DouZero
  • 借鉴了cardRecorder项目的部分代码以及模板图片,用于识别扑克牌

相关链接

Comments
  • 请问这是我的设置问题吗

    请问这是我的设置问题吗

    我首先按照要求安装了所需依赖,进入对局点击开始后提示输出

    等待下家出牌 等待下家出牌 等待下家出牌

    下家出牌: 44333 Traceback (most recent call last): File "c:\Users\11984\Downloads\DouZero_For_HappyDouDiZhu-master\main.py", line 170, in init_cards self.start() File "c:\Users\11984\Downloads\DouZero_For_HappyDouDiZhu-master\main.py", line 226, in start
    self.env.step(self.user_position, self.other_played_cards_env) TypeError: step() takes 1 positional argument but 3 were given

    以上这样的报错 图形界面卡死,图片附上

    report

    opened by jiahao2333 4
  • 开始以后闪退

    开始以后闪退

    看记录好像能识别出手牌,麻烦帮忙看看是为什么

    F:\Desktop\DouZero_For_HappyDouDiZhu-2.0>python main.py {'three_landlord_cards': [9, 8, 3], 'landlord_up': [17, 17, 14, 14, 13, 13, 12, 12, 10, 9, 8, 7, 7, 6, 5, 4, 3], 'landlord': [9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 13, 13, 14, 14, 17, 17, 20, 30], 'landlord_down': [3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8]} Traceback (most recent call last): File "C:\Users\liule\AppData\Local\Programs\Python\Python38\lib\site-packages\git_init_.py", line 83, in refresh() File "C:\Users\liule\AppData\Local\Programs\Python\Python38\lib\site-packages\git_init_.py", line 73, in refresh if not Git.refresh(path=path): File "C:\Users\liule\AppData\Local\Programs\Python\Python38\lib\site-packages\git\cmd.py", line 287, in refresh raise ImportError(err) ImportError: Bad git executable. The git executable must be specified in one of the following ways: - be included in your $PATH - be set via $GIT_PYTHON_GIT_EXECUTABLE - explicitly set via git.refresh()

    All git commands will error until this is rectified.

    This initial warning can be silenced or aggravated in the future by setting the $GIT_PYTHON_REFRESH environment variable. Use one of the following values: - quiet|q|silence|s|none|n|0: for no warning or exception - warn|w|warning|1: for a printed warning - error|e|raise|r|2: for a raised exception

    Example: export GIT_PYTHON_REFRESH=quiet

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "main.py", line 164, in init_cards ai_players[1] = DeepAgent(self.user_position, self.card_play_model_path_dict[self.user_position]) File "F:\Desktop\DouZero_For_HappyDouDiZhu-2.0\douzero\evaluation\deep_agent.py", line 25, in init self.model = load_model(position, model_path) File "F:\Desktop\DouZero_For_HappyDouDiZhu-2.0\douzero\evaluation\deep_agent.py", line 7, in load_model from douzero.dmc.models import model_dict File "F:\Desktop\DouZero_For_HappyDouDiZhu-2.0\douzero\dmc_init.py", line 1, in from .dmc import train File "F:\Desktop\DouZero_For_HappyDouDiZhu-2.0\douzero\dmc\dmc.py", line 12, in from .file_writer import FileWriter File "F:\Desktop\DouZero_For_HappyDouDiZhu-2.0\douzero\dmc\file_writer.py", line 25, in import git File "C:\Users\liule\AppData\Local\Programs\Python\Python38\lib\site-packages\git_init.py", line 85, in raise ImportError('Failed to initialize: {0}'.format(exc)) ImportError: Failed to initialize: Bad git executable. The git executable must be specified in one of the following ways: - be included in your $PATH - be set via $GIT_PYTHON_GIT_EXECUTABLE - explicitly set via git.refresh()

    All git commands will error until this is rectified.

    This initial warning can be silenced or aggravated in the future by setting the $GIT_PYTHON_REFRESH environment variable. Use one of the following values: - quiet|q|silence|s|none|n|0: for no warning or exception - warn|w|warning|1: for a printed warning - error|e|raise|r|2: for a raised exception

    Example: export GIT_PYTHON_REFRESH=quiet

    opened by 0xbba 3
  • 区域坐标能否解答下?

    区域坐标能否解答下?

    self.MyHandCardsPos = (414, 804, 1041, 59)  # 我的截图区域
            self.LPlayedCardsPos = (530, 470, 380, 160)  # 左边截图区域
            self.RPlayedCardsPos = (1010, 470, 380, 160)  # 右边截图区域
            self.LandlordFlagPos = [(1320, 300, 110, 140), (320, 720, 110, 140), (500, 300, 110, 140)]  # 地主标志截图区域(右-我-左)
            self.ThreeLandlordCardsPos = (817, 36, 287, 136)      # 地主底牌截图区域,resize成349x168
    

    我怎么用坐标拾取工具对比了下发现完全不对

    opened by daofeng2015 1
  • 由于分辨率导致的牌面识别瓶颈改进意见

    由于分辨率导致的牌面识别瓶颈改进意见

    使用win32gui库对游戏窗口进行坐标(0,0)、尺寸(默认尺寸)自动固定,如下: win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0, 1440, 838, win32con.SWP_SHOWWINDOW)

    然后在此基础上制作配套pics,可极大降低由分辨率问题引起的各类找图问题。

    opened by null119 0
  • pos_duge报错

    pos_duge报错

    [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('QQ截图20220507102631.png'): can't open/read file: check file path/integrity Traceback (most recent call last): File "G:/python/code_py/douzero_huanledoudizhu/DouZero_For_HappyDouDiZhu/pos_debug.py", line 25, in cv2.imshow("test", img) cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' 想问一下这是什么情况

    opened by fengmianchen 0
Releases(v2.0)
Owner
null