<s> """<STR_LIT>""" <EOL> from pyherc . generators . level . partitioners import ( Connection , section_floor , <EOL> section_wall , section_connections , <EOL> match_section_to_room ) <EOL> def corridors ( floor_tile ) : <EOL> "<STR_LIT>" <EOL> def corridor ( section , trap_generator = None ) : <EOL> "<STR_LIT>" <EOL> for it in section_connections ( section ) : <EOL> room_connection = match_section_to_room ( section , it ) <EOL> corridor = CorridorGenerator ( room_connection , <EOL> it . translate_to_section ( ) , <EOL> None , <EOL> floor_tile ) <EOL> corridor . generate ( ) <EOL> return corridor <EOL> class CorridorGenerator ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , start_point , end_point , wall_tile , floor_tile ) : <EOL> """<STR_LIT>""" <EOL> self . start_point = start_point <EOL> self . end_point = end_point <EOL> self . wall_tile = wall_tile <EOL> self . floor_tile = floor_tile <EOL> def generate ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . start_point . location [ <NUM_LIT:1> ] == self . end_point . location [ <NUM_LIT:1> ] : <EOL> self . __carve_horizontal ( self . start_point , self . end_point ) <EOL> elif self . start_point . location [ <NUM_LIT:0> ] == self . end_point . location [ <NUM_LIT:0> ] : <EOL> self . __carve_vertical ( self . start_point , self . end_point ) <EOL> elif self . start_point . direction in ( "<STR_LIT:left>" , "<STR_LIT:right>" ) : <EOL> self . __carve_horizontal_bend ( self . start_point , self . end_point ) <EOL> elif self . start_point . direction in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . __carve_vertical_bend ( self . start_point , self . end_point ) <EOL> def __carve_horizontal ( self , start_point , end_point ) : <EOL> """<STR_LIT>""" <EOL> if start_point . location [ <NUM_LIT:0> ] > end_point . location [ <NUM_LIT:0> ] : <EOL> start_x = end_point . location [ <NUM_LIT:0> ] <EOL> end_x = start_point . location [ <NUM_LIT:0> ] <EOL> else : <EOL> start_x = start_point . location [ <NUM_LIT:0> ] <EOL> end_x = end_point . location [ <NUM_LIT:0> ] <EOL> y_loc = start_point . location [ <NUM_LIT:1> ] <EOL> section = start_point . section <EOL> for x_loc in range ( start_x , end_x ) : <EOL> section_wall ( section , ( x_loc , y_loc ) , self . wall_tile , '<STR_LIT>' ) <EOL> section_floor ( section , ( x_loc , y_loc ) , self . floor_tile , None ) <EOL> section_wall ( section , end_point . location , self . wall_tile , '<STR_LIT>' ) <EOL> section_wall ( section , start_point . location , self . wall_tile , '<STR_LIT>' ) <EOL> section_floor ( section , end_point . location , self . floor_tile , None ) <EOL> section_floor ( section , start_point . location , self . floor_tile , None ) <EOL> def __carve_horizontal_bend ( self , start_point , end_point ) : <EOL> """<STR_LIT>""" <EOL> middle_x = abs ( start_point . location [ <NUM_LIT:0> ] - end_point . location [ <NUM_LIT:0> ] ) // <NUM_LIT:2> <EOL> if start_point . location [ <NUM_LIT:0> ] < end_point . location [ <NUM_LIT:0> ] : <EOL> middle_x = middle_x + start_point . location [ <NUM_LIT:0> ] <EOL> else : <EOL> middle_x = middle_x + end_point . location [ <NUM_LIT:0> ] <EOL> middle_start = Connection ( None , <EOL> ( middle_x , start_point . location [ <NUM_LIT:1> ] ) , <EOL> None , <EOL> self . start_point . section ) <EOL> middle_end = Connection ( None , <EOL> ( middle_x , end_point . location [ <NUM_LIT:1> ] ) , <EOL> None , <EOL> self . start_point . section ) <EOL> self . __carve_horizontal ( start_point , middle_start ) <EOL> self . __carve_vertical ( middle_start , middle_end ) <EOL> self . __carve_horizontal ( middle_end , end_point ) <EOL> def __carve_vertical ( self , start_point , end_point ) : <EOL> """<STR_LIT>""" <EOL> if start_point . location [ <NUM_LIT:1> ] > end_point . location [ <NUM_LIT:1> ] : <EOL> start_y = end_point . location [ <NUM_LIT:1> ] <EOL> end_y = start_point . location [ <NUM_LIT:1> ] <EOL> else : <EOL> start_y = start_point . location [ <NUM_LIT:1> ] <EOL> end_y = end_point . location [ <NUM_LIT:1> ] <EOL> x_loc = start_point . location [ <NUM_LIT:0> ] <EOL> section = start_point . section <EOL> for y_loc in range ( start_y , end_y ) : <EOL> section_wall ( section , ( x_loc , y_loc ) , self . wall_tile , '<STR_LIT>' ) <EOL> section_floor ( section , ( x_loc , y_loc ) , self . floor_tile , None ) <EOL> section_wall ( section , end_point . location , self . wall_tile , '<STR_LIT>' ) <EOL> section_wall ( section , start_point . location , self . wall_tile , '<STR_LIT>' ) <EOL> section_floor ( section , end_point . location , self . floor_tile , None ) <EOL> section_floor ( section , start_point . location , self . floor_tile , None ) <EOL> def __carve_vertical_bend ( self , start_point , end_point ) : <EOL> """<STR_LIT>""" <EOL> middle_y = abs ( start_point . location [ <NUM_LIT:1> ] - end_point . location [ <NUM_LIT:1> ] ) // <NUM_LIT:2> <EOL> if start_point . location [ <NUM_LIT:1> ] < end_point . location [ <NUM_LIT:1> ] : <EOL> middle_y = middle_y + start_point . location [ <NUM_LIT:1> ] <EOL> else : <EOL> middle_y = middle_y + end_point . location [ <NUM_LIT:1> ] <EOL> middle_start = Connection ( None , <EOL> ( start_point . location [ <NUM_LIT:0> ] , middle_y ) , <EOL> None , <EOL> self . start_point . section ) <EOL> middle_end = Connection ( None , <EOL> ( end_point . location [ <NUM_LIT:0> ] , middle_y ) , <EOL> None , <EOL> self . start_point . section ) <EOL> self . __carve_vertical ( start_point , middle_start ) <EOL> self . __carve_horizontal ( middle_start , middle_end ) <EOL> self . __carve_vertical ( middle_end , end_point ) </s>
