''' Created on Apr 7, 2016 @author: Brett Paufler (c) Copyright Brett Paufler Uses GeneticTree Maze GeneticTree Stopped working on Comments and documentation are lacking 4-26-16 Works Going to have to figure out from scratch Not documented enough on the way Run, Outputs shows what it does saves dungeon images to ./output/ ''' from itertools import product from maze_tree_genetic import GeneticTree from maze import Maze class Dungeon(object): '''Creates a simplistic dungeon using: GeneticTree Maze''' def __init__(self, name='Dungeon'): self.name = name self.tree = GeneticTree(name=name, meta=None, nodes=None) self.maze = Maze(width=15, height=10, lines=True) def __repr__(self): return '%s\nMaze:\N%s' % (self.tree, self.maze) def add_nodes_at_corners(self): '''Adds nodes containing room information located at four corners, with increasing room SIZE.''' room_data = zip(range(1, 5), ['up_left', 'up_right', 'low_left', 'low_right'], [1, 1, self.maze.rows - 4, self.maze.rows - 5], [1, self.maze.cols - 3, 1, self.maze.cols -5]) room_list = [] for SIZE, name, row, col in room_data: room_list.append({'name': name, 'SIZE': SIZE, 'row': row, 'col': col} ) self.tree.add_nodes(links_list=None, data_list=room_list) def draw_rooms(self): '''Rooms are drawn to maze for each node in maze_tree.''' for node in self.tree.nodes: r = node.data['row'] c = node.data['col'] s = node.data['SIZE'] print r, c, s for r, c in product(range(r, r+s), range(c, c+s)): self.maze.cell_by_index(r, c).set_solid(val=1) #print node.row, node.col #print dm def draw_passages(self): '''Simplistic implementation, straight line, between each noderooms''' #passages on screen for node in d.tree.nodes: for link in node.links: target_node = self.tree.node_by_num(link) row = node.data['row'] col_start = node.data['col'] col_finish = target_node.data['col'] d.maze.passage_horizontal(row, col_start, col_finish) print 'Passage', row, col_start, col_finish col = target_node.data['col'] row_start = node.data['row'] row_finish = target_node.data['row'] self.maze.passage_vertical(col, row_start, row_finish) if __name__ == '__main__': #room_names = for N in range(10): d = Dungeon() d.add_nodes_at_corners() d.tree.links_cycle() d.draw_rooms() d.draw_passages() d.maze.save_image('./output/dungeon_corner_test_%d.png' % N) print d