This article mainly introduces Python's Automatic Mine Clearance implementation method, provides Python's code ideas for implementing automatic mine clearance, and provides notes for reference, for more information about how to implement Python Automatic Mine Clearance, see the example in this article. Share it with you for your reference. The details are as follows:
# PyWinmineCrack. py # coding: utf-8import win32guiimport win32processimport win32conimport win32apifrom ctypes import * # maximum number of columns in the minefield MAX_ROWS = 24MAX_COLUMNS = 30 # Start coordinate of the minefield grid on the form and MINE_BEGIN_X = border 0x10 # frame, mine-free, and mine-protected internal representation MINE_BOARDER = 0x10MINE_SAFE = 0x0FMINE_DANGER = 0x8F # storage address BOARD_ADDR = 0x1005340class SMineCtrl (Structure) in the Mine Clearance Program): _ fields _ = [("HWnd", c_uint), ("board", (c_byte * (MAX_COLUMNS + 2) * (MAX_ROWS + 2), ("rows", c_byte ), ("columns", c_byte)] kernel32 = windll. loadLibrary ("kernel32.dll") ReadProcessMemory = kernel = kernel32.WriteProcessMemoryOpenProcess = kernel32.OpenProcessctrlData = SMineCtrl () # Find the clearance program and open the corresponding process try: ctrlData. hWnd = win32gui. findWindow ("mine clearance", "mine clearance") handle T: win32api. mess AgeBox (0, "run the Mine Clearance program first", "error! ", Win32con. MB_ICONERROR) exit (0) hreadID, processID = win32process. getWindowThreadProcessId (ctrlData. hWnd) hProc = OpenProcess (win32con. PROCESS_ALL_ACCESS, 0, processID) # Read bytesRead = c_ulong (0) ReadProcessMemory (hProc, BOARD_ADDR, byref (ctrlData. board), SMineCtrl. board. size, byref (bytesRead) if (bytesRead. value! = SMineCtrl. board. size): str = "ReadProcessMemory error, only read", bytesRead. value, "shocould read", SMineCtrl. board. size win32api. messageBox (0, str, "error! ", Win32con. MB_ICONERROR) exit () # obtain the actual size of the minefield in this project ctrlData. rows = 0ctrlData. columns = 0for I in range (0, MAX_COLUMNS + 2): if MINE_BOARDER = ctrlData. board [0]: ctrlData. columns + = 1 else: breakctrlData. columns-= 2 for I in range (1, MAX_ROWS + 1): if MINE_BOARDER! = CtrlData. board [1]: ctrlData. rows + = 1 else: break # simulate the mouse clicking action for I in range (0, ctrlData. rows): for j in range (0, ctrlData. columns): if MINE_SAFE = ctrlData. board [I + 1] [j + 1]: win32api. sendMessage (ctrlData. hWnd, win32con. WM_LBUTTONDOWN, win32con. MK_LBUTTON, win32api. MAKELONG (MINE_BEGIN_X + MINE_GRID_WIDTH * j + MINE_GRID_WIDTH/2, MINE_BEGIN_Y + MINE_GRID_HEIGHT * I + MINE_GRID_HEIGHT/2) win32a Pi. sendMessage (ctrlData. hWnd, win32con. WM_LBUTTONUP, win32con. MK_LBUTTON, win32api. MAKELONG (MINE_BEGIN_X + MINE_GRID_WIDTH * j + MINE_GRID_WIDTH/2, MINE_BEGIN_Y + MINE_GRID_HEIGHT * I + MINE_GRID_HEIGHT/2) # Get it done! Win32api. MessageBox (0, "done! "," Information ", win32con. MB_ICONINFORMATION)
I hope this article will help you with Python programming.