added async stone detection thread
This commit is contained in:
29
litris.py
29
litris.py
@@ -1,24 +1,18 @@
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
from time import time
|
||||
from game_base_class import GameBase
|
||||
from pynput.keyboard import Key, Controller
|
||||
from field import Field
|
||||
from tetromino import Tetromino
|
||||
from optimizer import Optimizer
|
||||
from litris_stone_id_thread import NewStoneID
|
||||
from window_capture import WindowCapture
|
||||
from vision import Vision
|
||||
from config_file import UserConfigs
|
||||
|
||||
class Litris(GameBase):
|
||||
|
||||
def __init__(self, overlay):
|
||||
super().__init__(overlay)
|
||||
|
||||
self.config = UserConfigs()
|
||||
self.capture_window = WindowCapture(None, None, self.config)
|
||||
self.vision_stun = Vision()
|
||||
|
||||
self.keyboard = Controller()
|
||||
|
||||
self.data_coordinates = np.zeros((20, 20), dtype=object)
|
||||
@@ -36,7 +30,7 @@ class Litris(GameBase):
|
||||
|
||||
self.litris_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
|
||||
|
||||
self.stone_id_thread = NewStoneID(self.capture_window)
|
||||
self.stone_id_thread = NewStoneID()
|
||||
|
||||
self.move_mode = 1
|
||||
|
||||
@@ -52,27 +46,24 @@ class Litris(GameBase):
|
||||
self.data_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim]
|
||||
|
||||
def assess_playfield_and_make_move(self):
|
||||
|
||||
last_letter_received = time()
|
||||
while True:
|
||||
if self.stone_id_thread.get_pick_up_status() == False:
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
screenshot = screenshot[880:1060, 1400:1600]
|
||||
if self.check_for_button_and_execute(screenshot, self.litris_reset_board, 1400, 880):
|
||||
if (time() - last_letter_received) >= 5:
|
||||
cv.waitKey(500)
|
||||
self.dig_point(1500, 980, 100)
|
||||
self.field.reset_field()
|
||||
last_letter_received = time()
|
||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||
return
|
||||
cv.waitKey(50)
|
||||
continue
|
||||
|
||||
#current_letter = self.new_stone_detection_and_identification()
|
||||
#current_letter = self.stone_id()
|
||||
#current_letter = 'D'
|
||||
|
||||
current_letter = self.stone_id_thread.get_actual_letter()
|
||||
#self.stone_id_thread.set_pick_up_status(False)
|
||||
print("current_letter: ", current_letter)
|
||||
#if current_letter is None:
|
||||
# cv.waitKey(50)
|
||||
# return
|
||||
last_letter_received = time()
|
||||
|
||||
|
||||
current_tetromino = Tetromino.create(current_letter)
|
||||
if self.move_mode == 2:
|
||||
|
||||
@@ -18,11 +18,11 @@ Z_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [0, 0, 0, 0]]
|
||||
T_FULL = [[0, 0, 0, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 0]]
|
||||
class NewStoneID(threading.Thread):
|
||||
|
||||
def __init__(self, cap_win):
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
#self.config = UserConfigs()
|
||||
self.capture_window = cap_win
|
||||
self.config = UserConfigs()
|
||||
self.capture_window = WindowCapture(None, None, self.config)
|
||||
self.vision_stun = Vision()
|
||||
|
||||
self.stone_coordinates = np.zeros((4, 4), dtype=object)
|
||||
|
||||
Reference in New Issue
Block a user