You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import cv2
  2. import time, random
  3. import pyautogui
  4. from datetime import datetime, date
  5. print(f"Hello")
  6. def find_image(image, coef=None):
  7. print(f"\n[find_image] {image}")
  8. template = cv2.imread("assets/{}".format(image), 0)
  9. width, height = template.shape[::-1]
  10. screen = cv2.imread("screenshot.png", 0)
  11. width2, height2 = screen.shape[::-1]
  12. match = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
  13. value, location = cv2.minMaxLoc(match)[1], cv2.minMaxLoc(match)[3]
  14. print(f"Value for {image}: {value}")
  15. if (value >= 0.8):
  16. return (location[0], location[1], width, height, value)
  17. else:
  18. print("Error while searching for image")
  19. return None
  20. def sleeper():
  21. # Random Time
  22. time.sleep(random.choices(population=[int(1),int(2),int(3),int(4),int(5),int(6),int(7),int(8)],
  23. weights=[0.03, 0.07, 0.1, 0.3, 0.3, 0.1, 0.07, 0.03])[0])
  24. return
  25. def loose_loop(loose_rounds):
  26. sleeper()
  27. pyautogui.screenshot("screenshot.png")
  28. v_options = False
  29. v_surrender = False
  30. v_ok = False
  31. v_continue = False
  32. v_ready = False
  33. loose_rounds += 1
  34. print(loose_rounds)
  35. # Options
  36. v_options_counter = 0
  37. while v_options == False:
  38. sleeper()
  39. pyautogui.screenshot("screenshot.png")
  40. options = find_image("options.png")
  41. if options != None:
  42. v_options = True
  43. pyautogui.click((options[0], options[1]))
  44. elif v_options_counter >= 10:
  45. v_options = True
  46. print(f"Skip options")
  47. else:
  48. print(f"Zahnräder nicht gefunden")
  49. sleeper()
  50. # Surrender
  51. v_surrender_counter = 0
  52. while v_surrender == False:
  53. sleeper()
  54. pyautogui.screenshot("screenshot.png")
  55. surrender = find_image("surrender.png")
  56. if surrender != None:
  57. v_surrender = True
  58. pyautogui.click((surrender[0], surrender[1]))
  59. elif v_surrender_counter >= 10:
  60. v_surrender = True
  61. print(f"Skip options")
  62. else:
  63. print(f"Surrender nicht gefunden")
  64. sleeper()
  65. # OK
  66. v_ok_counter = 0
  67. while v_ok == False:
  68. sleeper()
  69. pyautogui.screenshot("screenshot.png")
  70. ok = find_image("ok.png")
  71. if ok != None:
  72. v_ok = True
  73. pyautogui.click((ok[0], ok[1]))
  74. elif v_ok_counter >= 10:
  75. v_ok = True
  76. print(f"Skip options")
  77. else:
  78. print(f"OK nicht gefunden")
  79. sleeper()
  80. # Continue
  81. v_continue_counter = 0
  82. while v_continue == False:
  83. sleeper()
  84. pyautogui.screenshot("screenshot.png")
  85. f_continue = find_image("continue.png")
  86. if f_continue != None:
  87. v_continue = True
  88. pyautogui.click((f_continue[0], f_continue[1]))
  89. elif v_continue_counter >= 10:
  90. v_continue = True
  91. print(f"Skip options")
  92. else:
  93. print(f"Continue nicht gefunden")
  94. sleeper()
  95. # Ready
  96. v_ready_counter = 0
  97. while v_ready == False:
  98. sleeper()
  99. pyautogui.screenshot("screenshot.png")
  100. ready = find_image("ready.png")
  101. if ready != None:
  102. v_ready = True
  103. pyautogui.click((ready[0], ready[1]))
  104. elif v_ready_counter >= 10:
  105. v_ready = True
  106. print(f"Skip options")
  107. else:
  108. print(f"Ready nicht gefunden")
  109. sleeper()
  110. print(f"\n\n Loop complete restarting \nRunde {loose_rounds} absolviert\n\n")
  111. if loose_rounds >= 30:
  112. print(f"{loose_rounds} Spiele absolviert\nWechsle Modus")
  113. def win_loop(win_rounds):
  114. time.sleep(1)
  115. while win_rounds <= 31:
  116. time.sleep(1)
  117. pyautogui.screenshot("screenshot.png")
  118. f_continue = find_image("continue.png")
  119. f_ready = find_image("ready.png")
  120. if f_continue != None:
  121. pyautogui.click((f_continue[0], f_continue[1]))
  122. elif f_ready != None:
  123. pyautogui.click((f_ready[0], f_ready[1]))
  124. print(f"Siege: {win_rounds}")
  125. else:
  126. print(f"Kein Ergebniss gefunden")
  127. time.sleep(1)
  128. # Niederlage
  129. loose_rounds = 0
  130. while loose_rounds <= 3:
  131. loose_loop(loose_rounds)
  132. loose_rounds += 1
  133. # Siege
  134. win_rounds = 0
  135. while win_rounds <= 3:
  136. print("winorund loop")
  137. win_loop(win_rounds)
  138. win_rounds += 1