-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
51 lines (38 loc) · 1.52 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pyautogui
from PIL import Image
import pygetwindow as gw
def capture_minesweeper_map():
# Adjust the coordinates based on your screen resolution and Minesweeper position
top_left_x, top_left_y = 121,226
bottom_right_x, bottom_right_y = 297, 401
screenshot = pyautogui.screenshot(region=(top_left_x, top_left_y, bottom_right_x - top_left_x, bottom_right_y - top_left_y))
return screenshot
def process_minesweeper_map(screenshot):
image_data = screenshot.load()
width, height = screenshot.size
minesweeper_map = []
for y in range(height):
row = []
for x in range(width):
pixel = image_data[x, y]
# You may need to adjust these color values based on your Minesweeper theme
if pixel == (255, 255, 255): # Unopened box
row.append('U')
elif pixel == (192, 192, 192): # Opened box
row.append('O')
elif pixel == (0, 0, 255): # Mine
row.append('M')
else:
# Extract the number from the color or use a different marker for numbers
row.append('N')
minesweeper_map.append(row)
return minesweeper_map
def main():
mine_window = gw.getWindowsWithTitle('Minesweeper')
mine_window[0].activate()
minesweeper_screenshot = capture_minesweeper_map()
minesweeper_map = process_minesweeper_map(minesweeper_screenshot)
for row in minesweeper_map:
print(' '.join(row))
if __name__ == "__main__":
main()