# perfectDou-server **Repository Path**: jidongding/perfectDou-server ## Basic Information - **Project Name**: perfectDou-server - **Description**: perfectDou是当前最强ai斗地主,但源码只能模型与模型之间对弈,无法实际当中使用,所以perfectDou-server修改了源码,给改为了任意实战都可以调用api。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-13 - **Last Updated**: 2026-01-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: perfectDou, AI斗地主 ## README # 环境需求 由于perfectDou中有 libCalculateLeftHands.so文件的存在,让事情变得很麻烦,只能用linux和python3.7执行并且还得需要http服务通信。 如果没有linux,可以使用windows wsl(在windows商店一键安装即可) 有了linux系统之后,需要安装一个python3.7 有了python3.7之后 ```makefile 安装依赖模块 python3.7 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt python3.7 -m pip install onnxruntime==1.7.0 --index-url https://pypi.org/simple/ ``` # 发送请求函数 用python展示,如果使用其他语言道理是一样的。 ```python #接收json格式数据,向服务器发送请求 def send(data): try: # 发送POST请求,自动设置Content-Type为application/json # json参数会自动将字典转换为JSON字符串,并设置正确的请求头 response = requests.post( 'http://127.0.0.1:9999', json=data, # 自动处理JSON序列化和Content-Type timeout=10 # 设置超时时间(秒) ) # 检查响应状态码(200表示成功) if response.status_code == 200: print("请求成功!") #返回的数据 print(response.json()) else: print(f"请求失败,状态码:{response.status_code}") print("响应内容:", response.text) except Exception as e: print(f"发生错误:{str(e)}") ``` # 初始化AI ```python #ai初始化, #position_code如果是1的话代表自己是地主,如果是0的话,代表自己是地主上家,如果是2的话代表自己是地主下家。 #shoupai 自己的手牌,格式为字符串'RB2AKQJT9876543',R代表大王,B代表小王。如果是自己需要20张牌,其他玩家是17张牌。 #pid 随便填写 #three_landlord_cards 是三张底牌 #其他都是固定的 def aiInit(position_code,shoupai): aiInit = { "action": "init", "data":{ "pid": '100012', "three_landlord_cards": '345', "ai_amount": 1, "player_data":[ { "model": "PER", "hand_cards": shoupai, "position_code": position_code } ] } } initRes = send(aiInit) print('初始化ai返回消息',initRes) ``` # 上报玩家出牌信息 ```python #自己的不需要上报,只需要上报其他两位玩家即可, #player 代表玩家序号,跟position_code是一样的 #pid跟上面是一样的 #cards,是玩家出的牌 aiPlay = { "action": "play", "data": { "pid": '100012', "player": 1, "cards": '34567' } } resPlay = send(aiPlay) #可以查看ai返回的消息,得到自己想要的数据。 print('ai返回消息:',resPlay) ``` # scrcpyRpa作为前端 您可以任意选择是否使用scrcpyRpa作为前端,使用其他框架也是可以的,效果是一样的。 如果自己不想写前端程序,只需要把环境需求搭建上即可,其他事情交给scrcpyRpa。由于我测试开发使用的是华为pockets手机和微信小程序。如果使用其他手机或者非微信小程序的斗地主,需要将下面的json修改,将图片的roi替换即可。位置在在pai目录下有一个data.json文件。 ```javascript { "phone": "华为pockets", "self":{ "roi":[[251,702],[2402,875]],//手牌区域 "dizhuLogo":"run/omcx2488-852-2496-947" //自己是地主的标识 }, "left": { "notes": "左侧上家出牌数量和出牌区域", "roi":[[367,287],[1070,605]], "c1": "countLeft/12rq323-510-361-551", "c2": "countLeft/8e93323-510-361-553", "c3": "countLeft/l12c324-513-358-550", "c4": "countLeft/tzws325-513-359-548", "c5": "countLeft/14is325-511-359-549", "c6": "countLeft/okhv325-510-361-551", "c7": "countLeft/kjo2322-509-362-549", "c8": "countLeft/j0t5324-510-357-547", "c9": "countLeft/6ktw324-512-357-547", "c10": "countLeft/c9mg321-514-367-546", "c11": "countLeft/mfo8345-510-367-548", "c12": "countLeft/ish1345-516-366-548", "c13": "countLeft/rfqn344-515-367-547", "c14": "countLeft/cr1b346-514-367-542", "c15": "countLeft/u7rl346-512-368-547", "c16": "countLeft/v2k1346-514-366-547", "c17": "countLeft/4l7g343-514-365-548", "c18": "countLeft/gqej346-515-367-544", "c19": "countLeft/5ly6342-511-365-545", "c20": "countLeft/weoa316-509-342-551" }, "right": { "roi": [[1767,232],[2395,592]],//出牌区域 "c1": "countRight/7bpr2431-514-2457-547",//当前牌的数量c1代表的是只剩下一张牌,以此类推 "c2": "countRight/bv0z2428-511-2458-550", "c3": "countRight/2ib12432-516-2455-545", "c4": "countRight/ubih2430-511-2459-547", "c5": "countRight/zs7w2428-508-2460-549", "c6": "countRight/gjdy2422-507-2461-546", "c7": "countRight/lksa2425-506-2455-547", "c8": "countRight/ddx42430-512-2459-544", "c9": "countRight/w7b52426-509-2458-547", "c10": "countRight/wila2419-510-2469-548", "c11": "countRight/j16r2445-510-2469-552", "c12": "countRight/grkp2446-514-2467-551", "c13": "countRight/0zcw2443-512-2468-549", "c14": "countRight/0t1u2448-512-2468-547", "c15": "countRight/sj9y2448-511-2466-546", "c16": "countRight/1r3a2447-512-2467-547", "c17": "countRight/ds8q2444-512-2469-547", "c18": "countRight/mi362445-513-2468-547", "c19": "countRight/gn8p2445-511-2468-547", "c20": "countRight/9pa52416-506-2443-553" }, "cf": { "notes": "固位匹配和扫描匹配的置信度", "fix": 0.8, "scan": 0.8 }, "run": { "notes": "三家不出的标识", "buchuLeft": "run/xplj470-352-613-422", "buchuRight": "run/yjtg2193-355-2328-417", "buchuSelf": "run/gdaf1320-631-1464-700" }, "server": { "ipPort": "http://127.0.0.1:9999", "pid": 10001 } } ``` scrcpyRpa使用的是在网页中显示消息,就是说如果查看出牌提示可以使用,手机,电脑,平板,电视都可以。玩的时候也可以使用电脑投屏软件或者直接在手机上面玩也可以。 # 在线演示地址 https://outer-perfectdou-demo-gzailab.nie.netease.com/ # 赞助 修改perfectDou源码不易,接受大家1元起的赞助,赞助之后留下您的微信号,我后续会加您微信。 ![输入图片说明](https://env-00jxh1ahkbe6.normal.cloudstatic.cn/weixinzhifub.jpg?expire_at=1768273704&er_sign=9ed44c7ed55c3b412e72d71648e22c78)