From 3a8c8568acbb9dcfdb91b0f9d7e5cc1204cfdd27 Mon Sep 17 00:00:00 2001 From: "Thaloria@web.de" Date: Tue, 18 Oct 2022 23:07:43 +0200 Subject: [PATCH] bug fix 5s --- farm.py | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/farm.py b/farm.py index 402a961..8586d1e 100644 --- a/farm.py +++ b/farm.py @@ -157,9 +157,7 @@ class Farm(GameBase): for e in range(0, 8, 1): for i in range(0, 14, 1): for color in self.colors: - if self.check_5_horizontal(state, e, i, color): - return - if self.check_5_vertical(state, e, i, color): + if self.check_5s(state, e, i, color): return if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused': break @@ -210,43 +208,33 @@ class Farm(GameBase): continue return False - def check_5_horizontal(self, state, e, i, color): + def check_5s(self, state, e, i, color): try: # - if state[e, i] == color and state[e, i + 1] == color and state[e, i + 3] == color and state[ - e, i + 4] == color: - if state[e, i + 2] <= 0 or state[e, i + 2] >= 6: - return False - # - if e - 1 >= 0 and i + 2 <= 13: - if state[e - 1, i + 2] == color: - return True - return False - except: - return False - - def check_5_vertical(self, state, e, i, color): - try: - # - if state[e, i] == color and state[e + 1, i] == color and state[e + 3, i] == color and state[ - e + 4, i] == color: - if state[e + 2, i] <= 0 or state[e + 2, i] >= 6: - return False - # third left upper - if e + 2 <= 7 and i - 1 >= 0: - if state[e + 2, i - 1] == color: - # print("upper left", color, e, i) + if state[e, i] == color and state[e + 1, i] == color and state[e + 3, i] == color and state[e + 4, i] == color: + if state[e + 2, i] in self.colors: + if self.is_direction_in_bounce_and_same_color(state, (e + 2, i - 1), color): src_pt = self.get_click_point(self.data_coordinates[e + 2, i - 1]) dest_pt = self.get_click_point(self.data_coordinates[e + 2, i]) self.move_tile(src_pt, dest_pt) return True - if e + 2 <= 7 and i + 1 <= 13: - if state[e + 2, i + 1] == color: - # print("upper left", color, e, i) + if self.is_direction_in_bounce_and_same_color(state, (e + 2, i + 1), color): src_pt = self.get_click_point(self.data_coordinates[e + 2, i + 1]) dest_pt = self.get_click_point(self.data_coordinates[e + 2, i]) self.move_tile(src_pt, dest_pt) return True + elif state[e, i] == color and state[e, i + 1] == color and state[e, i + 3] == color and state[e, i + 4] == color: + if state[e, i + 2] in self.colors: + if self.is_direction_in_bounce_and_same_color(state, (e + 1, i +2), color): + src_pt = self.get_click_point(self.data_coordinates[e + 1, i + 2]) + dest_pt = self.get_click_point(self.data_coordinates[e, i + 2]) + self.move_tile(src_pt, dest_pt) + return True + if self.is_direction_in_bounce_and_same_color(state, (e - 1, i + 2), color): + src_pt = self.get_click_point(self.data_coordinates[e - 1, i + 2]) + dest_pt = self.get_click_point(self.data_coordinates[e, i + 2]) + self.move_tile(src_pt, dest_pt) + return True return False except: return False @@ -362,7 +350,7 @@ class Farm(GameBase): # third left lower if e + 2 <= 7 and i - 1 >= 0: if state[e + 2, i - 1] == color and (state[e + 2, i] in self.colors): - print("lower left", color, e, i) + # print("lower left", color, e, i) src_pt = self.get_click_point(self.data_coordinates[e + 2, i - 1]) dest_pt = self.get_click_point(self.data_coordinates[e + 2, i]) self.move_tile(src_pt, dest_pt)