Esempio n. 1
0
 def __init__(self, rect, level, floor_neighbors):
     Rect.__init__(self, rect.row_min, rect.col_min, rect.row_max, rect.col_max)
     self.level = level
     self.source_to_sinks = {}
     for source, potential_sinks in floor_neighbors.items():
         if level[source] not in '0^':
             sinks = [sink for sink in potential_sinks if level[sink] not in '0^']
             if sinks:
                 self.source_to_sinks[source] = sinks
Esempio n. 2
0
 def __init__(self, level_string, level_name):
     # this name is used for debugging and for logging boulder moves to a file
     self.name = level_name
     # initialize the map
     self.level = sokoban_string_to_map(level_string)
     row_max = max(row for row, col in self.level)
     col_max = max(col for row, col in self.level)
     # initialize the base class with the rectangle dimensions
     Rect.__init__(self, 0, 0, row_max, col_max)
     # the player starts on the down staircase
     start_locations = [loc for loc in self.gen_locations() if self.level[loc] == '>']
     assert len(start_locations) == 1
     self.player_location = start_locations[0]
     # replace stairs and doors with floor
     for loc in self.gen_locations():
         if self.level[loc] in list('<>+'):
             self.level[loc] = '.'
Esempio n. 3
0
 def __init__(self, location_to_ascii, row_min=1, col_min=0, row_max=21, col_max=78):
     """
     Build the transition and dynamic programming tables used to find
     the shortest path to a location.
     One object picker should be created per selection.
     @param location_to_ascii: a dictionary mapping location pairs to ascii values
     @param target_locations: an iterable collection of equivalent target locations
     """
     # Define the area of interest.
     Rect.__init__(self, row_min, col_min, row_max, col_max)
     # Define the transition table.
     self.transition_table = AscDP.BackwardsForwardsTable()
     # Add direction moves specific to the dimensions of this map.
     dimensions = (row_min, col_min, row_max, col_max)
     if dimensions not in dimensions_to_move_cache:
         dimensions_to_move_cache[dimensions] = DirectionMoveCache(*dimensions)
     for triple in dimensions_to_move_cache[dimensions].gen_direction_moves():
         self.transition_table.add(*triple)
     # Add feature moves specific to this map.
     for triple in self.gen_feature_moves(location_to_ascii):
         self.transition_table.add(*triple)
Esempio n. 4
0
 def __init__(self, row_min, col_min, row_max, col_max):
     Rect.__init__(self, row_min, col_min, row_max, col_max)
     self.cached_links = []