Skip to content

Commit

Permalink
Merge pull request #5 from TareHimself/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TareHimself authored Aug 16, 2023
2 parents 5aeae75 + d44e014 commit 13356d8
Show file tree
Hide file tree
Showing 6 changed files with 3,548 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node_modules/*
node_modules
pending-capture/*

*.mkv
*.mkv
*.lock
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ conda activate osu-ai
```bash
poetry install
# For cuda support run "poe force-cuda"
# For win32Mouse support run "poe use-win32"
```
- now we can run main
```bash
Expand Down
21 changes: 13 additions & 8 deletions ai/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
from collections import deque
from mss import mss
from ai.enums import EPlayAreaIndices
import pyautogui
import mouse
# 'osu!' #
DEFAULT_OSU_WINDOW = 'osu!' # "osu! (development)"

USE_WIN_32_MOUSE = False
try:
import win32api
USE_WIN_32_MOUSE = True
except:
USE_WIN_32_MOUSE = False

class EvalThread(Thread):

def __init__(self, model_id: str, game_window_name: str = DEFAULT_OSU_WINDOW, eval_key: str = '\\'):
super().__init__(group=None, daemon=True)
pyautogui.PAUSE = 0
self.game_window_name = game_window_name
self.model_id = model_id
self.capture_params = derive_capture_params()
Expand Down Expand Up @@ -62,7 +65,6 @@ def toggle_eval():

self.on_eval_ready()

print(self.capture_params)
with mss() as sct:
monitor = {"top": self.capture_params[EPlayAreaIndices.OffsetY.value],
"left": self.capture_params[EPlayAreaIndices.OffsetX.value],
Expand Down Expand Up @@ -134,9 +136,8 @@ def on_output(self, output: Tensor):


class AimThread(EvalThread):
def __init__(self, model_id: str, game_window_name: str = DEFAULT_OSU_WINDOW, eval_key: str = '\\',is_win32 = False):
def __init__(self, model_id: str, game_window_name: str = DEFAULT_OSU_WINDOW, eval_key: str = '\\'):
super().__init__(model_id, game_window_name, eval_key)
self.is_win32 = is_win32

# def get_model(self):
# # model = torch.jit.load(os.path.join(MODELS_DIR, self.model_id, 'model.pt'))
Expand All @@ -156,7 +157,7 @@ def on_output(self, output: Tensor):
(mouse_y_percent * self.capture_params[EPlayAreaIndices.Height.value]) + self.capture_params[
EPlayAreaIndices.OffsetY.value]))
# pyautogui.moveTo(position[0], position[1])
if self.is_win32:
if USE_WIN_32_MOUSE:
import win32api
win32api.SetCursorPos(position)
else:
Expand All @@ -177,7 +178,11 @@ def on_output(self, output: Tensor):
(mouse_y_percent * self.capture_params[EPlayAreaIndices.Height.value]) + self.capture_params[
EPlayAreaIndices.OffsetY.value]))

mouse.move(position[0],position[1])
if USE_WIN_32_MOUSE:
import win32api
win32api.SetCursorPos(position)
else:
mouse.move(position[0],position[1])

if k1_prob >= 0.5:
keyboard.press('z')
Expand Down
Loading

0 comments on commit 13356d8

Please sign in to comment.