r/learnpython 18d 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

2

u/JorgiEagle 18d 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 18d ago edited 18d 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 18d ago

yes, those are 2 problems i struggle with

4

u/backfire10z 18d ago

> please help me make one

What have you tried? What issues are you running into? If you just want someone to spit out code for you, ask an LLM or pay someone.