Compare commits

...

17 Commits

Author SHA1 Message Date
7eed550797 Merge remote-tracking branch 'origin/master' 2023-08-24 09:43:27 +02:00
cc9789c65c ring fix 2023-08-24 09:43:13 +02:00
d64b704274 update menti 2023-08-06 16:36:52 +02:00
ed23f196a6 update menti 2023-08-06 16:32:45 +02:00
b8abdb690b update menti 2023-08-06 16:30:20 +02:00
8d2aad34b2 update menti 2023-08-06 16:25:52 +02:00
e70c7d2be9 update menti 2023-08-06 16:23:55 +02:00
5005670bd3 update menti 2023-08-06 16:21:48 +02:00
b1fc655c0b update menti 2023-08-06 16:12:13 +02:00
9cc4018747 update flappy 2023-07-30 18:46:40 +02:00
849aaf8e27 update flappy 2023-07-30 18:42:53 +02:00
804f178fbf update flappy 2023-07-30 15:08:29 +02:00
c1eecfd567 update flappy 2023-07-30 15:05:47 +02:00
99a2976b61 update flappy 2023-07-30 15:01:20 +02:00
cadcfe8103 update litris with board detection 2023-07-30 14:28:15 +02:00
ab0def9115 update litris with board detection 2023-07-30 10:57:43 +02:00
b24a835f18 update litris with board detection 2023-07-30 10:08:33 +02:00
12 changed files with 120 additions and 36 deletions

View File

@@ -112,6 +112,9 @@ class Equipment(GameBase):
spawn_1 = self.find_emitter(emitter, screenshot, 1)
if len(spawn_1) == 1:
#output_by_area = self.vision_stun.draw_rectangles(screenshot, spawn_1)
#cv.imshow("spawn_1", output_by_area)
#cv.waitKey(150)
points = self.vision_stun.get_click_points(spawn_1)
for i in range(0, self.SPAWN_COUNT, 1):
self.click_point(points[0][0], points[0][1])
@@ -316,7 +319,7 @@ class Equipment(GameBase):
else:
needle = cv.imread("equip/emitters/ring_e2_32.jpg", cv.IMREAD_UNCHANGED)
mask = cv.imread("equip/emitters/ring_e2_32-mask.png", cv.IMREAD_COLOR)
return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
return self.vision_stun.find(screen, needle, 0.95, 1, False, mask)
elif emitter_to_use == EMITTER_WAND:
if layer == 0:
needle = cv.imread("equip/emitters/wand_e1_32.jpg", cv.IMREAD_UNCHANGED)

View File

@@ -2,6 +2,7 @@ import cv2 as cv
import pydirectinput
from game_base_class import GameBase
from flappy_pos_discovery_thread import FlappyPosDiscovery
from keyboard_thread import KeyboardEvent
class Flappy(GameBase):
@@ -11,18 +12,25 @@ class Flappy(GameBase):
self.litris_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
self.flappy_pos_disc = FlappyPosDiscovery()
self.keyboard_listener = KeyboardEvent()
def assess_playfield_and_make_move(self):
#last_letter_received = time()
wait_timer = 380
while True:
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
return
wait_timer = 380 + self.keyboard_listener.offset_value
self.click()
cv.waitKey(wait_timer)
'''
if self.flappy_pos_disc.next_gate_height[0] is not 0:
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.get_actual_pet_height()
if offset > 50:
self.click()
cv.waitKey(int(wait_timer -100))
print("pet_pos: ", self.flappy_pos_disc.get_actual_pet_height())
pydirectinput.mouseDown()
cv.waitKey(50)
pydirectinput.mouseUp()
cv.waitKey(int(wait_timer))
if self.flappy_pos_disc.next_gate_height[0] is not 0:
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.current_pet_height
if offset > 50:
@@ -33,4 +41,9 @@ class Flappy(GameBase):
wait_timer = 380 + offset
print(wait_timer)
print("pet_pos: ", self.flappy_pos_disc.current_pet_height)
print("next gate: ", self.flappy_pos_disc.next_gate_height[0] + 120)
print("next gate: ", self.flappy_pos_disc.next_gate_height[0] + 120) '''
def click(self):
pydirectinput.mouseDown()
cv.waitKey(50)
pydirectinput.mouseUp()

View File

@@ -20,7 +20,7 @@ class FlappyPosDiscovery(threading.Thread):
self.mask_g = self.scale_picture(cv.imread("flappy/gate-mask.png"), 50)
self.run_mode = 'run'
self.current_pet_height = 0
self.current_pet_height = []
self.next_gate_height = [0,0,0]
self.offset_down = 90
@@ -51,7 +51,9 @@ class FlappyPosDiscovery(threading.Thread):
pass
if len(rectangles_f) is not 0:
self.current_pet_height = rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down
self.current_pet_height.append(rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down)
if len(self.current_pet_height) > 5:
self.current_pet_height.pop(0)
#print("pet_pos: ", self.current_pet_height)
#print("next gate: ", self.next_gate_height)
@@ -68,7 +70,8 @@ class FlappyPosDiscovery(threading.Thread):
return thresh
def get_actual_pet_height(self):
return self.current_pet_height
return sum(self.current_pet_height) / len(self.current_pet_height)
def get_next_gate_height(self):
return self.next_gate_height

32
keyboard_thread.py Normal file
View File

@@ -0,0 +1,32 @@
import threading
import cv2 as cv
import keyboard
class KeyboardEvent(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.run_mode = 'run'
self.offset_value = 0
self.start()
def run(self):
while self.run_mode == 'run':
if keyboard.is_pressed('up'): # if key 'q' is pressed
self.offset_value = -75
elif keyboard.is_pressed('down'):
self.offset_value = 75
elif keyboard.is_pressed('left') or keyboard.is_pressed('right'):
self.offset_value = 0
cv.waitKey(10)
def callback(self):
pass
def destroy(self):
self.destroy()
def get_run_mode(self):
return self.run_mode

View File

@@ -27,6 +27,7 @@ class Litris(GameBase):
self.stone_id_thread = NewStoneID()
self.move_mode = 1
self.moved_around_full = False
self.field_state_storage = {
1: self.field,
@@ -35,14 +36,18 @@ class Litris(GameBase):
4: self.field
}
def reset(self):
self.field.reset_field()
self.field.cleared_rows = 1
self.move_mode = 1
self.moved_around_full = False
def assess_playfield_and_make_move(self):
last_letter_received = time()
while True:
if self.stone_id_thread.get_pick_up_status() == False:
if (time() - last_letter_received) >= 5:
self.field.reset_field()
self.field.cleared_rows = 1
self.move_mode = 1
self.reset()
last_letter_received = time()
self.dig_point(1500, 980, 100)
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
@@ -50,7 +55,7 @@ class Litris(GameBase):
continue
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
return
cv.waitKey(50)
cv.waitKey(25)
continue
@@ -82,7 +87,7 @@ class Litris(GameBase):
print(self.field)
if self.field.get_line_count() >= 6 and self.field.height() <= 2 and self.field.check_crucial_pos_to_be_free():
if self.field.predict_gaps_in_next_rotation() <= 3:
self.field_state_storage[self.move_mode] = self.field
self.field_state_storage[self.move_mode] = copy(self.field)
self.update_move_mode()
#self.field.state = self.stone_id_thread.get_current_board_state()
self.field.rotate_state()
@@ -95,15 +100,31 @@ class Litris(GameBase):
self.field.cleared_rows = 1
cv.waitKey(200)
cv.waitKey(100)
self.stone_id_thread.set_pick_up_status(False)
def update_field_with_stored_edges(self):
if self.move_mode == 4:
if self.move_mode == 1 and self.moved_around_full:
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[2].state))
for i in range(11,20,1):
for e in range(0,2,1):
self.field.state[i][e] = state_copy[i][e]
elif self.move_mode == 2 and self.moved_around_full:
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[3].state))
for i in range(11,20,1):
for e in range(0,2,1):
self.field.state[i][e] = state_copy[i][e]
elif self.move_mode == 3 and self.moved_around_full:
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[4].state))
for i in range(11, 20, 1):
for e in range(0, 2, 1):
self.field.state[i][e] = state_copy[i][e]
elif self.move_mode == 4:
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[1].state))
for i in range(11,20,1):
for e in range(0,2,1):
self.field.state[i][e] = state_copy[i][e]
self.moved_around_full = True
def drop_down(self):
if self.move_mode == 1:
@@ -126,7 +147,7 @@ class Litris(GameBase):
self.keyboard.press(down)
self.keyboard.release(down)
print("drop down pressed:", down)
cv.waitKey(50)
cv.waitKey(40)
def update_move_mode(self):
if self.move_mode <=3:
@@ -159,13 +180,13 @@ class Litris(GameBase):
self.keyboard.press(down)
self.keyboard.release(down)
print("direction pressed: ", down)
cv.waitKey(120)
cv.waitKey(60)
if rotation == 3:
self.keyboard.press('e')
self.keyboard.release('e')
print("rotation 1 pressed: e")
cv.waitKey(40)
cv.waitKey(30)
elif rotation == 2:
self.keyboard.press('e')
self.keyboard.release('e')
@@ -179,28 +200,28 @@ class Litris(GameBase):
self.keyboard.press('e')
self.keyboard.release('e')
print("rotation 3 pressed: e 1")
cv.waitKey(20)
cv.waitKey(30)
self.keyboard.press('e')
self.keyboard.release('e')
print("rotation 3 pressed: e 2")
cv.waitKey(20)
cv.waitKey(30)
self.keyboard.press('e')
self.keyboard.release('e')
print("rotation 3 pressed: e 3")
cv.waitKey(20)
cv.waitKey(30)
if col_movement < 0:
for i in range(0, col_movement, - 1):
self.keyboard.press(left)
self.keyboard.release(left)
print("move left 3 pressed:", left)
cv.waitKey(40)
cv.waitKey(30)
else:
for i in range(0, col_movement, 1):
self.keyboard.press(right)
self.keyboard.release(right)
print("move right 3 pressed:", right)
cv.waitKey(40)
cv.waitKey(30)
def point_in_rect(self, point):
for e in range(0, 20, 1):

View File

@@ -4,6 +4,7 @@ import pydirectinput
from nltk.corpus import words
from pytesseract import pytesseract
import utils
from utils import mse
from game_base_class import GameBase
import random
@@ -87,7 +88,7 @@ class MentiWords(GameBase):
with open("menti_dic") as file:
self.word_list = [line.rstrip() for line in file]
self.word_list2 = words.words()
#self.word_list2 = words.words()
def reset_lists(self):
self.current_letters = []
@@ -126,7 +127,7 @@ class MentiWords(GameBase):
#screenshot = cv.imread("menti_words/screenshot.jpg")
screenshot = self.capture_window.get_screenshot()
screenshot = screenshot[870:1270, 1080:1480]
screenshot = utils.scale_screenshot(screenshot[870:1270, 1080:1480], 200, False)
#cv.imshow("screenshot", screenshot)
#cv.waitKey(150)
@@ -134,26 +135,35 @@ class MentiWords(GameBase):
for needle_key in self.needles.keys():
# gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY)
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.85, 1)
thresh_needle = utils.scale_screenshot(self.needles[needle_key], 200, False)
rectangles = self.vision_stun.find(screenshot, thresh_needle , 0.85, 2)
#rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.95, 1 ,True, self.masks[needle_key])
if len(rectangles) == 0:
continue
points = self.vision_stun.get_click_points(rectangles)
for point in points:
self.current_letters.append(needle_key)
self.letter_coords[needle_key] = (int(point[0]/2), int(point[1]/2))
'''
cropped1 = self.vision_stun.draw_display_picture(screenshot, rectangles, 10)
#cropped1 = utils.scale_screenshot(cropped1)
cv.imshow("cropped1", cropped1)
cv.waitKey(150)
text_1 = pytesseract.image_to_string(cropped1, lang='eng', config='--psm 6').strip()
if str.isalpha(text_1):
#cv.imshow("cropped1", cropped1)
#cv.waitKey(150)
points = self.vision_stun.get_click_points(rectangles)
self.current_letters.append(text_1)
self.letter_coords[text_1] = points[0]
self.letter_coords[text_1] = points[0]'''
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
return
def possible_words(self, lwords, charSet):
lst = []
for word in lwords:
if len(word) <= 2:
if len(word) <= 1:
continue
flag = 1
chars = self.charCount(word)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -61,18 +61,20 @@ def check_for_bl_line(line_item, black_list):
return False
def scale_screenshot(screenshot):
scale_percent = 200 # percent of original size
def scale_screenshot(screenshot, percent = 200, thresh_mode = True):
scale_percent = percent # percent of original size
width = int(screenshot.shape[1] * scale_percent / 100)
height = int(screenshot.shape[0] * scale_percent / 100)
dim = (width, height)
resized_img = cv.resize(screenshot, dim, interpolation=4)
gray = cv.cvtColor(resized_img, cv.COLOR_BGR2GRAY)
thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
if thresh_mode:
gray = cv.cvtColor(resized_img, cv.COLOR_BGR2GRAY)
thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
return thresh
# cv.imshow("Tresh", thresh)
# cv.waitKey(1000)
return thresh
return resized_img
def save_line_item_npy_jpg(short_pic_list):