parent
ce06486c03
commit
d0586b7d2f
|
@ -180,8 +180,8 @@ class GameHelper:
|
|||
def Screenshot(self, region=None): # -> (im, (left, top))
|
||||
self.Handle = win32gui.FindWindow("Hlddz", None)
|
||||
hwnd = self.Handle
|
||||
# im = Image.open(r"C:\Users\q9294\Desktop\Snipaste_2021-09-05_00-52-51.png")
|
||||
# im = im.resize((1796, 1047))
|
||||
# im = Image.open(r"F:\DouZero\DouZero_For_HLDDZ_FullAuto\test.png")
|
||||
# im = im.resize((1798, 1047))
|
||||
# return im, (0,0)
|
||||
left, top, right, bot = win32gui.GetWindowRect(hwnd)
|
||||
width = right - left
|
||||
|
@ -214,7 +214,7 @@ class GameHelper:
|
|||
else:
|
||||
return None, (0, 0)
|
||||
|
||||
def LocateOnScreen(self, templateName, region, confidence=0.9):
|
||||
def LocateOnScreen(self, templateName, region, confidence=0.85):
|
||||
image, _ = self.Screenshot()
|
||||
return pyautogui.locate(needleImage=self.Pics[templateName],
|
||||
haystackImage=image, region=region, confidence=confidence)
|
||||
|
|
|
@ -2,7 +2,7 @@ import GameHelper as gh
|
|||
from GameHelper import GameHelper
|
||||
|
||||
GameHelper = GameHelper()
|
||||
GameHelper.ScreenZoomRate = 1.25
|
||||
GameHelper.ScreenZoomRate = 1.0
|
||||
img, _ = GameHelper.Screenshot()
|
||||
img = gh.DrawRectWithText(img, (313, 747, 1144, 200), "test")
|
||||
img.save("test.png")
|
||||
|
|
73
main.py
73
main.py
|
@ -45,7 +45,7 @@ AllCards = ['rD', 'bX', 'b2', 'r2', 'bA', 'rA', 'bK', 'rK', 'bQ', 'rQ', 'bJ', 'r
|
|||
'b9', 'r9', 'b8', 'r8', 'b7', 'r7', 'b6', 'r6', 'b5', 'r5', 'b4', 'r4', 'b3', 'r3']
|
||||
|
||||
helper = GameHelper()
|
||||
helper.ScreenZoomRate = 1.25 # 请修改屏幕缩放比
|
||||
helper.ScreenZoomRate = 1.0 # 请修改屏幕缩放比
|
||||
|
||||
class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
||||
def __init__(self):
|
||||
|
@ -63,9 +63,9 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
|
||||
# 参数
|
||||
self.MyConfidence = 0.95 # 我的牌的置信度
|
||||
self.OtherConfidence = 0.9 # 别人的牌的置信度
|
||||
self.OtherConfidence = 0.87 # 别人的牌的置信度
|
||||
self.WhiteConfidence = 0.95 # 检测白块的置信度
|
||||
self.LandlordFlagConfidence = 0.9 # # 检测地主标志的置信度
|
||||
self.LandlordFlagConfidence = 0.85 # # 检测地主标志的置信度
|
||||
self.ThreeLandlordCardsConfidence = 0.9 # 检测地主底牌的置信度
|
||||
self.PassConfidence = 0.85
|
||||
self.WaitTime = 1 # 等待状态稳定延时
|
||||
|
@ -73,6 +73,7 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
self.OtherFilter = 25 # 别人的牌检测结果过滤参数
|
||||
self.SleepTime = 0.1 # 循环中睡眠时间
|
||||
self.RunGame = False
|
||||
print("self.RunGame = False 2")
|
||||
self.AutoPlay = False
|
||||
self.BidThreshold1 = 65 # 叫地主阈值
|
||||
self.BidThreshold2 = 72 # 抢地主阈值
|
||||
|
@ -93,9 +94,9 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
self.shouldExit = 0 # 通知上一轮记牌结束
|
||||
self.canRecord = threading.Lock() # 开始记牌
|
||||
self.card_play_model_path_dict = {
|
||||
'landlord': "baselines/douzero_ADP/landlord.ckpt",
|
||||
'landlord_up': "baselines/douzero_ADP/landlord_up.ckpt",
|
||||
'landlord_down': "baselines/douzero_ADP/landlord_down.ckpt"
|
||||
'landlord': "baselines/resnet/landlord.ckpt",
|
||||
'landlord_up': "baselines/resnet/landlord_up.ckpt",
|
||||
'landlord_down': "baselines/resnet/landlord_down.ckpt"
|
||||
}
|
||||
|
||||
def init_display(self):
|
||||
|
@ -353,22 +354,27 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
result = helper.LocateOnScreen("finish_round", region=(810,840,200,80), confidence=0.8)
|
||||
if result is not None:
|
||||
helper.ClickOnImage("finish_round", region=(810,840,200,80), confidence=0.8)
|
||||
print("finish_round")
|
||||
self.sleep(1000)
|
||||
result = helper.LocateOnScreen("next_round", region=(958,869,300,100), confidence=0.8)
|
||||
if result is not None:
|
||||
helper.ClickOnImage("next_round", region=(958,869,300,100), confidence=0.8)
|
||||
print("next_round")
|
||||
self.sleep(1000)
|
||||
self.beforeStart()
|
||||
result = helper.LocateOnScreen("yes_btn", region=(680, 661, 435, 225))
|
||||
if result is not None:
|
||||
print("yes_btn")
|
||||
helper.ClickOnImage("yes_btn", region=(680, 661, 435, 225))
|
||||
self.sleep(1000)
|
||||
result = helper.LocateOnScreen("get_award_btn", region=(680, 661, 435, 225))
|
||||
if result is not None:
|
||||
print("get_award_btn")
|
||||
helper.ClickOnImage("get_award_btn", region=(680, 661, 435, 225))
|
||||
self.sleep(1000)
|
||||
result = helper.LocateOnScreen("yes_btn_sm", region=(669, 583, 468, 100))
|
||||
if result is not None:
|
||||
print("yes_btn_sm")
|
||||
helper.ClickOnImage("yes_btn_sm", region=(669, 583, 468, 100))
|
||||
self.sleep(200)
|
||||
|
||||
|
@ -382,18 +388,40 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
result = pyautogui.locateAll(needleImage=helper.Pics['o' + card], haystackImage=img,
|
||||
confidence=self.ThreeLandlordCardsConfidence)
|
||||
three_landlord_cards_real += card[1] * self.cards_filter(list(result), self.OtherFilter)
|
||||
if len(three_landlord_cards_real) > 3:
|
||||
three_landlord_cards_real = ""
|
||||
for card in AllCards:
|
||||
result = pyautogui.locateAll(needleImage=helper.Pics['o' + card], haystackImage=img,
|
||||
confidence=self.ThreeLandlordCardsConfidence + 0.05)
|
||||
three_landlord_cards_real += card[1] * self.cards_filter(list(result), self.OtherFilter)
|
||||
if len(three_landlord_cards_real) < 3:
|
||||
three_landlord_cards_real = ""
|
||||
for card in AllCards:
|
||||
result = pyautogui.locateAll(needleImage=helper.Pics['o' + card], haystackImage=img,
|
||||
confidence=self.ThreeLandlordCardsConfidence + 0.1)
|
||||
three_landlord_cards_real += card[1] * self.cards_filter(list(result), self.OtherFilter)
|
||||
delta = 0
|
||||
ratio = 0.05
|
||||
direction = 0
|
||||
for i in range(0, 15):
|
||||
if len(three_landlord_cards_real) > 3:
|
||||
if direction == 0:
|
||||
delta = ratio
|
||||
elif direction == -1:
|
||||
ratio /= 2
|
||||
delta += ratio
|
||||
else:
|
||||
delta += ratio
|
||||
direction = 1
|
||||
three_landlord_cards_real = ""
|
||||
for card in AllCards:
|
||||
result = pyautogui.locateAll(needleImage=helper.Pics['o' + card], haystackImage=img,
|
||||
confidence=self.ThreeLandlordCardsConfidence + delta)
|
||||
three_landlord_cards_real += card[1] * self.cards_filter(list(result), self.OtherFilter)
|
||||
elif len(three_landlord_cards_real) < 3:
|
||||
if direction == 0:
|
||||
delta = -ratio
|
||||
elif direction == 1:
|
||||
ratio /= 2
|
||||
delta -= ratio
|
||||
else:
|
||||
delta -= ratio
|
||||
direction = -1
|
||||
three_landlord_cards_real = ""
|
||||
for card in AllCards:
|
||||
result = pyautogui.locateAll(needleImage=helper.Pics['o' + card], haystackImage=img,
|
||||
confidence=self.ThreeLandlordCardsConfidence + delta)
|
||||
three_landlord_cards_real += card[1] * self.cards_filter(list(result), self.OtherFilter)
|
||||
else:
|
||||
break
|
||||
return three_landlord_cards_real
|
||||
|
||||
def find_my_cards(self, pos):
|
||||
|
@ -447,6 +475,7 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
def stop(self):
|
||||
try:
|
||||
self.RunGame = False
|
||||
print("self.RunGame = False")
|
||||
self.env.game_over = True
|
||||
self.env.reset()
|
||||
self.init_display()
|
||||
|
@ -465,12 +494,14 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
|
||||
def beforeStart(self):
|
||||
self.RunGame = True
|
||||
print("self.RunGame = True")
|
||||
GameHelper.Interrupt = True
|
||||
HaveBid = False
|
||||
isTaodou = False
|
||||
is_stolen = 0
|
||||
while True:
|
||||
if not self.RunGame:
|
||||
print("return")
|
||||
return
|
||||
outterBreak = False
|
||||
jiaodizhu_btn = helper.LocateOnScreen("jiaodizhu_btn", region=(765, 663, 116, 50))
|
||||
|
@ -485,6 +516,7 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
qiangdizhu_btn = helper.LocateOnScreen("qiangdizhu_btn", region=(783, 663, 116, 50))
|
||||
jiabei_btn = helper.LocateOnScreen("jiabei_btn", region=self.GeneralBtnPos)
|
||||
if jiabei_btn is None:
|
||||
print("jiabei_btn_1")
|
||||
img, _ = helper.Screenshot()
|
||||
cards, _ = helper.GetCards(img)
|
||||
cards_str = "".join([card[0] for card in cards])
|
||||
|
@ -517,6 +549,7 @@ class MyPyQT_Form(QtWidgets.QWidget, Ui_Form):
|
|||
print("淘豆场,跳过加倍")
|
||||
break
|
||||
else:
|
||||
print("find_three_landlord_cards_1")
|
||||
llcards = self.find_three_landlord_cards(self.ThreeLandlordCardsPos)
|
||||
print("地主牌:", llcards)
|
||||
img, _ = helper.Screenshot()
|
||||
|
@ -617,4 +650,8 @@ if __name__ == '__main__':
|
|||
""")
|
||||
my_pyqt_form = MyPyQT_Form()
|
||||
my_pyqt_form.show()
|
||||
# my_pyqt_form.find_three_landlord_cards((763, 37, 287, 136))
|
||||
# my_pyqt_form.find_other_cards((463, 355, 380, 250));
|
||||
# btn = helper.LocateOnScreen("jiabei_btn", region=(616, 631, 576, 117))
|
||||
# my_pyqt_form.beforeStart()
|
||||
sys.exit(app.exec_())
|
||||
|
|
Loading…
Reference in New Issue