diff --git a/src/entities/system_entities.py b/src/entities/system_entities.py index 2e053a09fd127e4ee4d7c6935c83b7f725ab903a..b68a6dd6d3be2f6504486ed567f03f0d3cbdad2b 100644 --- a/src/entities/system_entities.py +++ b/src/entities/system_entities.py @@ -690,6 +690,67 @@ class Walls: return True + def check_has_extra_walls(self): + """ + Checks if tile entity has "extra walls", outside of minimum the tile is required to have (depending on position). + :return: True if tile has "extra walls" | False otherwise. + """ + # Do easy check for any walls. + if not self.has_walls: + # No walls at all. + return False + else: + # Tile has some walls. Double check if edge tile or not. + has_walls = True + if self.tile_x == 0: + # Tile is on left edge of grid. + + if self.tile_y == 0: + # Tile is on upper left of grid. + if self.wall_state == 7: + has_walls = False + + elif self.tile_y == self.data_manager.tile_data['tile_h_count'] - 1: + # Tile is on bottom left of grid. + if self.wall_state == 10: + has_walls = False + + else: + # Tile is on general left edge, but not corner. + if self.wall_state == 4: + has_walls = False + + elif self.tile_x == self.data_manager.tile_data['tile_w_count'] - 1: + # Tile is on right edge of grid. + + if self.tile_y == 0: + # Tile is on upper right of grid. + if self.wall_state == 5: + has_walls = False + + elif self.tile_y == self.data_manager.tile_data['tile_h_count'] - 1: + # Tile is on lower right of grid. + if self.wall_state == 8: + has_walls = False + + else: + # Tile is on general right edge, but not corner. + if self.wall_state == 2: + has_walls = False + + elif self.tile_y == 0: + # Tile is on general top edge, but not corner. + if self.wall_state == 1: + has_walls = False + + elif self.tile_y == self.data_manager.tile_data['tile_h_count'] - 1: + # Tile is on general bottom edge, but not corner. + if self.wall_state == 3: + has_walls = False + + # Return final condition. + return has_walls + def bipartite_color_validation(self): """ Validates wall placement by using 2-coloring on the tile graph to ensure all nodes are reachable by the roomba. diff --git a/src/misc.py b/src/misc.py index 115b36d1e8c7c8530219f201bda36587d4b56ff2..c3d859fb67645735bd0e7c36975846d92a45633b 100644 --- a/src/misc.py +++ b/src/misc.py @@ -138,7 +138,7 @@ def handle_mouse_click(data_manager, button_state, pos_x, pos_y): # Middle click. # If tile is empty and no trash, generate some. - if not tile.walls.has_walls and not tile.trashpile.exists: + if not tile.walls.check_has_extra_walls() and not tile.trashpile.exists: tile.trashpile.place() # Else if tile is empty and has trash, remove.