diff --git a/src/entities/object_entities.py b/src/entities/object_entities.py index a01ee60108758a57109d97f321fb986d2c0cf639..0ed05a28027cbeb1a62e10db16dc81d76334e3e3 100644 --- a/src/entities/object_entities.py +++ b/src/entities/object_entities.py @@ -171,13 +171,6 @@ class TileSet: logger.info('graph.neighbors(1, 1): {0}'.format(list(data_manager.graph.neighbors('1, 1')))) logger.info('') - def get_tile_from_id(self, tile_id): - """""" - tile_x = int(tile_id[0]) - tile_y = int(tile_id[3]) - - return self.tiles[tile_y][tile_x] - def get_tile_id(self, tile, north_neighbor=False, east_neighbor=False, south_neighbor=False, west_neighbor=False): """ Returns the "graph node" identifier for corresponding tile. @@ -204,7 +197,6 @@ class TileSet: # Get coordinate values from tile. tile_x, tile_y = tile.sprite.tile - logger.info('tile: {0}, {1}'.format(tile_x, tile_y)) # Check if we get north neighboring tile id. @@ -249,6 +241,7 @@ class TileSet: Wrapper for wall randomization. Calls with all tile configurations having equal weight. """ + logger.debug('TileSet.randomize_tile_walls_equal()') logger.info('Randomizing tile walls (equal randomization).') self._randomize_tile_walls(weighted=False) @@ -258,6 +251,7 @@ class TileSet: Calls with certain tile configurations having larger weights. Generally speaking, tiles walls will be more sparsely populated. """ + logger.debug('TileSet.randomize_tile_walls_weighted()') logger.info('Randomizing tile walls (weighted randomization).') self._randomize_tile_walls(weighted=True) @@ -265,6 +259,8 @@ class TileSet: """ Randomizes walls on all tiles, while still abiding by wall validation logic. """ + logger.debug('TileSet._randomize_tile_walls()') + # Get each tile row. for row_index in range(self.sprite_data['tile_h_count']): @@ -285,6 +281,7 @@ class TileSet: """ Randomizes trash entities on all tiles. """ + logger.debug('TileSet.randomize_trash()') logger.info('Randomizing trash entity placement.') # Get each tile row. diff --git a/src/entities/system_entities.py b/src/entities/system_entities.py index b06b42c399b2e951300ef64a915568d8884c6e30..dbcd4f7369ea7f3546fff7bb2be69d33c5529580 100644 --- a/src/entities/system_entities.py +++ b/src/entities/system_entities.py @@ -44,6 +44,8 @@ class Movement: :param tile_y: Tile row (y-axis) of entity. :return: Corresponding (x,y) pixel grid coordinates that match tile location. """ + logger.debug('Movement.calculate_pix_from_tile()') + pos_x = (tile_x * 50) + self.data_manager.tile_data['max_pixel_west'] pos_y = (tile_y * 50) + self.data_manager.tile_data['max_pixel_north'] @@ -78,6 +80,8 @@ class AI: This is based on the "_ai_tick_rate" value. Smaller values means it triggers faster. :return: True if AI has met tick rate and should trigger | False otherwise. """ + logger.debug('AI.check_counter()') + # Increment counter. self._timer_counter += 1 @@ -91,15 +95,6 @@ class AI: # AI is still ticking to next trigger. return False - def _calc_distance_cost(self, curr_tile_x, curr_tile_y, end_tile_x, end_tile_y): - """""" - distance = abs(curr_tile_x - end_tile_x) + abs(curr_tile_y - end_tile_y) - print('tile_cost for ({0}, {1}) to ({2}, {3}): {4}'.format(curr_tile_x, curr_tile_y, end_tile_x, end_tile_y, distance)) - return distance - - def _calc_forward_cost(self, curr_tile, end_tile): - """""" - # endregion Active Systems @@ -168,10 +163,12 @@ class Walls: @property def wall_state(self): + logger.debug('Walls.wall_state()') return self._wall_state @wall_state.setter def wall_state(self, value): + logger.debug('Walls.wall_state()') # Verify is int. if not isinstance(value, int): raise TypeError('Variable "wall_state" must be an integer.') @@ -291,10 +288,12 @@ class Walls: @property def has_wall_north(self): + logger.debug('Walls.has_wall_north()') return self._has_wall_north @has_wall_north.setter def has_wall_north(self, value): + logger.debug('Walls.has_wall_north()') # Validate passed value. if not isinstance(value, bool): raise TypeError('Must be boolean.') @@ -362,10 +361,13 @@ class Walls: @property def has_wall_east(self): + logger.debug('Walls.has_wall_east()') return self._has_wall_east @has_wall_east.setter def has_wall_east(self, value): + logger.debug('Walls.has_wall_east()') + # Validate passed value. if not isinstance(value, bool): raise TypeError('Must be boolean.') @@ -433,10 +435,13 @@ class Walls: @property def has_wall_south(self): + logger.debug('Walls.has_wall_south()') return self._has_wall_south @has_wall_south.setter def has_wall_south(self, value): + logger.debug('Walls.has_wall_south()') + # Validate passed value. if not isinstance(value, bool): raise TypeError('Must be boolean.') @@ -504,10 +509,13 @@ class Walls: @property def has_wall_west(self): + logger.debug('Walls.has_wall_west()') return self._has_wall_west @has_wall_west.setter def has_wall_west(self, value): + logger.debug('Walls.has_wall_west()') + # Validate passed value. if not isinstance(value, bool): raise TypeError('Must be boolean.') @@ -583,6 +591,8 @@ class Walls: :param wall_state: Integer value of current potential new wall configuration for tile. :return: True if new state is valid for wall | False otherwise. """ + logger.debug('Walls.validate_wall_state()') + # Verify state is within expected bounds. if wall_state < 0: return False @@ -600,6 +610,8 @@ class Walls: 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. """ + logger.debug('Walls.check_has_extra_walls()') + # Do easy check for any walls. if not self.has_walls: # No walls at all. @@ -660,6 +672,8 @@ class Walls: """ Validates wall placement by using 2-coloring on the tile graph to ensure all nodes are reachable by the roomba. """ + logger.debug('Walls.bipartite_color_validation()') + # Get initial color state of tiles. green_tiles, red_tiles = self.calc_bipartite_color() @@ -737,6 +751,8 @@ class Walls: Calculates all tiles accessible by roomba entity. These are marked as "green", all other tiles are "red". :return: (Array of green tiles, array of red tiles). """ + logger.debug('Walls.calc_bipartite_color()') + # Get roomba location. roomba_x, roomba_y = self.data_manager.roomba.sprite.tile @@ -815,6 +831,8 @@ class Walls: Increases wall state counter. Ensures walls update in predictable order. """ + logger.debug('Walls.increment_wall_state()') + wall_state = self.wall_state + 1 # Loop until valid "next increment" state is found. @@ -836,6 +854,8 @@ class Walls: Decreases wall state counter. Ensures walls update in predictable order. """ + logger.debug('Walls.decrement_wall_state()') + wall_state = self.wall_state - 1 # Loop until valid "next decrement" state is found. @@ -857,6 +877,8 @@ class Walls: Determine new state counter, based on internal wall data. :return: """ + logger.debug('Walls.get_new_state()') + # All walls inactive. if ( @@ -1000,6 +1022,8 @@ class Walls: Sets walls to random configuration value. :param weighted: Bool indicating if randomization should use weighted generation or not. """ + logger.debug('Walls.randomize_walls()') + # Handle based on mode. if not weighted: # Give all states an equal chance. @@ -1038,6 +1062,8 @@ class Walls: This is not true for certain edge-case tiles. In such an edge-case, logic is tailored to try to avoid the possibility of infinite/long loops, while still being as random as possible. """ + logger.debug('Walls._weighted_randomize_walls()') + # Get random value for tile count. Default 25% chance of each. rand_val = random.randint(0, 3) @@ -1061,6 +1087,8 @@ class Walls: """ Logic for assigning 3 randomized walls to tile, if possible. """ + logger.debug('Walls._assign_0_walls()') + # Update variables for wall assignment. tried_0 = True potential_states = [0] @@ -1072,6 +1100,8 @@ class Walls: """ Logic for assigning 3 randomized walls to tile, if possible. """ + logger.debug('Walls._assign_1_wall()') + # Update variables for wall assignment. tried_1 = True potential_states = [1, 2, 3, 4] @@ -1083,6 +1113,8 @@ class Walls: """ Logic for assigning 3 randomized walls to tile, if possible. """ + logger.debug('Walls._assign_2_walls()') + # Update variables for wall assignment. tried_2 = True potential_states = [5, 6, 7, 8, 9, 10] @@ -1094,6 +1126,8 @@ class Walls: """ Logic for assigning 3 randomized walls to tile, if possible. """ + logger.debug('Walls._assign_3_walls()') + # Update variables for wall assignment. tried_3 = True potential_states = [11, 12, 13, 14] @@ -1105,6 +1139,8 @@ class Walls: """ General logic for assigning randomized wall when using weights. """ + logger.debug('Walls._assign_wall()') + valid_state = False wall_state = -1 @@ -1176,6 +1212,8 @@ class TrashPile: Attempts to place trash on file. :return: Bool indicating if trash was successfully placed. """ + logger.debug('TrashPile.place()') + if self.exists: # Trash already present. Skip placing. logger.info('Tile ({0}, {1}) already has trash. Skipping trash placement.'.format(self.tile_x, self.tile_y)) @@ -1211,6 +1249,8 @@ class TrashPile: """ Attempts to clean tile of trash, if any is present. """ + logger.debug('TrashPile.clean()') + if self.exists: logger.info('Cleaned trash at tile ({0}, {1}).'.format(self.tile_x, self.tile_y)) diff --git a/src/misc.py b/src/misc.py index 3af4942b2e0f2c58e31ec87c58b421b58ddfe69d..cbe7995e653b83d4e85be4d657c441688f5ede3a 100644 --- a/src/misc.py +++ b/src/misc.py @@ -77,6 +77,8 @@ def handle_key_press(data_manager, event): :param data_manager: Data manager data structure. Consolidates useful program data to one location. :param event: Event instance to handle. Only confirmed "key press" events should be passed here. """ + logger.debug('handle_key_press()') + roomba = data_manager.roomba # Handle if arrow direction was pressed. @@ -101,6 +103,8 @@ def handle_mouse_click(data_manager, button_state, pos_x, pos_y): :param pos_x: Mouse click x coordinate. :param pos_y: Mouse click y coordinate. """ + logger.debug('handle_mouse_click()') + logger.info('pos_x.value: {0} pos_y.value: {1}'.format(pos_x, pos_y)) logger.info('buttonstate: {0}'.format(button_state)) @@ -178,6 +182,7 @@ def toggle_roomba_ai(data_manager): Toggles roomba AI on or off. Program start default is off. :param data_manager: Data manager data structure. Consolidates useful program data to one location. """ + logger.debug('toggle_roomba_ai()') logger.info('Toggling roomba ai.') if data_manager.ai_active: data_manager.ai_active = False @@ -190,6 +195,7 @@ def set_roomba_vision_range_0(data_manager): Adjusts roomba AI sight to see 0 tiles out from current location. :param data_manager: Data manager data structure. Consolidates useful program data to one location. """ + logger.debug('set_roomba_vision_range_0()') logger.info('Setting roomba vision to "0 tiles" (bump sensor).') data_manager.roomba_vision = 0 @@ -199,6 +205,7 @@ def set_roomba_vision_range_1(data_manager): Adjusts roomba AI sight to see 1 tiles out from current location. :param data_manager: Data manager data structure. Consolidates useful program data to one location. """ + logger.debug('set_roomba_vision_range_1()') logger.info('Setting roomba vision to "1 tiles".') data_manager.roomba_vision = 1 @@ -208,6 +215,7 @@ def set_roomba_vision_range_2(data_manager): Adjusts roomba AI sight to see 2 tiles out from current location. :param data_manager: Data manager data structure. Consolidates useful program data to one location. """ + logger.debug('set_roomba_vision_range_2()') logger.info('Setting roomba vision to "2 tiles".') data_manager.roomba_vision = 2 @@ -217,6 +225,7 @@ def set_roomba_vision_range_full(data_manager): Adjusts roomba AI sight to see all tiles on map. :param data_manager: Data manager data structure. Consolidates useful program data to one location. """ + logger.debug('set_roomba_vision_range_full()') logger.info('Setting roomba vision to "full sight".') data_manager.roomba_vision = -1 @@ -232,6 +241,7 @@ def get_tile_coord_from_id(tile_id): :param tile_id: Identifier for tile. :return: Tuple of (x_coord, y_coord) for tile. """ + logger.debug('get_tile_coord_from_id()') id_split = str(tile_id).split(', ') tile_x = int(id_split[0]) tile_y = int(id_split[1]) @@ -246,6 +256,7 @@ def get_tile_from_id(data_manager, tile_id): :param tile_id: Id of tile to get entity for. :return: Corresponding tile entity. """ + logger.debug('get_tile_from_id()') tile_x, tile_y = get_tile_coord_from_id(tile_id) return data_manager.tile_set.tiles[tile_y][tile_x] @@ -257,6 +268,7 @@ def get_id_from_coord(tile_x, tile_y): :param tile_y: Tile y coordinate. :return: Corresponding tile id. """ + logger.debug('get_id_from_coord()') return '{0}, {1}'.format(tile_x, tile_y) @@ -266,6 +278,7 @@ def get_id_from_tile(tile_entity): :param tile_entity: Tile entity to generate id for. :return: Corresponding tile id. """ + logger.debug('get_id_from_tile()') tile_x, tile_y = tile_entity.sprite.tile return get_id_from_coord(tile_x, tile_y) @@ -279,6 +292,7 @@ def calc_distance_cost(start_tile_x, start_tile_y, end_tile_x, end_tile_y): :param end_tile_y: The y coordinate of the tile to end at. :return: Calculated distance between tiles. """ + logger.debug('calc_distance_cost()') distance = abs(start_tile_x - end_tile_x) + abs(start_tile_y - end_tile_y) return distance @@ -293,6 +307,8 @@ def calc_trash_distances(data_manager, roomba_only=False): :param roomba_only: Bool indicating if only roomba paths should be calculated. :return: Set of all calculated "ideal paths" from each trash tile to every other trash tile. """ + logger.debug('calc_trash_distances()') + priority_queue = [] handled_tiles = {} @@ -303,6 +319,8 @@ def calc_trash_distances(data_manager, roomba_only=False): """ Start of function logic. """ + logger.debug('calc_trash_distances()._calc_trash_distances()') + # Tell function to use variables in larger function scope. nonlocal priority_queue nonlocal handled_tiles @@ -439,6 +457,8 @@ def calc_trash_distances(data_manager, roomba_only=False): """ Calculates distances from roomba to each trash tile. """ + logger.debug('calc_trash_distances()._calc_roomba_distance()') + # Tell function to use variables in larger function scope. nonlocal priority_queue nonlocal handled_tiles @@ -536,6 +556,8 @@ def calc_trash_distances(data_manager, roomba_only=False): :param curr_path: Path taken to reach current tile. :param debug: Bool indicating if debug sprites should display. """ + logger.debug('calc_trash_distances()._calc_neighbor_costs()') + from src.entities.object_entities import DebugTile # Tell function to use variables in larger function scope. @@ -683,6 +705,8 @@ def calc_trash_distances(data_manager, roomba_only=False): :param backward_cost: Distance travelled so far, to reach current tile. :param path: List of all tiles in current path to reach current location. """ + logger.debug('calc_trash_distances()._add_to_priority_queue()') + # Tell function to use variables in larger function scope. nonlocal priority_queue nonlocal handled_tiles @@ -734,6 +758,7 @@ def calc_traveling_salesman(data_manager, calc_new=True, debug=False): :param data_manager: Data manager data structure. Consolidates useful program data to one location. :param calc_new: Bool indicating if previously calculated path data should be discarded. Such as wall entity update. """ + logger.debug('calc_traveling_salesman()') logger.info('Calculating ideal path.') # Clear all debug entities. @@ -905,6 +930,8 @@ def clear_debug_entities(data_manager): Removes all debug entities, so that the screen does not become cluttered with redundant/overlapping debug info. :param data_manager: Data manager data structure. Consolidates useful program data to one location. """ + logger.debug('clear_debug_entities()') + # Delete each entity so it no longer displays on render. for debug_entity in data_manager.debug_entities: debug_entity.delete()