From 62ff7cb40d2b3fe7919f4edfcb2b6ff0228cac31 Mon Sep 17 00:00:00 2001 From: Thaloria Date: Sun, 23 Jul 2023 18:38:50 +0200 Subject: [PATCH] added first draft litris --- litris.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/litris.py b/litris.py index f919c24..454c5d0 100644 --- a/litris.py +++ b/litris.py @@ -6,17 +6,17 @@ from field import Field from tetromino import Tetromino from optimizer import Optimizer -O_FULL = [[0, 1, 1, 0], [0, 1, 1, 0]] -D_FULL = [[0, 1, 1, 0], [0, 0, 1, 0]] -L_FULL = [[0, 0, 1, 0], [1, 1, 1, 0]] -J_FULL = [[1, 1, 1, 0], [0, 0, 1, 0]] -I_FULL = [[1, 1, 1, 1], [0, 0, 0, 0]] -C_FULL = [[0, 0, 0, 0], [0, 0, 1, 0]] -B_FULL = [[0, 0, 0, 0], [0, 1, 1, 0]] -A_FULL = [[0, 1, 1, 1], [0, 0, 0, 0]] -S_FULL = [[0, 0, 1, 1], [0, 1, 1, 0]] -Z_FULL = [[0, 1, 1, 0], [0, 0, 1, 1]] -T_FULL = [[0, 1, 1, 1], [0, 0, 1, 0]] +O_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]] +D_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]] +L_FULL = [[0, 0, 0, 0], [0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0]] +J_FULL = [[0, 0, 0, 0], [1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]] +I_FULL = [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]] +C_FULL = [[0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]] +B_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]] +A_FULL = [[0, 0, 0, 0], [0, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]] +S_FULL = [[0, 0, 0, 0], [0, 0, 1, 1], [0, 1, 1, 0], [0, 0, 0, 0]] +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 Litris(GameBase): @@ -26,7 +26,7 @@ class Litris(GameBase): self.keyboard = Controller() self.data_coordinates = np.zeros((20, 20), dtype=object) - self.stone_coordinates = np.zeros((2, 4), dtype=object) + self.stone_coordinates = np.zeros((4, 4), dtype=object) self.observation = np.zeros((20, 20), dtype=int) self.colors = [1, 2, 3, 4, 5, 6, 7, 8, 9] @@ -57,13 +57,13 @@ class Litris(GameBase): for e in range(0, 20, 1): for i in range(0, 20, 1): self.data_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim] - for e in range(0, 2, 1): + for e in range(0, 4, 1): for i in range(0, 4, 1): self.stone_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim] def assess_playfield_and_make_move(self): - # current_letter = self.new_stone_detection_and_identification() - current_letter = self.stone_id() + current_letter = self.new_stone_detection_and_identification() + #current_letter = self.stone_id() #current_letter = 'D' print("current_letter: ", current_letter) if current_letter is None: @@ -157,13 +157,13 @@ class Litris(GameBase): screenshot = self.capture_window.get_screenshot() #screenshot = cv.imread("litris/main_playfield.jpg") # 1148 1412 580 845 - screenshot = screenshot[643:782, 1148:1412] + screenshot = screenshot[580:845, 1148:1412] #cv.imshow("screenshot", screenshot) #cv.waitKey(150) # 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[1], 0.85, 4) + rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 16) if len(rectangles) == 0: if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused': return @@ -284,7 +284,7 @@ class Litris(GameBase): return None, None def point_in_smal_rect(self, point): - for e in range(0, 2, 1): + for e in range(0, 4, 1): for i in range(0, 4, 1): x1, y1, w, h = self.stone_coordinates[e][i] x2, y2 = x1 + w, y1 + h