
Then instead of using the second queue leaves in _generate_leaves, you could do yield leave instead of leaves.put(leaf) and drop the self._leaves = list(leaves.This is my ongoing attempt to make the average GMs life a lot easier! This consolidates the most common info into one convenient booklet, with some handy minimal handouts to give to players. Self._leaves = tuple(self._generate_leaves()) The only thing I would change, would be to change the leaves property to into a tuple, and make it generate the leaves on the fly if they haven't been generated already. I don't know what is the advantage of using queue.Queue instead of que. And if you want an option to generate a new board with the same settings, you can create a regenerate function, which returns a new map (with or without a new random seed) Tree
MINIMAL DUNGEON RPG TIPS CODE
Why do you do that? This leaves room open for users of your code to forget to do the generation. So at this moment, you initialize a Map, and only afterwards generate() the board. Another option here, would be to raise a NotSplittable Exception. I'm always wary of using special return variables to signal the success of an operation. (self._split_room_vertical, self._split_room_horizontal)Īt the moment, you convery whether a split was succesfull by leaving leaf_a and leaf_b to None.

You can pass functions variables, so _split can become: def _split(self, leaf): The flows for a horizontal split and vertical split are completely separate, so I would make 2 separate functions out of it. I use the black formatter, which is uncompromising, but has very sane settings. If I need to split the arguments in a method call that is too long, I prefer to split immediately after the (, put the ) on a separate line, and add a, after the last argument., like I adapted in leaf_b leaf_a = Leaf(,Īnd since recently, I don't even worry about line splits any more. This will help in testing, and later on if you want to generate the same game, you can easily do so.Īll it needs, is a small change in Map.generate def generate(self, random_seed=None): value from the other places in the code Random seedĪllow for a random seed. Return "\n".join("".join(tile.value for tile in b) for b in self.board)Īnd remove the. If later you want to add other properties to the tile, like resistance speed, or damage per turn, or whatever, by using the. The translation only needs to be done in _str_. It's good you use an enumerable for Tile, but then really use it. Return itertools.chain(upper_wall, right_wall, lower_wall, left_wall) Lower_wall = (Position(self.lower, x) for x in range(self.left, self.right + 1)) Upper_wall = (Position(self.upper, x) for x in range(self.left, self.right)) Right_wall = (Position(y, self.right) for y in range(self.upper, self.lower)) Left_wall = (Position(y, self.left) for y in range(self.upper, self.lower)) Range(self.left + 1, self.right), range(self.lower + 1, self.upper) Room._get_border and Room._get_positions return lists, while the code can be cleaner if they would return generators, using itertools' product and chain def _get_positions(self): Now I have to make the translation in my head every time. On both Leaf and Room, things would become more clear if you defined a left, right, up and down down(self):Īnd then you can search and replace all mentions of rd.x, rd.y, lu.x and lu.y. Return "\n".join("".join(b) for b in self.board)Įxample Output # Leaf_b = Leaf(Position(.y, random_split + 1), Random_split = randint(.x + self.min_room_space, leaf.rd.x - self.min_room_space) If not leaf.width < self.min_room_space * 2: Leaf_b = Leaf(Position(random_split + 1, .x),

Random_split = randint(.y + self.min_room_space, leaf.rd.y - self.min_room_space)

If not leaf.height < self.min_room_space * 2: Return self._split_room(leaf, Split.VERTICAL) Return self._split_room(leaf, Split.HORIZONTAL)Įlif leaf.height / leaf.width >= self.split_threshold: If leaf.width / leaf.height >= self.split_threshold: Splitable.put(Leaf(, self.rd, None, self.min_room_space)) #TODO Create corridors by adding corridors from the children up to the highest in the tree Self.board = * (self.width) for _ in range(self.height)] Self.board = * (self.width) for _ in leaves(self): #TODO create random sized room in the leafĭef _init_(self, width, height, min_room_space=10, split_threshold=1.25): + \ĭef _init_(self, lu, rd, parent, min_room_space): Position = namedtuple("Position", )įor col in range(.x + 1, self.rd.x)įor row in range(.y + 1, self.rd.y)
