From fba0c2c50606c00d915cada13ccf871a4d146d80 Mon Sep 17 00:00:00 2001 From: Thaloria Date: Sat, 22 Jul 2023 10:54:32 +0200 Subject: [PATCH] litris fixes --- litris.py | 32 +++++++++++++++++++++++++------- tetromino.py | 16 ++++++++-------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/litris.py b/litris.py index 643e4ca..4a27984 100644 --- a/litris.py +++ b/litris.py @@ -101,6 +101,10 @@ class Litris(GameBase): # 2: cv.imread("sodoku/2.jpg", cv.IMREAD_COLOR), } + def reset_field(self): + self.state = [[' ' for cols in range(Field.WIDTH)] + for rows in range(Field.HEIGHT)] + def fill_data_coordinates(self): # 610 to 1950 = 1340 - 76 / 20 = 63 # 40 to 1380 = 1340 - 76 / 20 = 63 @@ -133,7 +137,10 @@ class Litris(GameBase): #ier = 0 current_stone = self.new_stone_detection_and_identification() - current_tetromino = Tetromino.create(self.get_letter_for_stone(current_stone)) + current_letter = self.get_letter_for_stone(current_stone) + if current_letter is None: + return + current_tetromino = Tetromino.create(current_letter) opt = Optimizer.get_optimal_drop(self.field, current_tetromino) rotation = opt['tetromino_rotation'] column = opt['tetromino_column'] @@ -141,6 +148,7 @@ class Litris(GameBase): offset_col = current_tetromino.get_offset_column(rotation) self.field.drop(current_tetromino, column) self.move_stone(column - offset_col, rotation) + print(self.field) #time.sleep(0.2) #self.observation = new_observation @@ -199,6 +207,8 @@ class Litris(GameBase): rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 16) if len(rectangles) == 0: cv.waitKey(100) + if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused': + return continue points = self.vision_stun.get_click_points(rectangles) @@ -238,6 +248,8 @@ class Litris(GameBase): return "Z" elif np.array_equal(stone, T1_FULL): return "T" + else: + return None def find_place_for_stone(self, stone, current_board): @@ -337,17 +349,23 @@ class Litris(GameBase): cv.waitKey(250) if rotation == 1: - self.keyboard.press('e') - self.keyboard.release('e') + self.keyboard.press('q') + self.keyboard.release('q') elif rotation == 2: - self.keyboard.press('e') - self.keyboard.release('e') + self.keyboard.press('q') + self.keyboard.release('q') cv.waitKey(40) - self.keyboard.press('e') - self.keyboard.release('e') + self.keyboard.press('q') + self.keyboard.release('q') elif rotation == 3: self.keyboard.press('q') self.keyboard.release('q') + cv.waitKey(40) + self.keyboard.press('q') + self.keyboard.release('q') + cv.waitKey(40) + self.keyboard.press('q') + self.keyboard.release('q') if col_movement < 0: for i in range(0, col_movement, - 1): diff --git a/tetromino.py b/tetromino.py index a83edc8..9d3f7a8 100644 --- a/tetromino.py +++ b/tetromino.py @@ -169,17 +169,17 @@ class Tetromino(): def get_offset_column(self, rotation): offset_map= { - 'i': {0: 10, 1: 9, 2: 10, 3: 9}, + 'i': {0: 8, 1: 9, 2: 9, 3: 9}, 'a': {0: 9, 1: 9, 2: 9, 3: 9}, - 'b': {0: 9, 1: 8, 2: 10, 3: 8}, - 'c': {0: 8, 1: 8, 2: 8, 3: 8}, + 'b': {0: 9, 1: 9, 2: 9, 3: 9}, + 'c': {0: 10, 1: 9, 2: 9, 3: 9}, 'o': {0: 9, 1: 9, 2: 9, 3: 9}, 'd': {0: 9, 1: 9, 2: 9, 3: 9}, - 't': {0: 9, 1: 9, 2: 10, 3: 9}, - 's': {0: 9, 1: 9, 2: 9, 3: 9}, - 'z': {0: 9, 1: 9, 2: 9, 3: 9}, - 'j': {0: 9, 1: 8, 2: 8, 3: 8}, - 'l': {0: 9, 1: 8, 2: 8, 3: 8} + 't': {0: 9, 1: 9, 2: 9, 3: 9}, + 's': {0: 9, 1: 10, 2: 9, 3: 10}, + 'z': {0: 9, 1: 10, 2: 9, 3: 10}, + 'j': {0: 9, 1: 9, 2: 10, 3: 9}, + 'l': {0: 9, 1: 9, 2: 9, 3: 9} } return offset_map.get(self.letter)[rotation]