123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import cv2
- import time, random
- import pyautogui
- from datetime import datetime, date
-
- print(f"Hello")
-
- def find_image(image, coef=None):
- print(f"\n[find_image] {image}")
- template = cv2.imread("assets/{}".format(image), 0)
- width, height = template.shape[::-1]
- screen = cv2.imread("screenshot.png", 0)
- width2, height2 = screen.shape[::-1]
- match = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
- value, location = cv2.minMaxLoc(match)[1], cv2.minMaxLoc(match)[3]
- print(f"Value for {image}: {value}")
- if (value >= 0.8):
- return (location[0], location[1], width, height, value)
- else:
- print("Error while searching for image")
- return None
-
- def sleeper():
- # Random Time
- time.sleep(random.choices(population=[int(1),int(2),int(3),int(4),int(5),int(6),int(7),int(8)],
- weights=[0.03, 0.07, 0.1, 0.3, 0.3, 0.1, 0.07, 0.03])[0])
- return
-
-
- def loose_loop(loose_rounds):
- sleeper()
- pyautogui.screenshot("screenshot.png")
-
- v_options = False
- v_surrender = False
- v_ok = False
- v_continue = False
- v_ready = False
-
- loose_rounds += 1
- print(loose_rounds)
-
- # Options
-
- v_options_counter = 0
- while v_options == False:
- sleeper()
- pyautogui.screenshot("screenshot.png")
- options = find_image("options.png")
- if options != None:
- v_options = True
- pyautogui.click((options[0], options[1]))
- elif v_options_counter >= 10:
- v_options = True
- print(f"Skip options")
- else:
- print(f"Zahnräder nicht gefunden")
- sleeper()
-
- # Surrender
-
- v_surrender_counter = 0
- while v_surrender == False:
- sleeper()
- pyautogui.screenshot("screenshot.png")
- surrender = find_image("surrender.png")
- if surrender != None:
- v_surrender = True
- pyautogui.click((surrender[0], surrender[1]))
- elif v_surrender_counter >= 10:
- v_surrender = True
- print(f"Skip options")
- else:
- print(f"Surrender nicht gefunden")
- sleeper()
-
- # OK
-
- v_ok_counter = 0
- while v_ok == False:
- sleeper()
- pyautogui.screenshot("screenshot.png")
- ok = find_image("ok.png")
- if ok != None:
- v_ok = True
- pyautogui.click((ok[0], ok[1]))
- elif v_ok_counter >= 10:
- v_ok = True
- print(f"Skip options")
- else:
- print(f"OK nicht gefunden")
- sleeper()
-
- # Continue
-
- v_continue_counter = 0
- while v_continue == False:
- sleeper()
- pyautogui.screenshot("screenshot.png")
- f_continue = find_image("continue.png")
- if f_continue != None:
- v_continue = True
- pyautogui.click((f_continue[0], f_continue[1]))
- elif v_continue_counter >= 10:
- v_continue = True
- print(f"Skip options")
- else:
- print(f"Continue nicht gefunden")
- sleeper()
-
- # Ready
-
- v_ready_counter = 0
- while v_ready == False:
- sleeper()
- pyautogui.screenshot("screenshot.png")
- ready = find_image("ready.png")
- if ready != None:
- v_ready = True
- pyautogui.click((ready[0], ready[1]))
- elif v_ready_counter >= 10:
- v_ready = True
- print(f"Skip options")
- else:
- print(f"Ready nicht gefunden")
- sleeper()
-
- print(f"\n\n Loop complete restarting \nRunde {loose_rounds} absolviert\n\n")
-
- if loose_rounds >= 30:
- print(f"{loose_rounds} Spiele absolviert\nWechsle Modus")
-
-
- def win_loop(win_rounds):
- time.sleep(1)
-
- while win_rounds <= 31:
- time.sleep(1)
- pyautogui.screenshot("screenshot.png")
- f_continue = find_image("continue.png")
- f_ready = find_image("ready.png")
- if f_continue != None:
- pyautogui.click((f_continue[0], f_continue[1]))
- elif f_ready != None:
- pyautogui.click((f_ready[0], f_ready[1]))
- print(f"Siege: {win_rounds}")
- else:
- print(f"Kein Ergebniss gefunden")
- time.sleep(1)
-
-
- # Niederlage
- loose_rounds = 0
- while loose_rounds <= 3:
- loose_loop(loose_rounds)
- loose_rounds += 1
-
- # Siege
- win_rounds = 0
- while win_rounds <= 3:
- print("winorund loop")
- win_loop(win_rounds)
- win_rounds += 1
|