├── start.bat ├── kards2.bat ├── k.png ├── No.png ├── start.png ├── confirm.png ├── continue.png ├── endturn.png ├── setting.png ├── surrender.png ├── requirements.txt ├── README.md ├── kards.py └── kards2.py /start.bat: -------------------------------------------------------------------------------- 1 | python kards.py -------------------------------------------------------------------------------- /kards2.bat: -------------------------------------------------------------------------------- 1 | python kards2.py 2 | 3 | -------------------------------------------------------------------------------- /k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/k.png -------------------------------------------------------------------------------- /No.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/No.png -------------------------------------------------------------------------------- /start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/start.png -------------------------------------------------------------------------------- /confirm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/confirm.png -------------------------------------------------------------------------------- /continue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/continue.png -------------------------------------------------------------------------------- /endturn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/endturn.png -------------------------------------------------------------------------------- /setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/setting.png -------------------------------------------------------------------------------- /surrender.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bulubr/autoKards/HEAD/surrender.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyScreeze==0.1.29 2 | numpy==1.26.4 3 | opencv_python==4.9.0.80 4 | PyAutoGUI==0.9.54 5 | PyGetWindow==0.0.9 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # autoKards 2 | Kards1939自动挂机升级脚本 3 | 4 | 解压后运行start.bat 5 | 6 | 检测到开始按钮时开始运行,进行拖牌等操作一分钟之内过回合,四分钟点击投降并开始下一局游戏 7 | 8 | 运行期间占用鼠标,若需一边进行其他鼠标操作 可运行kards2.bat 减少鼠标占用。 9 | 10 | 灵感来源 https://github.com/WHOAMIsuperMan/KardsAFK4EXP @WHOAMIsuperMan 11 | 12 | 原作者的软件及其完善以及有完整的出牌逻辑及防封操作但现在已经不更新了 13 | 14 | 此为其建议替代版本 能实现基本功能 15 | 16 | 分辨率需调整至1280x720 17 | -------------------------------------------------------------------------------- /kards.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | import cv2 3 | import numpy as np 4 | import time 5 | import os 6 | 7 | # 截图函数,捕捉指定区域的图像 8 | def take_screenshot(region=None): 9 | screenshot = pyautogui.screenshot(region=region) 10 | screenshot = np.array(screenshot) 11 | return cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR) 12 | 13 | # 检测按钮并返回是否找到按钮(不点击) 14 | def detect_button(image_path, threshold=0.8): 15 | screenshot = take_screenshot() 16 | template = cv2.imread(image_path, cv2.IMREAD_COLOR) 17 | result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED) 18 | min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) 19 | 20 | if max_val >= threshold: 21 | button_x, button_y = max_loc 22 | button_w, button_h = template.shape[1], template.shape[0] 23 | center_x, center_y = button_x + button_w // 2, button_y + button_h // 2 24 | print(f"Button detected at ({center_x}, {center_y})") 25 | return (center_x, center_y) 26 | return None 27 | 28 | # 检测按钮并移动鼠标点击 29 | def detect_and_click_button(image_path, threshold=0.8): 30 | button_pos = detect_button(image_path, threshold) 31 | if button_pos: 32 | pyautogui.moveTo(button_pos[0], button_pos[1]) 33 | time.sleep(0.5) # 稍作等待 34 | pyautogui.click() 35 | return True 36 | return False 37 | 38 | # 拖动鼠标操作 39 | def drag_mouse(start_x, start_y, drag_x, drag_y): 40 | pyautogui.moveTo(start_x, start_y) 41 | pyautogui.mouseDown() 42 | pyautogui.move(drag_x, drag_y) # 按住左键并拖动 43 | pyautogui.mouseUp() 44 | 45 | def drag_mouse(start_x, start_y, drag_x, drag_y, duration=0.3): 46 | pyautogui.moveTo(start_x, start_y) 47 | pyautogui.mouseDown() 48 | pyautogui.move(drag_x, drag_y, duration=duration) # 按住左键并拖动,duration 参数控制滑动速度 49 | pyautogui.mouseUp() 50 | 51 | # 检测并处理 Setting 图标操作 52 | def handle_setting_and_drag(setting_image_path): 53 | for i in range(1): # 重复1次拖动操作 54 | button_pos = detect_button(setting_image_path) 55 | if button_pos: 56 | center_x, center_y = button_pos 57 | # 移动鼠标至 setting 图标中央 58 | pyautogui.moveTo(center_x, center_y) 59 | time.sleep(1) # 稍作等待 60 | 61 | # 向左移动400像素,向下移动400像素 62 | pyautogui.move(-580, 630) 63 | time.sleep(1) # 稍作等待 64 | 65 | # 按住左键向上移动100像素后松开 66 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 67 | time.sleep(1) 68 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 69 | time.sleep(1) 70 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 71 | else: 72 | print("Setting button not found.") 73 | 74 | time.sleep(1) # 每次操作后等待7秒 75 | 76 | for i in range(1): # 重复1次拖动操作 77 | button_pos = detect_button(setting_image_path) 78 | if button_pos: 79 | center_x, center_y = button_pos 80 | # 移动鼠标至 setting 图标中央 81 | pyautogui.moveTo(center_x, center_y) 82 | time.sleep(0.5) # 稍作等待 83 | 84 | # 向左移动400像素,向下移动400像素 85 | pyautogui.move(-500, 630) 86 | time.sleep(1) # 稍作等待 87 | 88 | # 按住左键向上移动100像素后松开 89 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 90 | time.sleep(1) 91 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 92 | time.sleep(1) 93 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 94 | else: 95 | print("Setting button not found.") 96 | 97 | time.sleep(1) # 每次操作后等待7秒 98 | # 主程序 99 | def main(): 100 | current_dir = os.path.dirname(os.path.abspath(__file__)) 101 | start_image_path = os.path.join(current_dir, 'start.png') 102 | confirm_image_path = os.path.join(current_dir, 'confirm.png') 103 | endturn_image_path = os.path.join(current_dir, 'endturn.png') 104 | setting_image_path = os.path.join(current_dir, 'setting.png') # Setting 图标路径 105 | continue_image_path = os.path.join(current_dir, 'continue.png') # Continue 按钮路径 106 | surrender_image_path = os.path.join(current_dir, 'surrender.png') 107 | No_image_path = os.path.join(current_dir, 'No.png') 108 | 109 | 110 | 111 | pyautogui.click() 112 | time.sleep(2) 113 | pyautogui.click() 114 | pyautogui.click() 115 | time.sleep(2) 116 | pyautogui.click() 117 | 118 | # 检测并点击 Start 按钮 119 | detect_and_click_button(No_image_path) 120 | while True: 121 | if detect_and_click_button(start_image_path): 122 | print("Start button clicked, waiting for 10 seconds...") 123 | time.sleep(2) 124 | break 125 | 126 | # 检测并点击 Confirm 按钮 127 | while True: 128 | if detect_and_click_button(confirm_image_path): 129 | print("Confirm button clicked, starting 4-minute countdown...") 130 | break 131 | time.sleep(1) 132 | pyautogui.click() 133 | 134 | # 进入4分钟倒计时 135 | countdown_time = 4 * 65 # 4分钟 136 | start_time = time.time() 137 | 138 | while time.time() - start_time < countdown_time: 139 | print("Checking for Endturn or Continue button...") 140 | 141 | endturn_pos = detect_button(endturn_image_path) 142 | continue_pos = detect_button(continue_image_path) 143 | 144 | if continue_pos: 145 | while True: 146 | if detect_and_click_button(continue_image_path): 147 | time.sleep(3) 148 | detect_and_click_button(continue_image_path) 149 | time.sleep(3) 150 | detect_and_click_button(continue_image_path) 151 | time.sleep(3) 152 | detect_and_click_button(continue_image_path) 153 | time.sleep(3) 154 | detect_and_click_button(continue_image_path) 155 | time.sleep(3) 156 | pyautogui.move(-550, 0) 157 | break 158 | 159 | print("Restarting main process...") 160 | return # 结束当前循环并重新开始程序 161 | 162 | if endturn_pos: 163 | print("Endturn button detected, waiting 5 seconds...") 164 | time.sleep(3) # 探测到endturn按钮后等待5秒 165 | 166 | # 检测setting按钮并执行操作 167 | handle_setting_and_drag(setting_image_path) 168 | 169 | # 等待25秒后点击endturn按钮 170 | print("Waiting 25 seconds before clicking Endturn...") 171 | time.sleep(25) # 等待25秒 172 | 173 | # 点击endturn按钮 174 | detect_and_click_button(endturn_image_path) 175 | print("Endturn button clicked after Setting operations.") 176 | pyautogui.move(-580, 0) 177 | 178 | time.sleep(1) # 每秒检测一次endturn按钮 179 | detect_and_click_button(setting_image_path) 180 | time.sleep(2) # 等待2秒 181 | detect_and_click_button(surrender_image_path) 182 | pyautogui.move(-580, 0) 183 | time.sleep(6) # 等待10秒 184 | while True: 185 | if detect_and_click_button(continue_image_path): 186 | time.sleep(3) 187 | detect_and_click_button(continue_image_path) 188 | time.sleep(3) 189 | detect_and_click_button(continue_image_path) 190 | time.sleep(3) 191 | detect_and_click_button(continue_image_path) 192 | time.sleep(3) 193 | detect_and_click_button(continue_image_path) 194 | time.sleep(3) 195 | pyautogui.move(-550, 0) 196 | break 197 | if __name__ == '__main__': 198 | while True: 199 | main() 200 | 201 | -------------------------------------------------------------------------------- /kards2.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | import cv2 3 | import numpy as np 4 | import time 5 | import os 6 | 7 | # 截图函数,捕捉指定区域的图像 8 | def take_screenshot(region=None): 9 | screenshot = pyautogui.screenshot(region=region) 10 | screenshot = np.array(screenshot) 11 | return cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR) 12 | 13 | # 检测按钮并返回是否找到按钮(不点击) 14 | def detect_button(image_path, threshold=0.8): 15 | screenshot = take_screenshot() 16 | template = cv2.imread(image_path, cv2.IMREAD_COLOR) 17 | result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED) 18 | min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) 19 | 20 | if max_val >= threshold: 21 | button_x, button_y = max_loc 22 | button_w, button_h = template.shape[1], template.shape[0] 23 | center_x, center_y = button_x + button_w // 2, button_y + button_h // 2 24 | print(f"Button detected at ({center_x}, {center_y})") 25 | return (center_x, center_y) 26 | return None 27 | 28 | # 检测按钮并移动鼠标点击 29 | def detect_and_click_button(image_path, threshold=0.8): 30 | button_pos = detect_button(image_path, threshold) 31 | if button_pos: 32 | pyautogui.moveTo(button_pos[0], button_pos[1]) 33 | time.sleep(0.5) # 稍作等待 34 | pyautogui.click() 35 | return True 36 | return False 37 | 38 | # 拖动鼠标操作 39 | def drag_mouse(start_x, start_y, drag_x, drag_y): 40 | pyautogui.moveTo(start_x, start_y) 41 | pyautogui.mouseDown() 42 | pyautogui.move(drag_x, drag_y) # 按住左键并拖动 43 | pyautogui.mouseUp() 44 | 45 | def drag_mouse(start_x, start_y, drag_x, drag_y, duration=0.3): 46 | pyautogui.moveTo(start_x, start_y) 47 | pyautogui.mouseDown() 48 | pyautogui.move(drag_x, drag_y, duration=duration) # 按住左键并拖动,duration 参数控制滑动速度 49 | pyautogui.mouseUp() 50 | 51 | # 检测并处理 Setting 图标操作 52 | def handle_setting_and_drag(setting_image_path): 53 | for i in range(1): # 重复1次拖动操作 54 | button_pos = detect_button(setting_image_path) 55 | if button_pos: 56 | center_x, center_y = button_pos 57 | # 移动鼠标至 setting 图标中央 58 | pyautogui.moveTo(center_x, center_y) 59 | time.sleep(1) # 稍作等待 60 | 61 | # 向左移动400像素,向下移动400像素 62 | pyautogui.move(-580, 630) 63 | time.sleep(1) # 稍作等待 64 | 65 | # 按住左键向上移动100像素后松开 66 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 67 | time.sleep(1) 68 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 69 | time.sleep(1) 70 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 71 | else: 72 | print("Setting button not found.") 73 | 74 | time.sleep(1) # 每次操作后等待7秒 75 | 76 | for i in range(1): # 重复1次拖动操作 77 | button_pos = detect_button(setting_image_path) 78 | if button_pos: 79 | center_x, center_y = button_pos 80 | # 移动鼠标至 setting 图标中央 81 | pyautogui.moveTo(center_x, center_y) 82 | time.sleep(0.5) # 稍作等待 83 | 84 | # 向左移动400像素,向下移动400像素 85 | pyautogui.move(-500, 630) 86 | time.sleep(1) # 稍作等待 87 | 88 | # 按住左键向上移动100像素后松开 89 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 90 | time.sleep(1) 91 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 92 | time.sleep(1) 93 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 94 | else: 95 | print("Setting button not found.") 96 | 97 | time.sleep(1) # 每次操作后等待7秒 98 | # 主程序 99 | def main(): 100 | current_dir = os.path.dirname(os.path.abspath(__file__)) 101 | start_image_path = os.path.join(current_dir, 'start.png') 102 | confirm_image_path = os.path.join(current_dir, 'confirm.png') 103 | endturn_image_path = os.path.join(current_dir, 'endturn.png') 104 | setting_image_path = os.path.join(current_dir, 'setting.png') # Setting 图标路径 105 | continue_image_path = os.path.join(current_dir, 'continue.png') # Continue 按钮路径 106 | surrender_image_path = os.path.join(current_dir, 'surrender.png') 107 | 108 | # 检测并点击 Start 按钮 109 | while True: 110 | if detect_and_click_button(start_image_path): 111 | print("Start button clicked, waiting for 10 seconds...") 112 | time.sleep(2) 113 | break 114 | 115 | # 检测并点击 Confirm 按钮 116 | while True: 117 | if detect_and_click_button(confirm_image_path): 118 | print("Confirm button clicked, starting 4-minute countdown...") 119 | break 120 | time.sleep(1) 121 | pyautogui.click() 122 | 123 | # 进入4分钟倒计时 124 | countdown_time = 4 * 60 # 4分钟 125 | start_time = time.time() 126 | 127 | while time.time() - start_time < countdown_time: 128 | print("Checking for Endturn or Continue button...") 129 | 130 | endturn_pos = detect_button(endturn_image_path) 131 | continue_pos = detect_button(continue_image_path) 132 | 133 | if continue_pos: 134 | while True: 135 | if detect_and_click_button(continue_image_path): 136 | time.sleep(3) 137 | detect_and_click_button(continue_image_path) 138 | time.sleep(3) 139 | detect_and_click_button(continue_image_path) 140 | time.sleep(3) 141 | detect_and_click_button(continue_image_path) 142 | time.sleep(3) 143 | detect_and_click_button(continue_image_path) 144 | time.sleep(3) 145 | break 146 | 147 | print("Restarting main process...") 148 | return # 结束当前循环并重新开始程序 149 | 150 | if endturn_pos: 151 | print("Endturn button detected, waiting 5 seconds...") 152 | time.sleep(3) # 探测到endturn按钮后等待5秒 153 | 154 | for i in range(1): # 重复1次拖动操作 155 | button_pos = detect_button(setting_image_path) 156 | if button_pos: 157 | center_x, center_y = button_pos 158 | # 移动鼠标至 setting 图标中央 159 | pyautogui.moveTo(center_x, center_y) 160 | time.sleep(1) # 稍作等待 161 | 162 | # 向左移动400像素,向下移动400像素 163 | pyautogui.move(-580, 630) 164 | time.sleep(1) # 稍作等待 165 | 166 | # 按住左键向上移动100像素后松开 167 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 168 | time.sleep(1) 169 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 170 | time.sleep(1) 171 | drag_mouse(pyautogui.position()[0], pyautogui.position()[1], 0, -165) 172 | else: 173 | print("Setting button not found.") 174 | 175 | time.sleep(1) # 每次操作后等待7秒 176 | 177 | # 等待25秒后点击endturn按钮 178 | print("Waiting 25 seconds before clicking Endturn...") 179 | time.sleep(30) # 等待25秒 180 | 181 | # 点击endturn按钮 182 | detect_and_click_button(endturn_image_path) 183 | print("Endturn button clicked after Setting operations.") 184 | 185 | time.sleep(1) # 每秒检测一次endturn按钮 186 | detect_and_click_button(setting_image_path) 187 | time.sleep(2) # 等待2秒 188 | detect_and_click_button(surrender_image_path) 189 | pyautogui.move(-580, 0) 190 | time.sleep(6) # 等待10秒 191 | while True: 192 | if detect_and_click_button(continue_image_path): 193 | time.sleep(3) 194 | detect_and_click_button(continue_image_path) 195 | time.sleep(3) 196 | detect_and_click_button(continue_image_path) 197 | time.sleep(3) 198 | detect_and_click_button(continue_image_path) 199 | time.sleep(3) 200 | detect_and_click_button(continue_image_path) 201 | time.sleep(3) 202 | break 203 | if __name__ == '__main__': 204 | while True: 205 | main() 206 | 207 | --------------------------------------------------------------------------------