2 İşlemeler 8422efeb58 ... 90791bab75

Yazar SHA1 Mesaj Tarih
  Richard Köhl 90791bab75 slightly randomize taps and sleep times 1 yıl önce
  Richard Köhl 53dc0e28a6 update .env.example 1 yıl önce
2 değiştirilmiş dosya ile 27 ekleme ve 11 silme
  1. 5 0
      .env.example
  2. 22 11
      dungeon.py

+ 5 - 0
.env.example

@@ -1,3 +1,8 @@
 ANDROID_ADDRESS=192.168.178.32:5555
 SCREENSHOT_PATH=Test
 RAMDRIVE_PATH=
+
+# dungeon settings
+FIRE_VS_EARTH=earth
+SWAP_TANK_AT_LOW_HEALTH=true
+FIRST_DEATH_STOP=true

+ 22 - 11
dungeon.py

@@ -2,6 +2,7 @@ import cv2
 import os
 import time
 import numpy as np
+import random
 from helper import (
     tap as tap_helper,
     look_for_templates,
@@ -10,7 +11,11 @@ from helper import (
     get_current_screen,
 )
 
-fire_vs_earth = os.getenv("FIRE_VS_EARTH", "earth").lower()
+fire_or_earth = os.getenv("FIRE_OR_EARTH", "earth").lower()
+stop_at_first_death = os.getenv("FIRST_DEATH_STOP", "False").lower() == "true"
+swap_tank_at_low_health = (
+    os.getenv("SWAP_TANK_AT_LOW_HEALTH", "False").lower() == "true"
+)
 
 # templates
 templates = {
@@ -56,7 +61,7 @@ def low_health(element, name):
 
     print(f"Remaining Health ({name}): {health_percentage:.2f}%")
 
-    return health_percentage < 60
+    return health_percentage < 70
 
 
 def read_screen():
@@ -68,22 +73,23 @@ def read_screen():
 
 def tap(name, x, y=None):
     sleep = 0.5
-    if name in ["ok"]:
+    if name in ["ok", "lock"]:
         sleep = 2
     elif name in ["collect"]:
         sleep = 5
-    elif name in ["lock"]:
-        sleep = 2
     elif name in ["remove angus", "remove moloch"]:
         sleep = 1
 
+    sleep += random.uniform(0, 0.2)
     text = f"- {name} (pause for {sleep}s)"
-    tap_helper(x, y, text)
+
+    tap_helper(x + random.randint(-3, 3), y + random.randint(-3, 3), text)
     time.sleep(sleep)
 
 
 print("watching the screen...")
 is_mixed = False
+idle_counter = 0
 while True:
     try:
         capture_current_screen()
@@ -92,15 +98,14 @@ while True:
         if name is not None:
             if name in ["to_battle", "ok", "lock", "collect"]:
                 tap(name, *locations[0])
+                idle_counter = 0
                 continue
             if name in ["auto_battle"]:
-                dead = os.getenv(
-                    "STOP_AT_FIRST_DEATH", "False"
-                ).lower() == "true" and first_template(tpl_dead)
+                dead = stop_at_first_death and first_template(tpl_dead)
                 if dead:
                     print("++++++++ at least one titan is dead. stopping")
                     break
-                if is_mixed:
+                if swap_tank_at_low_health and is_mixed:
                     moloch = first_template(tpl_moloch)
                     if (
                         moloch
@@ -135,6 +140,7 @@ while True:
                                 )
                                 break
                 tap(name, *locations[0])
+                idle_counter = 0
                 continue
             if name == "attack":
                 if len(locations) == 1:
@@ -151,13 +157,18 @@ while True:
                         is_mixed = False
                         element = first_template(tpl_water)
                         if element is None:
-                            if fire_vs_earth == "earth":
+                            if fire_or_earth == "earth":
                                 element = first_template(tpl_earth)
                             else:
                                 element = first_template(tpl_fire)
 
                     tap(name, element[0], locations[0][1])
+                    idle_counter = 0
                     continue
         print("...")
+        idle_counter += 1
+        if idle_counter >= 3:
+            print("######### stopping due to three idle loop iterations.")
+            break
     except Exception as e:
         print(f"error: {e}")