DouZero_For_HLDDZ_FullAuto: 将DouZero用于欢乐斗地主自动化

Overview

DouZero_For_HLDDZ_FullAuto: 将DouZero用于欢乐斗地主自动化

  • 本项目基于DouZeroDouZero_For_Happy_DouDiZhu
  • 环境配置请移步项目DouZero
  • 模型默认为ADP,更换模型请修改main.py中的模型路径
  • 运行main.py即可
  • 在原 DouZero_For_Happy_DouDiZhu 的基础上加入了自动出牌,基于手牌自动叫牌,加倍,同时修改截屏方式为窗口区域截屏,游戏原窗口遮挡不影响游戏进行。
  • 请勿把游戏界面最小化,否则无法使用

说明

  • 欢乐斗地主使用 窗口 模式运行
  • 如果觉得这个项目有用,请给一个Star谢谢!
  • 本项目仅供学习以及技术交流,请勿用于其它目的,否则后果自负。

使用步骤

  1. 先使用 debug_screenshot.py 确认自己的屏幕缩放比

  2. 修改 main.py 中屏幕缩放比为自己屏幕的缩放比

  3. 点击游戏中开始游戏后点击程序的 自动开始

  4. 如果需要自动继续下一把,点击单局按钮,使其变为自动

自动叫牌/加倍原理

用DouZero自我博弈N局,对于随机到的每种手牌,随机生成若干种对手手牌,把该牌型和赢的局数扔进一个简单的全连接网络进行训练,得到手牌与胜率之间的关系,最后根据预期胜率,以一定阈值进行叫牌和加倍。

潜在Bug

  • 有较低几率把王炸识别为不出

鸣谢

其他

欢迎加入QQ群交流自动化相关:565142377

也可以在原作者DouZero_For_Happy_DouDiZhu 的QQ群交流

You might also like...
Comments
  • 叫地主后闪退

    叫地主后闪退

    叫牌预估得分: 0.772 不叫预估得分: 1.234 等待加倍或叫地主...地主牌: DXX22AAAAAKQQQQQJJJTT998877666554444433 Traceback (most recent call last): File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\main.py", line 437, in game_loop self.before_start() File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\main.py", line 845, in before_start win_rate = LandlordModel.predict_by_model(cards_str, llcards) File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\LandlordModel.py", line 112, in predict_by_model action_message, show_action_list = pre_env.step("landlord") File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\douzero\env\game.py", line 156, in step action, actions_confidence, action_list = self.players[1].act(self.game_infoset) File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\douzero\evaluation\deep_agent.py", line 44, in act obs = get_obs(infoset, model_type=self.model_type) File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\douzero\env\env.py", line 193, in get_obs return _get_obs_resnet(infoset, infoset.player_position) File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\douzero\env\env.py", line 598, in _get_obs_resnet three_landlord_cards = _cards2array(infoset.three_landlord_cards) File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\douzero\env\env.py", line 228, in _cards2array matrix[:, Card2Column[card]] = NumOnes2Array[num_times] KeyError: 5

    opened by icekylinH 0
  • 运行报错

    运行报错

    运行时出现错误,已重置 KeyError(None) Traceback (most recent call last): File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\main.py", line 269, in init_cards self.start() File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\main.py", line 525, in start self.handle_others(self.RPlayedCardsPos, self.RPlayedCard, "下家") File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\main.py", line 379, in handle_others self.env.step(self.user_position, self.other_played_cards_env) File "C:\Gametools\DouZero_For_HLDDZ_FullAuto-main\douzero\env\game.py", line 205, in step self.played_cards[self.acting_player_position] += action KeyError: None

    opened by icekylinH 0
  • 测试分辨率报错

    测试分辨率报错

    截图时出现错误: error(1400, 'GetWindowRect', '无效的窗口句柄。') 截图时出现错误: error(1400, 'GetWindowRect', '无效的窗口句柄。') 截图时出现错误: error(1400, 'GetWindowRect', '无效的窗口句柄。') Traceback (most recent call last): File "H:\Code Files\Python\Pycharm\DouZero_For_HLDDZ_FullAuto\DouZero_For_HLDDZ_FullAuto-main\debug_screenshot.py", line 7, in img = gh.DrawRectWithText(img, (313, 747, 1144, 200), "test") File "H:\Code Files\Python\Pycharm\DouZero_For_HLDDZ_FullAuto\DouZero_For_HLDDZ_FullAuto-main\GameHelper.py", line 29, in DrawRectWithText img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'cvtColor'

    Overload resolution failed:

    • src data type = 17 is not supported
    • Expected Ptrcv::UMat for argument 'src'
    opened by ZakiuC 2
Owner
null