Autoscout
This commit is contained in:
@@ -14,4 +14,11 @@ def order_peasants(number):
|
||||
def select_town_center():
|
||||
pyautogui.press('h')
|
||||
time.sleep(WAIT4CLICK)
|
||||
|
||||
|
||||
def follow_points(points):
|
||||
pyautogui.keyDown('shift')
|
||||
for x,y in points:
|
||||
pyautogui.rightClick(x,y)
|
||||
time.sleep(WAIT4CLICK)
|
||||
pyautogui.keyUp('shift')
|
||||
pyautogui.move(-500, -500) # reset mouse
|
||||
@@ -8,6 +8,7 @@ import time
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
import aoe_commands
|
||||
DELTA = 1
|
||||
|
||||
def wait_for_start():
|
||||
start_started = False
|
||||
@@ -23,6 +24,75 @@ def wait_for_start():
|
||||
print("Startscreen not found")
|
||||
time.sleep(0.5)
|
||||
|
||||
def find_top(image,x,y,classifyer):
|
||||
left = (x,y)
|
||||
print(f"xy: {x},{y}")
|
||||
loop = True
|
||||
while loop:
|
||||
nxt = left[0], left[1] - 1
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = left[0] - DELTA, left[1] -1
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = left[0] + DELTA, left[1] -1
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
break
|
||||
left = nxt
|
||||
return left[1]
|
||||
|
||||
def find_bottom(image,x,y,classifyer):
|
||||
right = (x,y)
|
||||
loop = True
|
||||
while loop:
|
||||
nxt = right[0], right[1] + 1
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = right[0] - DELTA, right[1] + 1
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = right[0] + DELTA, right[1] + 1
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
break
|
||||
right = nxt
|
||||
return right[1]
|
||||
|
||||
def find_left(image, x, y, classifyer):
|
||||
top = (x,y)
|
||||
loop = True
|
||||
while loop:
|
||||
nxt = top[0] - 1, top[1]
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = top[0] - 1, top[1] - DELTA
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = top[0] - 1, top[1] + DELTA
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
break
|
||||
top = nxt
|
||||
return top[0]
|
||||
|
||||
def find_right(image, x, y, classifyer):
|
||||
bottom = (x,y)
|
||||
loop = True
|
||||
while loop:
|
||||
nxt = bottom[0] + 1, bottom[1]
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = bottom[0] + 1, bottom[1] - DELTA
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
nxt = bottom[0] + 1, bottom[1] + DELTA
|
||||
rr,gg,bb = image.getpixel(nxt)
|
||||
if not classifyer(rr,gg,bb):
|
||||
break
|
||||
bottom = nxt
|
||||
return bottom[0]
|
||||
|
||||
def collect_screenshots():
|
||||
cnt = 0
|
||||
while True: #keyboard.is_pressed('q') == False:
|
||||
@@ -31,6 +101,85 @@ def collect_screenshots():
|
||||
pic.save(f"image_{cnt}.png")
|
||||
cnt += 1
|
||||
|
||||
def initial_scout_trace():
|
||||
def find_town_center_in_map():
|
||||
aoe_commands.select_town_center()
|
||||
# TODO
|
||||
image = pyautogui.screenshot()
|
||||
# Map: 1546 886 - 1920 1080
|
||||
width, height = image.size
|
||||
is_white = lambda r,g,b: r == 255 and b == 255 and g == 255
|
||||
for x in range(1546, width, 3):
|
||||
for y in range(886, height, 3):
|
||||
r,g,b = image.getpixel((x,y))
|
||||
if is_white(r,g,b):
|
||||
top = find_top(image, x, y, is_white)
|
||||
bottom = find_bottom(image, x, y, is_white)
|
||||
left = find_left(image, x, y, is_white)
|
||||
right = find_right(image, x, y, is_white)
|
||||
print(f"Found white pixel ({x}/{y}) --> ({left}, {top}),({right}, {bottom})")
|
||||
if bottom - top == right - left: # viereckig in der Karte
|
||||
print (f"found town center in map: {left}/{top}")
|
||||
return (left + 1, top + 1)
|
||||
return (0,0)
|
||||
|
||||
def initial_scout_trace():
|
||||
walk_further_out = 3
|
||||
outer_circle = [(1730, 1072), (1570,986),(1730, 898), (1890, 984), (1730, 1072)]
|
||||
mid_circle = [(1730, 1047), (1610,986),(1730, 920), (1840, 984), (1730, 1035)]
|
||||
inner_circle = [(1730, 1020), (1650, 980), (1730, 940), (1790, 980), (1730, 1000) ]
|
||||
center = [(1730, 980)]
|
||||
x, y = find_town_center_in_map()
|
||||
time.sleep(0.3)
|
||||
not_black = lambda r,g,b: r > 1 or b > 1 or g > 1
|
||||
image = pyautogui.screenshot()
|
||||
lx = find_left(image, x, y, not_black)
|
||||
rx = find_right(image, x, y, not_black)
|
||||
|
||||
ty = find_top(image, x, y, not_black)
|
||||
by = find_bottom(image, x, y, not_black)
|
||||
print(f"Town center x: {x}, y:{y} gave us minimal and maximal x values to watch: lx: {lx}, rx={rx}")
|
||||
scout_trace = []
|
||||
delta = 4
|
||||
for yy in range(by, ty, -5):
|
||||
xx = find_left(image, x, yy, not_black) - delta
|
||||
scout_trace.append((xx,yy))
|
||||
for xx in range(lx, rx, 5):
|
||||
yy = find_top(image, xx, y, not_black) - delta
|
||||
scout_trace.append((xx,yy))
|
||||
for yy in range(ty, by, 5):
|
||||
xx = find_right(image, x, yy, not_black) + delta
|
||||
scout_trace.append((xx,yy))
|
||||
for xx in range(rx, lx, -5):
|
||||
yy = find_bottom(image, xx, y, not_black) + delta
|
||||
scout_trace.append((xx,yy))
|
||||
|
||||
delta = 12
|
||||
for yy in range(by, ty, -5):
|
||||
xx = find_left(image, x, yy, not_black) - delta
|
||||
scout_trace.append((xx,yy))
|
||||
for xx in range(lx, rx, 5):
|
||||
yy = find_top(image, xx, y, not_black) - delta
|
||||
scout_trace.append((xx,yy))
|
||||
for yy in range(ty, by, 5):
|
||||
xx = find_right(image, x, yy, not_black) + delta
|
||||
scout_trace.append((xx,yy))
|
||||
for xx in range(rx, lx, -5):
|
||||
yy = find_bottom(image, xx, y, not_black) + delta
|
||||
scout_trace.append((xx,yy))
|
||||
|
||||
delta = 20
|
||||
for yy in range(by, ty, -5):
|
||||
xx = find_left(image, x, yy, not_black) - delta
|
||||
scout_trace.append((xx,yy))
|
||||
for xx in range(lx, rx, 5):
|
||||
yy = find_top(image, xx, y, not_black) - delta
|
||||
scout_trace.append((xx,yy))
|
||||
for yy in range(ty, by, 5):
|
||||
xx = find_right(image, x, yy, not_black) + delta
|
||||
scout_trace.append((xx,yy))
|
||||
for xx in range(rx, lx, -5):
|
||||
yy = find_bottom(image, xx, y, not_black) + delta
|
||||
scout_trace.append((xx,yy))
|
||||
|
||||
print(f"scout_trace: {scout_trace}")
|
||||
return scout_trace + center + inner_circle + mid_circle + outer_circle
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import keyboard
|
||||
WAIT4CLICK = 0.04
|
||||
|
||||
import aoe_commands
|
||||
import aoe_recognition
|
||||
|
||||
def assign_hotkeys():
|
||||
pyautogui.press(',')
|
||||
@@ -61,5 +62,8 @@ def run_start_routine():
|
||||
aoe_commands.order_peasants(4)
|
||||
assign_hotkeys()
|
||||
build_houses()
|
||||
xxa = aoe_recognition.initial_scout_trace()
|
||||
pyautogui.press('1')
|
||||
pyautogui.press('1')
|
||||
pyautogui.press('1')
|
||||
aoe_commands.follow_points(xxa)
|
||||
pyautogui.press('h')
|
||||
Reference in New Issue
Block a user