Fishing agent first draft
|
Before Width: | Height: | Size: 8.9 MiB After Width: | Height: | Size: 8.1 MiB |
BIN
assets/fishing/Bobber.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
|
|
@ -6,29 +6,19 @@ import time
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyautogui
|
import pyautogui
|
||||||
|
from core.Logger import Logger
|
||||||
|
|
||||||
class FishingAgent:
|
class FishingAgent:
|
||||||
def __init__(self, mainAgent) -> None:
|
def __init__(self, monitor) -> None:
|
||||||
self.mainAgent = mainAgent
|
self.logger = Logger("Fishing Agent")
|
||||||
|
self.monitor = monitor
|
||||||
# interpolate here_path to get the path to the fishing target image
|
|
||||||
assetPath = os.path.join(
|
assetPath = os.path.join(
|
||||||
os.path.dirname(os.path.realpath(__file__)),
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
"assets"
|
"..\\..\\assets"
|
||||||
)
|
)
|
||||||
assetPath = os.path.dirname(os.path.realpath(__file__))
|
self.fishingBobberImg = cv.imread(os.path.join(assetPath,"fishing","Bobber.png"), cv.IMREAD_GRAYSCALE)
|
||||||
print(assetPath)
|
|
||||||
self.fishingBobber = cv.imread(
|
|
||||||
os.path.join(
|
|
||||||
assetPath,
|
|
||||||
"assets", "Bobber.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.fishingThread = None
|
self.fishingThread = None
|
||||||
|
|
||||||
def agentLog(self, log: str):
|
|
||||||
print("Fishing Agent: " + log)
|
|
||||||
|
|
||||||
def castLure(self):
|
def castLure(self):
|
||||||
self.agentLog("Casting Lure.")
|
self.agentLog("Casting Lure.")
|
||||||
# pyautogui.press('1')
|
# pyautogui.press('1')
|
||||||
|
|
@ -59,11 +49,17 @@ class FishingAgent:
|
||||||
def pullLine(self):
|
def pullLine(self):
|
||||||
self.agentLog("Pulling line!")
|
self.agentLog("Pulling line!")
|
||||||
|
|
||||||
|
def test(self):
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
self.logger.log("###")
|
||||||
|
self.monitor.findMatch(self.fishingBobberImg)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.mainAgent.currImg is None:
|
if self.monitor.screenshot is None:
|
||||||
print("Image capture not found! Did you start the screen capture thread?")
|
self.logger.log("Screenshot capture not found...")
|
||||||
return
|
return
|
||||||
print("Starting fishing thread in 10 seconds...")
|
self.logger.log("Starting fishing thread in 3 seconds...")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
# print("Switching to fishing hotbar (hotbar 4)")
|
# print("Switching to fishing hotbar (hotbar 4)")
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 1010 B |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.2 MiB |
|
Before Width: | Height: | Size: 4.0 MiB |
|
Before Width: | Height: | Size: 4.9 MiB |
9
core/Logger.py
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import datetime;
|
||||||
|
|
||||||
|
class Logger:
|
||||||
|
def __init__(self, name = "Logger") -> None:
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def log(self, message):
|
||||||
|
ct = datetime.datetime.now()
|
||||||
|
print(ct.strftime("%m/%d/%Y-%H:%M:%S:"), self.name, ">>", message)
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
from threading import Thread
|
|
||||||
from core.Monitor import Monitor
|
from core.Monitor import Monitor
|
||||||
|
from bots.fishing.FishingAgent import FishingAgent
|
||||||
|
|
||||||
class MainAgent:
|
class MainAgent:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.monitor = Monitor()
|
self.monitor = Monitor()
|
||||||
self.screenThread = None
|
self.fishingBot = FishingAgent(self.monitor)
|
||||||
|
|
||||||
def startScreenCaptureThread(self):
|
def startFishBot(self):
|
||||||
self.screenThread = Thread(target=self.monitor.updateScreen, args=(self,), name="Update screen thread", daemon=True)
|
self.monitor.startScreenCaptureThread()
|
||||||
self.screenThread.start()
|
self.fishingBot.test()
|
||||||
print("Main Agent: Thread started")
|
|
||||||
|
|
||||||
def stopScreenCaptureThread(self):
|
|
||||||
if (self.screenThread):
|
|
||||||
self.screenThread.terminate()
|
|
||||||
print("Main Agent: Thread terminated")
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,22 @@
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
from threading import Thread
|
||||||
|
from screeninfo import get_monitors
|
||||||
import pyautogui
|
import pyautogui
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
from screeninfo import get_monitors
|
from matplotlib import pyplot as plt
|
||||||
|
from core.Logger import Logger
|
||||||
|
|
||||||
FPS_REPORT_DELAY = 3
|
FPS_REPORT_DELAY = 3
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.logger = Logger("Monitor")
|
||||||
self.monitor = None
|
self.monitor = None
|
||||||
|
self.screenThread = None
|
||||||
self.screenshot = None
|
self.screenshot = None
|
||||||
|
self.fps = None
|
||||||
self.getMonitor()
|
self.getMonitor()
|
||||||
|
|
||||||
def getMonitor(self):
|
def getMonitor(self):
|
||||||
|
|
@ -18,8 +25,8 @@ class Monitor:
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
|
|
||||||
def updateScreen(self):
|
def updateScreen(self):
|
||||||
print("Starting computer vision screen update...")
|
self.logger.log("Monitor: Starting computer vision screen update...")
|
||||||
print("Detected display resolution: " + str(self.monitor.width) + " x " + str(self.monitor.height))
|
self.logger.log("Monitor: Detected display resolution: " + str(self.monitor.width) + " x " + str(self.monitor.height))
|
||||||
|
|
||||||
loopTime = time.time()
|
loopTime = time.time()
|
||||||
fpsPrintTime = time.time()
|
fpsPrintTime = time.time()
|
||||||
|
|
@ -32,8 +39,50 @@ class Monitor:
|
||||||
|
|
||||||
currTime = time.time()
|
currTime = time.time()
|
||||||
if currTime - fpsPrintTime >= FPS_REPORT_DELAY:
|
if currTime - fpsPrintTime >= FPS_REPORT_DELAY:
|
||||||
print('FPS: {}'.format(1 / (currTime - loopTime)))
|
self.fps = 1 / (currTime - loopTime)
|
||||||
fpsPrintTime = currTime
|
fpsPrintTime = currTime
|
||||||
loopTime = currTime
|
loopTime = currTime
|
||||||
|
|
||||||
|
def startScreenCaptureThread(self):
|
||||||
|
self.screenThread = Thread(target=self.updateScreen, name="Update screen thread", daemon=True)
|
||||||
|
self.screenThread.start()
|
||||||
|
self.logger.log("Main Agent: Thread started")
|
||||||
|
|
||||||
|
def findMatch(self, img, method = "TM_CCOEFF_NORMED"):
|
||||||
|
methodInt = getattr(cv, method)
|
||||||
|
|
||||||
|
herePath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
template = cv.imread(os.path.join(herePath, "assets", "FishTest3.png"), cv.IMREAD_GRAYSCALE)
|
||||||
|
|
||||||
|
res = cv.matchTemplate(img, template, methodInt)
|
||||||
|
w, h = template.shape[::-1]
|
||||||
|
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
|
||||||
|
|
||||||
|
# If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
|
||||||
|
if method in [cv.TM_SQDIFF, cv.TM_SQDIFF_NORMED]:
|
||||||
|
top_left = min_loc
|
||||||
|
else:
|
||||||
|
top_left = max_loc
|
||||||
|
bottom_right = (top_left[0] + w, top_left[1] + h)
|
||||||
|
|
||||||
|
cv.rectangle(img,top_left, bottom_right, 255, 2)
|
||||||
|
|
||||||
|
plt.subplot(121)
|
||||||
|
plt.imshow(res,cmap = 'gray')
|
||||||
|
plt.title('Matching Result')
|
||||||
|
plt.xticks([])
|
||||||
|
plt.yticks([])
|
||||||
|
plt.subplot(122)
|
||||||
|
plt.imshow(img,cmap = 'gray')
|
||||||
|
plt.title('Detected Point')
|
||||||
|
plt.xticks([])
|
||||||
|
plt.yticks([])
|
||||||
|
plt.suptitle(method)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
def stopScreenCaptureThread(self):
|
||||||
|
if (self.screenThread):
|
||||||
|
self.screenThread.terminate()
|
||||||
|
self.logger.log("Main Agent: Thread terminated")
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 8.9 MiB After Width: | Height: | Size: 8.1 MiB |
|
|
@ -1,10 +1,12 @@
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
from core.Logger import Logger
|
||||||
|
|
||||||
class CLIAgent:
|
class CLIAgent:
|
||||||
def __init__(self, mainAgent) -> None:
|
def __init__(self, mainAgent) -> None:
|
||||||
self.isRunning = False
|
self.isRunning = False
|
||||||
|
self.logger = Logger("CliAgent")
|
||||||
if (not mainAgent):
|
if (not mainAgent):
|
||||||
raise Exception("CLI: Main agent not found...")
|
raise Exception("Main agent not found...")
|
||||||
self.mainAgent = mainAgent
|
self.mainAgent = mainAgent
|
||||||
|
|
||||||
def printMenu(self):
|
def printMenu(self):
|
||||||
|
|
@ -18,26 +20,20 @@ class CLIAgent:
|
||||||
self.isRunning = True
|
self.isRunning = True
|
||||||
|
|
||||||
self.printMenu()
|
self.printMenu()
|
||||||
while self.isRunning:
|
while self.isRunning is True:
|
||||||
userInput = input()
|
userInput = input()
|
||||||
userInput = str.lower(userInput).strip()
|
userInput = str.lower(userInput).strip()
|
||||||
|
|
||||||
if (userInput == "f"):
|
if (userInput == "f"):
|
||||||
print("Starting Fishing bot...")
|
self.logger.log("Starting Fishing bot...")
|
||||||
self.mainAgent.startScreenCaptureThread()
|
self.mainAgent.startFishBot()
|
||||||
break
|
|
||||||
# fishingAgent = FishingAgent(mainAgent)
|
|
||||||
# fishingAgent.run()
|
|
||||||
elif (userInput == "h"):
|
elif (userInput == "h"):
|
||||||
self.printMenu()
|
self.printMenu()
|
||||||
break
|
|
||||||
elif (userInput == "q"):
|
elif (userInput == "q"):
|
||||||
cv.destroyAllWindows()
|
cv.destroyAllWindows()
|
||||||
print("Exiting application...")
|
self.logger.log("Exiting application...")
|
||||||
self.isRunning = False
|
self.isRunning = False
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
print("Unknown Command.")
|
self.logger.log("Unknown Command.")
|
||||||
self.printMenu()
|
self.printMenu()
|
||||||
break
|
|
||||||
|
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 800 KiB After Width: | Height: | Size: 1.5 MiB |