| 
					
				 | 
			
			
				@@ -5,10 +5,12 @@ from time import sleep, time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import pyautogui as gui 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import sched 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cv2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from collections import namedtuple 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 cv2.namedWindow('View', cv2.WINDOW_NORMAL) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 DEFAULT_MONITOR = 3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+DEBUG = True 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 scheduler = sched.scheduler(time, sleep) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -49,7 +51,7 @@ def open_dino(sct): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def short_jump(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     with gui.hold('space'): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sleep(0.05) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sleep(0.07) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def long_jump(): 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -57,6 +59,11 @@ def long_jump(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sleep(0.2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def take_down(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    with gui.hold('down'): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sleep(0.05) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def get_playing_bbox(sct): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Screen = take_screenshot(sct) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     binaryScreen = np.zeros(Screen.shape[:-1]) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -73,6 +80,7 @@ def get_playing_bbox(sct): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def to_bbox(bin_image): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    bin_image = cv2.dilate(bin_image, None, iterations=2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     labels, labeledScreen = cv2.connectedComponents(bin_image.astype('uint8')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for label in range(1, labels): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         x,y = np.where(labeledScreen==label) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -96,23 +104,35 @@ if __name__ == '__main__': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     binScreen = take_binaryScreenshot(sct, playing_bbox) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     binScreen = to_bbox(binScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     labels, labeledScreen = cv2.connectedComponents(binScreen.astype('uint8')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    rgbScreen = binary_to_RGB(binScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    dino = min(range(1,labels), key=lambda x: np.where(labeledScreen==x)[1].min()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    dino_pos = np.where(labeledScreen == dino)[1].max() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    rgbScreen[labeledScreen==dino] = (0, 255, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if DEBUG: rgbScreen = binary_to_RGB(binScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    dino = min(range(1,labels), key=lambda x: np.where(labeledScreen==x)[1].min())  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    dino_pos = np.where(labeledScreen == dino)[1].max() + 5*mw 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    jump_zone = dino_pos + 13*mw 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if DEBUG: rgbScreen[labeledScreen==dino] = (0, 255, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    start = time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     while cv2.waitKey(1) != ord('q'): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         binScreen = take_binaryScreenshot(sct, playing_bbox) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         binScreen = to_bbox(binScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         labels, labeledScreen = cv2.connectedComponents(binScreen.astype('uint8')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        rgbScreen = binary_to_RGB(binScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if DEBUG: rgbScreen = binary_to_RGB(binScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for label in range(1, labels): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             pos = np.where(labeledScreen == label) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if pos[1].max() > dino_pos and (pos[1].max()-pos[1].min()) > mw: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                rgbScreen[labeledScreen == label] = (0, 0, 255) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            else: rgbScreen[labeledScreen == label] = (0, 255, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if pos[1].max() < dino_pos: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if DEBUG: rgbScreen[pos] = (0, 255, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif pos[1].max() < jump_zone + max(1*(pos[0].max() - pos[0].min()), 1*(pos[1].max() - pos[1].min())) and (pos[1].max() - pos[1].min()) > mw : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                # Ближайший Противник                        
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if DEBUG: rgbScreen[pos] = (0, 0, 255) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (pos[1].max() - pos[1].min()) > 8*mw: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    long_jump() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                else: short_jump() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if time() - start > 10:  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            jump_zone += mw 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            start = time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         cv2.imshow('View', rgbScreen) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        cv2.waitKey(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     cv2.destroyAllWindows() 
			 |