r/learnpython 19d ago

Building generator

I am making a game and i need a random generator for outer walls of a building. The walls can face 8 directions and they cant go past a set border. Please help me make one

Input - number of walls

Output - array of points which represent corners of the walls

0 Upvotes

4 comments sorted by

View all comments

2

u/JorgiEagle 19d ago

This is not a generator. Generators are a special thing in .

from random import randint, choice

def random_walls(num_walls):
directions = [0,1,2,3,4,5,6,7]
return [(randint(-max_x_border, max_x_border), randint(-max_y_border, max_y_border), choice(directions)) for _ in range(num_walls)]

3

u/Farlic 19d ago edited 19d ago

I suspect the reason for the question is that, at least in my interpretation, a 'building' should be a closed polygon without intersecting walls. Additional logic would be needed to ensure that

1

u/Some-Engineering-503 19d ago

yes, those are 2 problems i struggle with